Move to a generic script to create directory

This commit is contained in:
Jeremy Gardais 2018-10-10 11:02:55 +02:00
parent 09fb786f1e
commit 31d5b0c669
1 changed files with 15 additions and 6 deletions

View File

@ -2,7 +2,7 @@
# Purpose {{{ # Purpose {{{
## This script will: ## This script will:
### Try to get the member of an LDAP group (allowed to connect to Compute Cluster). ### 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. ### If the list of member is unchanged from a previous run, the script exit.
# }}} # }}}
# Vars {{{ # Vars {{{
@ -19,9 +19,18 @@ new_user_list_path="/tmp/cluster.user.list"
old_user_list_path="/tmp/cluster.user.list.old" old_user_list_path="/tmp/cluster.user.list.old"
script_wd=$(dirname -- "${0}") 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 {{{ # Check if ldap-utils/ldapsearch is available {{{
if [ ! "$(command -v ldapsearch)" ]; then 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." [ "${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
fi fi
# }}} # }}}
# Create user homedir {{{ # Create wanted directory for user {{{
while IFS= read -r username; do while IFS= read -r username; do
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Homedir — Apply ${homedir_script} for ${username}." [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: New dir — Apply ${newdir_script_name} for ${username}."
${homedir_script} "${username}" ${newdir_script_path} "${username}"
done < "${new_user_list_path}" 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 mv -f -- "${new_user_list_path}" "${old_user_list_path}"
command chmod 0400 -- "${old_user_list_path}" command chmod 0400 -- "${old_user_list_path}"