forked from team/makeuser
38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# ---------------------------------------------------------------------------
|
|
# makeuser - tilde.team new user creation
|
|
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
|
|
# ---------------------------------------------------------------------------
|
|
|
|
PROGNAME=${0##*/}
|
|
VERSION="0.1"
|
|
|
|
error_exit() {
|
|
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
|
|
exit 1
|
|
}
|
|
|
|
usage() {
|
|
echo -e "usage: $PROGNAME [-h|--help] <username> <email> \"<pubkey>\""
|
|
}
|
|
|
|
[[ $(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
|
|
|
|
sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $2 sudoers@tilde.team
|
|
|
|
echo "$3" | tee /home/$1/.ssh/authorized_keys
|
|
toot "welcome new user ~$1!" ;;
|
|
esac
|