From 31d5b0c66973cf572b95daa1fec4f97f22eacaf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 10 Oct 2018 11:02:55 +0200 Subject: [PATCH] Move to a generic script to create directory --- ....all.homedir.sh => auto.create.all.dir.sh} | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) rename cluster/{auto.create.all.homedir.sh => auto.create.all.dir.sh} (81%) diff --git a/cluster/auto.create.all.homedir.sh b/cluster/auto.create.all.dir.sh similarity index 81% rename from cluster/auto.create.all.homedir.sh rename to cluster/auto.create.all.dir.sh index 39f37ea..15ac2e6 100755 --- a/cluster/auto.create.all.homedir.sh +++ b/cluster/auto.create.all.dir.sh @@ -2,7 +2,7 @@ # Purpose {{{ ## This script will : ### Try to get the member of an LDAP group (allowed to connect to Compute Cluster). -### Call a script in order to create the homedir for each user. +### Call the script passed in argument in order to create the wanted directory for each user (eg. home,…). ### If the list of member is unchanged from a previous run, the script exit. # }}} # Vars {{{ @@ -19,9 +19,18 @@ new_user_list_path="/tmp/cluster.user.list" old_user_list_path="/tmp/cluster.user.list.old" script_wd=$(dirname -- "${0}") -homedir_script="${script_wd}/create.user.homedir.sh" +newdir_script_name="${1}" +newdir_script_path="${script_wd}/${newdir_script_name}" # }}} +# Ensure to get one argument {{{ +if [ "${#}" -eq 1 ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : arg check — ${0} get one argument: ${1}." +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : arg check — ${0} should get one argument." + exit 1 +fi +# }}} # Check if ldap-utils/ldapsearch is available {{{ if [ ! "$(command -v ldapsearch)" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ldapsearch check — ldapsearch doesn't seems to be available. Please install ldap-utils package." @@ -62,14 +71,14 @@ diff -- "${new_user_list_path}" "${old_user_list_path}" fi fi # }}} -# Create user homedir {{{ +# Create wanted directory for user {{{ while IFS= read -r username; do - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Homedir — Apply ${homedir_script} for ${username}." - ${homedir_script} "${username}" + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : New dir — Apply ${newdir_script_name} for ${username}." + ${newdir_script_path} "${username}" done < "${new_user_list_path}" # }}} -# Keep a record of user list for next use and restrict access +# Keep a record of user list for next run and restrict access command mv -f -- "${new_user_list_path}" "${old_user_list_path}" command chmod 0400 -- "${old_user_list_path}"