Update purpose and error code
This commit is contained in:
parent
4301c4c7eb
commit
e504952702
|
@ -3,7 +3,10 @@
|
||||||
# Purpose {{{
|
# Purpose {{{
|
||||||
# This script will create homedir for members of an LDAP group
|
# This script will create homedir for members of an LDAP group
|
||||||
# 1. Get members list from LDAP group given as argument
|
# 1. Get members list from LDAP group given as argument
|
||||||
# …
|
# 2. Compare current list with previous (if it exists)
|
||||||
|
# 3. Try to create homedir for each user
|
||||||
|
# 4. Fix permissions on homedir
|
||||||
|
# 5. Rename members list for next run
|
||||||
#
|
#
|
||||||
# 2021-11-19
|
# 2021-11-19
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -44,6 +47,8 @@ EXAMPLES :
|
||||||
|
|
||||||
- Use default SSSD user for ldap requests
|
- Use default SSSD user for ldap requests
|
||||||
${PROGNAME} --user-cmd "sed -n 's/\(^ldap_default_bind_dn = \)\(.*\)/\2/p' /etc/sssd/sssd.conf"
|
${PROGNAME} --user-cmd "sed -n 's/\(^ldap_default_bind_dn = \)\(.*\)/\2/p' /etc/sssd/sssd.conf"
|
||||||
|
- Create new homedir in a specific path (/mnt/home.remote)
|
||||||
|
${PROGNAME} --home "/mnt/home.remote"
|
||||||
|
|
||||||
OPTIONS :
|
OPTIONS :
|
||||||
-b,--base LDAP_BASE
|
-b,--base LDAP_BASE
|
||||||
|
@ -368,7 +373,7 @@ main() { # {{{
|
||||||
## If ldapsearch command is not available {{{
|
## If ldapsearch command is not available {{{
|
||||||
### exit with message and error
|
### exit with message and error
|
||||||
is_command_available "ldapsearch" \
|
is_command_available "ldapsearch" \
|
||||||
|| error_message "ldapsearch command doesn't seems to be available. Please install ldap-utils package." "3"
|
|| error_message "ldapsearch command doesn't seems to be available. Please install ldap-utils package." 1
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## Define all vars
|
## Define all vars
|
||||||
|
@ -379,25 +384,25 @@ main() { # {{{
|
||||||
### AND exit with message and error
|
### AND exit with message and error
|
||||||
is_var_empty "${ldap_group_cn}" \
|
is_var_empty "${ldap_group_cn}" \
|
||||||
&& usage \
|
&& usage \
|
||||||
&& error_message "Please enter a GROUP with -g|--group option." 1
|
&& error_message "Please enter a GROUP with -g|--group option." 10
|
||||||
## }}}
|
## }}}
|
||||||
## If ldap_user or ldap_passwd is empty {{{
|
## If ldap_user or ldap_passwd is empty {{{
|
||||||
### Print help message
|
### Print help message
|
||||||
### AND exit with message and error
|
### AND exit with message and error
|
||||||
is_var_empty_silent "${ldap_user}" "${ldap_passwd}" \
|
is_var_empty_silent "${ldap_user}" "${ldap_passwd}" \
|
||||||
&& usage \
|
&& usage \
|
||||||
&& error_message "LDAP user or password is empty. Please verify your configuration or the --user-cmd|--passwd-cmd options." 2
|
&& error_message "LDAP user or password is empty. Please verify your configuration or the --user-cmd|--passwd-cmd options." 11
|
||||||
## }}}
|
## }}}
|
||||||
## If home_base directory doesn't exists {{{
|
## If home_base directory doesn't exists {{{
|
||||||
### AND exit with message and error
|
### AND exit with message and error
|
||||||
is_directory_absent "${home_base}" \
|
is_directory_absent "${home_base}" \
|
||||||
&& error_message "Home base directory (${home_base}) doesn't exists. Check your configuration or use -h|--home option." 3
|
&& error_message "Home base directory (${home_base}) doesn't exists. Check your configuration or use -h|--home option." 12
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## Try to get the user list of LDAP group {{{
|
## Try to get the user list of LDAP group {{{
|
||||||
### OR Exit
|
### OR Exit
|
||||||
get_ldap_user_list \
|
get_ldap_user_list \
|
||||||
|| error_message "Can't get the user list of ${ldap_group_cn} LDAP group. Please use --debug option." 4
|
|| error_message "Can't get the user list of ${ldap_group_cn} LDAP group. Please use --debug option." 20
|
||||||
## }}}
|
## }}}
|
||||||
## If a previous list of users exists {{{
|
## If a previous list of users exists {{{
|
||||||
### If the two lists are the same
|
### If the two lists are the same
|
||||||
|
@ -411,16 +416,16 @@ main() { # {{{
|
||||||
## Parse users list {{{
|
## Parse users list {{{
|
||||||
while IFS= read -r username; do
|
while IFS= read -r username; do
|
||||||
user_groupname=$(id --group -- "${username}" \
|
user_groupname=$(id --group -- "${username}" \
|
||||||
|| error_message "Can't get the primary group uid for ${username} user." 6)
|
|| error_message "Can't get the primary group uid for ${username} user." 21)
|
||||||
### Create user's home directory {{{
|
### Create user's home directory {{{
|
||||||
### OR Exit
|
### OR Exit
|
||||||
create_directory "${home_base}/${username}" \
|
create_directory "${home_base}/${username}" \
|
||||||
|| error_message "Can't create home directory (${home_base}/${username}) for ${username} user. Please use --debug option." 5
|
|| error_message "Can't create home directory (${home_base}/${username}) for ${username} user. Please use --debug option." 22
|
||||||
### }}}
|
### }}}
|
||||||
### Fix permissions for this directory {{{
|
### Fix permissions for this directory {{{
|
||||||
### OR Exit
|
### OR Exit
|
||||||
fix_directory_permissions "${home_base}/${username}" "${username}" "${user_groupname}" \
|
fix_directory_permissions "${home_base}/${username}" "${username}" "${user_groupname}" \
|
||||||
|| error_message "Can't fix permissions for ${username} home directory (path: ${home_base}/${username}, username: ${username}, group: ${user_groupname}. Please use --debug option." 7
|
|| error_message "Can't fix permissions for ${username} home directory (path: ${home_base}/${username}, username: ${username}, group: ${user_groupname}. Please use --debug option." 23
|
||||||
### }}}
|
### }}}
|
||||||
|
|
||||||
done < "${ldap_user_list_path}"
|
done < "${ldap_user_list_path}"
|
||||||
|
|
Loading…
Reference in New Issue