move code to a function and add usage options

This commit is contained in:
Naglfar 2020-04-29 23:39:09 +02:00
parent e74b9287dc
commit f9c526342e
1 changed files with 21 additions and 12 deletions

33
rmuser
View File

@ -3,21 +3,30 @@ CONFIG=./setenv
. $CONFIG . $CONFIG
echo "This will remove user account $1 from Thunix." if [ -z $1 ]
echo "It is assumed the user account has been un-enforced in Ansible as well." then
echo -e "Usage: `basename $0` [ username ]"
else
remove_user $1
fi
echo "Unsubscribe from this list..." remove_user()
echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME {
echo "This will remove user account $1 from Thunix."
echo "It is assumed the user account has been un-enforced in Ansible as well."
echo "Killing user processes..." echo "Unsubscribe from this list..."
sudo pkill -9 -U $1 echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME
echo "Archiving home dir..." echo "Killing user processes..."
sudo tar cfz /root/backups/$1.tgz /home/$1 sudo pkill -9 -U $1
sudo rm -rf /home/$1
echo "Deleting account from system..." echo "Archiving home dir..."
sudo userdel $1 sudo tar cfz /root/backups/$1.tgz /home/$1
sudo rm -rf /home/$1
echo "User $1 removed from system. Make sure user is unenforced in ansible." | sudo mail -s "User Account $1 removed from Thunix" $ADMIN_EMAIL echo "Deleting account from system..."
sudo userdel $1
echo "User $1 removed from system. Make sure user is unenforced in ansible." | sudo mail -s "User Account $1 removed from Thunix" $ADMIN_EMAIL
}