2018-09-13 17:39:05 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Vars {{{
|
|
|
|
|
DEBUG=0
|
|
|
|
|
|
|
|
|
|
username="${1}"
|
|
|
|
|
|
|
|
|
|
homedir_basepath="/mnt/home.ipr"
|
|
|
|
|
user_id="$(id -u "${username}" 2>/dev/null)"
|
|
|
|
|
user_primary_group="$(id -g "${username}" 2>/dev/null)"
|
|
|
|
|
user_homedir_path="${homedir_basepath}/${username}"
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
# 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 only one argument."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
# }}}
|
|
|
|
|
# Check user exist {{{
|
|
|
|
|
if [ "${user_id}" ]; then
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : user check — ${username} exists."
|
|
|
|
|
else
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : user check — ${username} doesn't exists."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
|
# Check group exist {{{
|
|
|
|
|
if [ "${user_primary_group}" ]; then
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : group check — group ${user_primary_group} exists."
|
|
|
|
|
else
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : group check — ${username}'s primary doesn't seems available on this system."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
|
# Check home base path is available {{{
|
|
|
|
|
if [ $(ls -1 -- "${homedir_basepath}" 2> /dev/null| wc -l) -gt 5 ]; then
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : home_base check — ${homedir_basepath} seems available."
|
|
|
|
|
else
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : home_base check — ${homedir_basepath} doesn't seems available."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
|
# Try to create user's homedir {{{
|
|
|
|
|
command mkdir -p -- "${user_homedir_path}"
|
|
|
|
|
if [ $(ls -1d "${user_homedir_path}" 2> /dev/null) ]; then
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : homedir creation — ${user_homedir_path} ok."
|
|
|
|
|
else
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : homedir creation — ${user_homedir_path} error."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2018-09-14 11:03:21 +02:00
|
|
|
|
|
2018-09-13 17:39:05 +02:00
|
|
|
|
# }}}
|
|
|
|
|
# Try to set permissions on user's homedir {{{
|
|
|
|
|
if command chown "${user_id}:${user_primary_group}" -R -- "${user_homedir_path}"; then
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : homedir permissions — set permission for ${user_id}:${user_primary_group} ok."
|
|
|
|
|
else
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : homedir permissions — set permission for ${user_id}:${user_primary_group} error."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2018-09-14 11:03:21 +02:00
|
|
|
|
|
2018-09-13 17:39:05 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
exit 0
|