explicitly check for absent to handle state-typos gracefully

This commit is contained in:
tom 2018-10-11 15:58:30 +02:00
parent 09870ece59
commit 409d736339

View file

@ -3,6 +3,7 @@
# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011 Nico Schottelius (nico-cdist at schottelius.org) # 2011 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Daniel Heule (hda at sfs.biz) # 2013 Daniel Heule (hda at sfs.biz)
# 2018 Thomas Eckert (tom at it-eckert.de)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -130,7 +131,7 @@ if [ "$state" = "present" ]; then
echo useradd "$@" "$name" echo useradd "$@" "$name"
fi fi
fi fi
else elif [ "$state" = "absent" ]; then
if grep -q "^${name}:" "$__object/explorer/passwd"; then if grep -q "^${name}:" "$__object/explorer/passwd"; then
#user exists, but state != present, so delete it #user exists, but state != present, so delete it
if [ -f "$__object/parameter/remove-home" ]; then if [ -f "$__object/parameter/remove-home" ]; then
@ -139,4 +140,6 @@ else
echo userdel "${name}" echo userdel "${name}"
fi fi
fi fi
else
echo "Invalid state $state" >&2
fi fi