move code to a function and add usage options

This commit is contained in:
Blade of Darkness 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
echo "This will remove user account $1 from Thunix."
echo "It is assumed the user account has been un-enforced in Ansible as well."
if [ -z $1 ]
then
echo -e "Usage: `basename $0` [ username ]"
else
remove_user $1
fi
echo "Unsubscribe from this list..."
echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME
remove_user()
{
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..."
sudo pkill -9 -U $1
echo "Unsubscribe from this list..."
echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME
echo "Archiving home dir..."
sudo tar cfz /root/backups/$1.tgz /home/$1
sudo rm -rf /home/$1
echo "Killing user processes..."
sudo pkill -9 -U $1
echo "Deleting account from system..."
sudo userdel $1
echo "Archiving home dir..."
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
}