makeuser/makeuser

48 lines
1.2 KiB
Plaintext
Raw Normal View History

2018-09-20 15:18:17 +00:00
#!/bin/bash
# ---------------------------------------------------------------------------
# makeuser - tilde.team new user creation
# 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
" | sudo -u $1 sendmail tildeteam-join@lists.tildeverse.org
}
[[ $(id -u) != 0 ]] && error_exit "you must be the superuser to run this script."
case $1 in
-h | --help)
usage; exit ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
[[ $# -ne 3 ]] && error_exit "not enough args"
echo "adding new user $1"
newpw=$(pwgen -1B 10)
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
useradd -m -g 100 -p $pwcrypt -s /bin/bash $1 || exit 1
2018-10-19 16:37:57 +00:00
sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $1 $2 sudoers@tilde.team
2018-12-15 01:29:03 +00:00
sub_to_list $1
2019-02-15 18:26:17 +00:00
sudo -u znc /home/znc/add_znc_user.sh $1
echo "$3" | tee /home/$1/.ssh/authorized_keys
toot "welcome new user ~$1!" ;;
esac
2018-09-21 14:04:48 +00:00