mirroring: add individual foreign vcs mirror control
[girocco.git] / toolbox / remove-user.sh
blob89dc66a71547c5569b7eb7528e5639e2e62a9b77
1 #!/bin/sh
3 set -e
5 . @basedir@/shlib.sh
7 if [ -z "$1" ]; then
8 echo "Syntax: ./remove-user.sh <username>"
9 exit 1
11 ETC="$cfg_chroot/etc"
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)."
15 exit 1
17 GRPS=`(grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$1"'(,|$)' "$ETC/group" || :) | cut -d : -f 1`
18 if [ "$GRPS" ]; then
19 echo "User '$1' is still part of these groups:" $GRPS
20 echo "fatal: this simplistic script cannot remove users from groups."
21 exit 1
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 if [ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ]; then
31 "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$1"
33 echo "User (+SSH key/certs) removed."