From 85ba2a65dda75c26b923559b9203357bdb8b1e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 15 Feb 2017 14:37:46 +0100 Subject: [PATCH] Correct whitespaces --- mailtosesame | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/mailtosesame b/mailtosesame index fbd0c61..6610145 100755 --- a/mailtosesame +++ b/mailtosesame @@ -1,32 +1,40 @@ #!/bin/sh # This script will convert UR1 user mail into UR1 user sesame -# The first argument should be a file with a mail by line! +# The first argument must be : +# a file with a mail by line ! +# a mail address # Dependancies: # ldapsearch (provide by ldap-utils on GNU/Linux) -MAIL_LIST="${1}" -UID_LIST="${MAIL_LIST}_uid" +# Test if the first arg is a existing file +if [ -f "${1}" ]; then + MAIL_LIST="${1}" + UID_LIST="${MAIL_LIST}_uid" -# Test if the given file exists -if [ -f "${MAIL_LIST}" ]; then - touch "${UID_LIST}" + touch "${UID_LIST}" + + index=0 + while read -r mail; do + index=$((index+1)) + uid=$(ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(mail='"${mail}"')' -b "dc=univ-rennes1,dc=fr" -x uid | grep "^uid" | cut -d" " -f2) + + #printf '%b' "${index}: ${mail} -> ${uid}\n" + printf '%b' "${uid}\n" >> "${UID_LIST}" + + done < "${MAIL_LIST}" + + printf '%b' "Please see ${UID_LIST} file\n" + exit 0 else - printf '%b' "The fist argument should be a file with one mail/line\n" - exit 1 + MAIL="${1}" + + printf '%b' "This email address correspond to :\n" + + ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(mail='"${MAIL}"')' -b "dc=univ-rennes1,dc=fr" -x uid | grep "^uid" | cut -d" " -f2 + + exit 0 fi -index=0 -while read mail; do - index=$((index+1)) - uid=$(ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(mail='"${mail}"')' -b "dc=univ-rennes1,dc=fr" -x uid | grep "^uid" | cut -d" " -f2) - - #printf '%b' "${index}: ${mail} -> ${uid}\n" - printf '%b' "${uid}\n" >> "${UID_LIST}" - -done < "${MAIL_LIST}" - -printf '%b' "Please see ${UID_LIST} file\n" - exit 0