2018-09-20 15:18:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# ---------------------------------------------------------------------------
|
2019-09-17 16:04:37 +00:00
|
|
|
# makeuser - tilde.club new user creation
|
2018-09-21 14:10:50 +00:00
|
|
|
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
|
2018-09-20 15:18:17 +00:00
|
|
|
# ---------------------------------------------------------------------------
|
2018-09-20 14:04:19 +00:00
|
|
|
|
2018-09-20 15:18:17 +00:00
|
|
|
PROGNAME=${0##*/}
|
|
|
|
VERSION="0.1"
|
2018-09-20 14:04:19 +00:00
|
|
|
|
2018-09-20 15:18:17 +00:00
|
|
|
error_exit() {
|
|
|
|
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2018-09-20 14:04:19 +00:00
|
|
|
|
2018-09-20 15:18:17 +00:00
|
|
|
usage() {
|
2018-09-20 15:40:17 +00:00
|
|
|
echo -e "usage: $PROGNAME [-h|--help] <username> <email> \"<pubkey>\""
|
2018-09-20 15:18:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 01:29:03 +00:00
|
|
|
sub_to_list() {
|
|
|
|
echo "
|
|
|
|
From: $1
|
|
|
|
Subject: subscribe
|
2019-09-17 16:04:37 +00:00
|
|
|
" | sudo -u $1 sendmail tildeclub-join@lists.tildeverse.org
|
2018-12-15 01:29:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:10:50 +00:00
|
|
|
case $1 in
|
|
|
|
-h | --help)
|
|
|
|
usage; exit ;;
|
|
|
|
-* | --*)
|
|
|
|
usage; error_exit "unknown option $1" ;;
|
|
|
|
*)
|
|
|
|
[[ $# -ne 3 ]] && error_exit "not enough args"
|
2019-06-28 15:18:20 +00:00
|
|
|
|
2019-09-17 16:04:37 +00:00
|
|
|
if id $1 > /dev/null 2>&1; then
|
2019-10-22 22:28:26 +00:00
|
|
|
exit 0
|
2019-09-17 16:04:37 +00:00
|
|
|
fi
|
|
|
|
|
2018-09-21 14:10:50 +00:00
|
|
|
echo "adding new user $1"
|
|
|
|
newpw=$(pwgen -1B 10)
|
2020-03-27 06:12:33 +00:00
|
|
|
sudo useradd -m -g 100 -s /usr/bin/bash $1 \
|
2019-06-28 15:18:20 +00:00
|
|
|
|| error_exit "couldn't add user"
|
2019-10-22 22:28:26 +00:00
|
|
|
echo "$1:$newpw" | sudo chpasswd
|
2019-06-28 15:18:20 +00:00
|
|
|
|
|
|
|
echo "sending welcome mail"
|
2019-07-03 19:55:14 +00:00
|
|
|
sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" /usr/local/bin/welcome-email.tmpl \
|
2019-09-17 16:04:37 +00:00
|
|
|
| sendmail $1 $2 root
|
2018-09-21 14:10:50 +00:00
|
|
|
|
2019-06-28 15:18:20 +00:00
|
|
|
echo "subscribing to mailing list"
|
2023-04-06 16:11:18 +00:00
|
|
|
#sub_to_list $1
|
2019-06-28 15:18:20 +00:00
|
|
|
|
2021-12-12 08:12:09 +00:00
|
|
|
echo "removing .git and README.md from new homedir"
|
2019-12-01 21:35:50 +00:00
|
|
|
sudo rm -rf /home/$1/.git
|
2021-12-12 08:12:09 +00:00
|
|
|
sudo rm -rf /home/$1/README.md
|
2018-09-21 14:10:50 +00:00
|
|
|
|
2019-06-28 15:18:20 +00:00
|
|
|
echo "adding ssh pubkey"
|
|
|
|
echo "$3" | sudo tee /home/$1/.ssh/authorized_keys
|
2020-04-15 18:32:54 +00:00
|
|
|
|
2023-04-06 16:11:18 +00:00
|
|
|
#echo "making znc user"
|
|
|
|
#znccreate.py "$1" "$newpw"
|
2021-12-28 22:07:03 +00:00
|
|
|
|
2020-03-27 06:12:33 +00:00
|
|
|
echo "announcing new user on mastodon"
|
|
|
|
toot "welcome new user ~$1!"
|
|
|
|
|
|
|
|
esac
|