8 echo "Syntax: ./remove-user.sh <username>"
12 COUNT
=`grep -E -c "^$1:" "$ETC/passwd" || :`
13 if [ "$COUNT" -ne "1" ]; then
14 echo "fatal: user '$1' doesn't appear to exist (or exists multiple times, or contains regexpy characters)."
17 GRPS
=`(grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$1"'(,|$)' "$ETC/group" || :) | cut -d : -f 1`
19 echo "User '$1' is still part of these groups:" $GRPS
20 echo "fatal: this simplistic script cannot remove users from groups."
23 sed -i.$$
-e "/^$1:/ d" "$ETC/passwd"
24 rm -f "$ETC/passwd.$$" ||
:
25 rm -f "$ETC/sshkeys/$1" ||
:
26 rm -f "$ETC/sshcerts/$cfg_nickname"_
"$1"_user_
*.pem ||
:
27 ! [ -e "$ETC/sshkeys/$1" ] ||
echo "Warning: unable to remove $ETC/sshkeys/$1" >&2
28 [ "$(echo "$ETC/sshcerts
/$cfg_nickname"_"$1"_user_*.pem)" = "$ETC/sshcerts/$cfg_nickname"_
"$1"_user_
"*".pem
] ||
29 echo "Warning: unable to remove $(echo "$ETC/sshcerts
/$cfg_nickname"_"$1"_user_*.pem)" >&2
30 echo "User (+SSH key/certs) removed."