From: Vincent Le Gallic Date: Wed, 11 Jun 2014 01:04:17 +0000 (+0200) Subject: [populate_forwards] Un peu plus générique et {cwd,sudo}-proof X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=7f26c0abefaf1bc5ae75075600c70e2e2c2b95ce;p=scripts-20-100.git [populate_forwards] Un peu plus générique et {cwd,sudo}-proof --- diff --git a/populate_forward.sh b/populate_forward.sh index 276a5f3..b492c9c 100755 --- a/populate_forward.sh +++ b/populate_forward.sh @@ -2,15 +2,26 @@ # Remplir le fichier forward -find /home -mindepth 1 -maxdepth 1 -type d | sort | \ -while read -r dossier; -do - if test -f ${dossier}/.forward; - then - echo -n "${dossier/\/home\//} : "; - cat ${dossier}/.forward - fi -done > forwards +USER=legallic -chown legallic:users forwards -chmod 600 forwards +FILE=/home/${USER}/forwards + +if [ $EUID -eq 0 ] +then + touch ${FILE} + chown ${USER}:users ${FILE} + chmod 600 ${FILE} + + find /home -mindepth 1 -maxdepth 1 -type d | sort | \ + while read -r dossier; + do + if test -f ${dossier}/.forward; + then + echo -n "${dossier/\/home\//} : "; + cat ${dossier}/.forward + fi + done > ${FILE} + +else + echo "À exécuter en root !" +fi