fix case closing and re-format indentation

This commit is contained in:
Ben Harris 2020-01-17 11:47:41 -05:00
parent cdc7f9f2cf
commit 0032d86857
1 changed files with 36 additions and 35 deletions

View File

@ -8,55 +8,56 @@ PROGNAME=${0##*/}
VERSION="0.1"
error_exit() {
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
exit 1
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
exit 1
}
usage() {
echo -e "usage: $PROGNAME [-h|--help] <username> <email> \"<pubkey>\""
echo -e "usage: $PROGNAME [-h|--help] <username> <email> \"<pubkey>\""
}
sub_to_list() {
echo "
From: $1
Subject: subscribe
" | sudo -u $1 sendmail tildeteam-join@lists.tildeverse.org
echo "
From: $1
Subject: subscribe
" | sudo -u $1 sendmail tildeteam-join@lists.tildeverse.org
}
case $1 in
-h | --help)
usage; exit ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
[[ $# -ne 3 ]] && error_exit "not enough args"
-h | --help)
usage; exit ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
[[ $# -ne 3 ]] && error_exit "not enough args"
if id $1 > /dev/null 2>&1; then
exit 0
fi
if id $1 > /dev/null 2>&1; then
exit 0
fi
echo "adding new user $1"
newpw=$(pwgen -1B 10)
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
sudo useradd -m -g 100 -p "$pwcrypt" -s /bin/bash $1 \
|| error_exit "couldn't add user"
echo "adding new user $1"
newpw=$(pwgen -1B 10)
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
sudo useradd -m -g 100 -p "$pwcrypt" -s /bin/bash $1 \
|| error_exit "couldn't add user"
echo "sending welcome mail"
sed -e "s/newusername/$1/g" \
-e "s/newpassword/$newpw/" \
-e "s/newtoemail/$2/" \
/usr/local/bin/welcome-email.tmpl \
| sendmail $1 $2 sudoers@tilde.team
echo "sending welcome mail"
sed -e "s/newusername/$1/g" \
-e "s/newpassword/$newpw/" \
-e "s/newtoemail/$2/" \
/usr/local/bin/welcome-email.tmpl \
| sendmail $1 $2 sudoers@tilde.team
echo "subscribing to mailing list"
sub_to_list $1
echo "subscribing to mailing list"
sub_to_list $1
echo "adding ssh pubkey"
echo "$3" | sudo tee /home/$1/.ssh/authorized_keys
echo "adding ssh pubkey"
echo "$3" | sudo tee /home/$1/.ssh/authorized_keys
echo "announcing new user on mastodon"
toot "welcome new user ~$1!" ;;
echo "announcing new user on mastodon"
toot "welcome new user ~$1!"
echo "cleanup current signup"
sed -i /"$1"/d /var/signups_current
echo "cleanup current signup"
sed -i /"$1"/d /var/signups_current
;;
esac