mkusers: do not assume passwd and shadow files exist

This commit is contained in:
Calin Crisan 2018-11-10 17:48:38 +02:00
parent c77070e015
commit c08ed69429

View File

@ -313,7 +313,7 @@ add_one_user() {
# Remove any previous instance of this user
for _f in "${PASSWD}" "${SHADOW}"; do
sed -r -i --follow-symlinks -e '/^'"${username}"':.*/d;' "${_f}"
test -f ${_f} && sed -r -i --follow-symlinks -e '/^'"${username}"':.*/d;' "${_f}"
done
_gid="$( get_gid "${group}" )"
@ -342,13 +342,17 @@ add_one_user() {
;;
esac
printf "%s:x:%d:%d:%s:%s:%s\n" \
"${username}" "${uid}" "${_gid}" \
"${comment}" "${_home}" "${_shell}" \
>>"${PASSWD}"
printf "%s:%s:::::::\n" \
"${username}" "${_passwd}" \
>>"${SHADOW}"
if [ -f ${PASSWD} ]; then
printf "%s:x:%d:%d:%s:%s:%s\n" \
"${username}" "${uid}" "${_gid}" \
"${comment}" "${_home}" "${_shell}" \
>>"${PASSWD}"
fi
if [ -f ${SHADOW} ]; then
printf "%s:%s:::::::\n" \
"${username}" "${_passwd}" \
>>"${SHADOW}"
fi
# Add the user to its additional groups
if [ "${groups}" != "-" ]; then