SLBR/deluser.sh

26 lines
796 B
Bash
Raw Permalink Normal View History

2018-08-28 17:39:44 +00:00
#!/bin/sh
# deluser.sh
# deletes a user, their container, and their home direcory
# can be called manually or by a script
2018-09-14 17:34:46 +00:00
SLBRUSER=$1
test -z "$SLBRUSER" && echo "no user provided" && exit
if ! (grep -qE "^$SLBRUSER$" users.txt)
2018-09-26 15:11:40 +00:00
then
echo "user $SLBRUSER not found in users.txt, will not delete"
2018-09-26 15:11:40 +00:00
exit
fi
2018-09-24 18:28:07 +00:00
2018-09-14 17:34:46 +00:00
if ps -o stat= -p $PPID | grep -qv S+ #check if this is being called from listen.py
then
2018-10-11 04:50:26 +00:00
echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USER'S NAME TO CONTINUE"
read -r ENTEREDUSER
[ "$ENTEREDUSER" != "$SLBRUSER" ] && echo "users did not match, exiting..." && exit
2018-09-14 17:34:46 +00:00
fi
lxc stop "$SLBRUSER"
lxc delete "$SLBRUSER"
sudo rm -rf "/home/slbr/users/$SLBRUSER"
sudo userdel "$SLBRUSER"
2018-10-11 04:50:26 +00:00
sed -i "s/^$SLBRUSER$//g" users.txt
sed -i '/^$/d' users.txt