Use Config.pm settings to avoid hard-coding /srv/git
[girocco.git] / toolbox / remove-user.sh
blob0446d196d5abe3c70a477a83f147ff358311452f
1 #!/bin/sh
3 . @basedir@/shlib.sh
5 if [ -z "$1" ]; then
6 echo "Syntax: ./remove-user.sh <username>"
7 exit 1
8 fi
9 ETC="$cfg_chroot/etc"
10 COUNT=`grep -E -c "^$1:" $ETC/passwd`
11 if [ "$COUNT" -ne "1" ]; then
12 echo "fatal: user '$1' doesn't appear to exist (or exists multiple times, or contains regexpy characters)."
13 exit 1
15 GROUPS=`sed -rn '/[,:]'$1'(,|$)/ s/:.*$// p' $ETC/group`
16 if [ "$GROUPS" ]; then
17 echo "User '$1' is still part of these groups:" $GROUPS
18 echo "fatal: this simplistic script cannot remove users from groups."
19 exit 1
21 sed -i "/^$1:/ d" $ETC/passwd
22 rm $ETC/sshkeys/$1
23 echo "User (+SSH key) removed."