2019-12-12 20:15:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#Common functions used for several makeuser scripts
|
|
|
|
|
|
|
|
error_exit() {
|
|
|
|
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2021-08-18 21:07:12 +00:00
|
|
|
echo -e "usage: $PROGNAME [-h|--help] <username> <email> <pubkey>"
|
2019-12-12 20:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub_to_list() {
|
|
|
|
echo "From: $1 Subject: subscribe" | sudo -u $1 mail $LIST_NAME
|
|
|
|
}
|
2019-12-16 14:09:57 +00:00
|
|
|
|
|
|
|
makeuser_no_ansible()
|
|
|
|
{
|
|
|
|
echo "adding new user $1"
|
|
|
|
newpw=`pwgen -1B 10`
|
|
|
|
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
|
|
|
|
sudo useradd -m -g 1000 -p $pwcrypt -s /bin/bash $1 || exit 1
|
|
|
|
#This is the welcome for team.
|
|
|
|
#sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" $EMAIL_TEMPLATE | sudo mail $1 $2 $ADMIN_EMAIL
|
|
|
|
|
|
|
|
#This is the welcome email for thunix
|
2020-11-30 21:10:05 +00:00
|
|
|
sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/g" include/email.tmpl | sudo mail -s "Welcome to Thunix!" $2,$ADMIN_EMAIL
|
2019-12-16 14:09:57 +00:00
|
|
|
sub_to_list $1
|
|
|
|
|
|
|
|
#We don't need this for thunix, since ansible will do it
|
|
|
|
#echo "$3" | tee /home/$1/.ssh/authorized_keys
|
|
|
|
|
|
|
|
#If root doesn't have a fediverse account, comment this out
|
|
|
|
#sudo toot "welcome new user ~$1!"
|
|
|
|
}
|
2020-01-15 18:16:53 +00:00
|
|
|
|
|
|
|
add_account_recovery()
|
|
|
|
{
|
2020-01-15 20:44:39 +00:00
|
|
|
sudo mkdir -p --mode=700 /home/$1/.thunix
|
2020-02-04 19:28:58 +00:00
|
|
|
echo $2 | sudo tee /home/$1/.thunix/recovery
|
2020-02-01 03:35:01 +00:00
|
|
|
sudo chmod 600 /home/$1/.thunix/recovery
|
2020-01-15 19:24:42 +00:00
|
|
|
sudo chown -R $1 /home/$1/.thunix
|
2020-01-15 18:16:53 +00:00
|
|
|
}
|
2021-10-01 08:27:53 +00:00
|
|
|
|
|
|
|
remove_user()
|
|
|
|
{
|
|
|
|
echo "Unsubscribe from this list..."
|
|
|
|
echo "From: $1 Subject: unsubscribe " | sudo -u $1 mail $LIST_NAME
|
|
|
|
|
|
|
|
echo "Deleting account from system..."
|
|
|
|
sudo userdel $1
|
|
|
|
sudo rm -rf /home/$1
|
|
|
|
|
|
|
|
echo "$1 user account is unenforced in ansible..."
|
|
|
|
currdir=`pwd`
|
|
|
|
cd $REPO_LOCATION; git pull
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
backup_user_data()
|
|
|
|
{
|
|
|
|
echo "Archiving home dir..."
|
|
|
|
sudo tar cfz /root/backups/$1.tgz /home/$1
|
|
|
|
}
|