New remirror-project.pl utility script
[girocco.git] / toolbox / remove-user.sh
blob28ac4476359f7d473330bbf53ae8a93f0d5a02e8
1 #!/bin/sh
3 if [ -z "$1" ]; then
4 echo "Syntax: ./remove-user.sh <username>"
5 exit 1
6 fi
7 ETC=$HOME/j/etc
8 COUNT=`grep -E -c "^$1:" $ETC/passwd`
9 if [ "$COUNT" -ne "1" ]; then
10 echo "fatal: user '$1' doesn't appear to exist (or exist multiple times, or contain regexpy characters)."
11 exit 1
13 GROUPS=`sed -rn '/[,:]'$1'(,|$)/ s/:.*$// p' $ETC/group`
14 if [ "$GROUPS" ]; then
15 echo "User '$1' is still part of these groups:" $GROUPS
16 echo "fatal: this simplistic script cannot remove users from groups."
17 exit 1
19 sed -i "/^$1:/ d" $ETC/passwd
20 rm $ETC/sshkeys/$1
21 echo "User (+SSH key) removed."