makeuser/rmuser

49 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2019-12-06 15:40:49 +00:00
CONFIG=./setenv
. $CONFIG
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 "Unsubscribe from this list..."
echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME
2019-05-14 11:36:41 +00:00
echo "Killing user processes..."
sudo pkill -9 -U $1
2019-05-14 11:36:41 +00:00
[ -n $2 ] && [[ $2 == --backup ]] && bacup_user_data $1
2019-05-14 11:36:41 +00:00
echo "Deleting account from system..."
sudo userdel $1
2021-08-13 09:28:36 +00:00
sudo rm -rf /home/$1
2019-12-12 20:28:16 +00:00
echo "$1 user account is unenforced in ansible..."
currdir=`pwd`
cd $REPO_LOCATION; git pull
2020-12-07 20:08:33 +00:00
sed -i "/$1/d" $REPO_LOCATION/roles/shell/tasks/users.yml
rm $REPO_LOCATION/roles/shell/tasks/users/$YAML_FILE
git commit -am "$1 account unenforced in ansible"
git push
cd $currdir
echo "User $1 removed from system." | sudo mail -s "User Account $1 removed from Thunix" $ADMIN_EMAIL
}
bacup_user_data()
{
echo "Archiving home dir..."
sudo tar cfz /root/backups/$1.tgz /home/$1
}
if [ -z $1 ]
then
echo -e "Usage: `basename $0` username [ --banned ][ --backup ]"
else
remove_user $1
2021-01-30 08:06:47 +00:00
[ -n $2 ] && [[ $2 == --banned ]] && echo $1 | sudo tee -a $BANNED
fi