8 echo "Syntax: ./remove-user.sh <username>"
12 qu
="$(printf '%s' "$u" | sed -e 's/\./\\./g' -e 's/+/[+]/g')"
14 COUNT
=$
(grep -E -c "^$qu:" "$ETC/passwd" ||
:)
15 if [ "$COUNT" -ne "1" ]; then
16 echo "fatal: user '$u' doesn't appear to exist (or exists multiple times, or contains regexpy characters)."
19 ENTRY
="$(grep -E "^
$qu:" "$ETC/passwd
" | cut -d : -f 1-5)"
20 GRPS
=$
( (grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$qu"'(,|:|$)' "$ETC/group" ||
:) | cut
-d : -f 1 )
22 echo "User '$u' is still part of these groups:" $GRPS
23 echo "fatal: this simplistic script cannot remove users from groups."
26 sed -i.$$
-e "/^$qu:/ d" "$ETC/passwd"
27 rm -f "$ETC/passwd.$$" ||
:
28 rm -f "$ETC/sshkeys/$u" ||
:
29 rm -f "$ETC/sshcerts/$cfg_nickname"_
"$u"_user_
*.pem ||
:
30 rm -f "$ETC/sshactive/$u" ||
:
31 rm -f "$ETC/sshactive/$u",* ||
:
32 ! [ -e "$ETC/sshkeys/$u" ] ||
echo "Warning: unable to remove $ETC/sshkeys/$u" >&2
33 [ "$(echo "$ETC/sshcerts
/$cfg_nickname"_"$u"_user_*.pem)" = "$ETC/sshcerts/$cfg_nickname"_
"$u"_user_
"*".pem
] ||
34 echo "Warning: unable to remove $(echo "$ETC/sshcerts
/$cfg_nickname"_"$u"_user_*.pem)" >&2
35 if [ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ]; then
36 "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$u"
38 echo "User \"$ENTRY\" (+SSH key/certs) removed."