forked from team/makeuser
bash version
This commit is contained in:
parent
e05705d6c9
commit
8c385dff1d
|
@ -0,0 +1,43 @@
|
||||||
|
Subject: welcome to tilde.team!
|
||||||
|
|
||||||
|
hey ~newusername,
|
||||||
|
|
||||||
|
welcome to tilde.team!
|
||||||
|
|
||||||
|
your new account has been established. you can ssh into tilde.team with
|
||||||
|
the ssh key you supplied on registration.
|
||||||
|
|
||||||
|
your password is "newpassword". please change it when you log in for
|
||||||
|
the first time. the password is used for imap/smtp auth, not shell login,
|
||||||
|
which is set to only use ssh key authentication.
|
||||||
|
|
||||||
|
to get started, type `motd` at the command prompt to see a few ways to
|
||||||
|
get started. have fun!
|
||||||
|
|
||||||
|
the greatest value of tilde.team is not the services provided by the
|
||||||
|
server, but rather the interesting and welcoming community built by its
|
||||||
|
users. this is possible because of people like you who choose to make
|
||||||
|
this a great place. the best way you can help tilde.team is by working
|
||||||
|
to support a great system culture. chat on irc; build cool programs and
|
||||||
|
share them with others; focus on learning, and help others learn; be a
|
||||||
|
good example for others; have fun!
|
||||||
|
|
||||||
|
also, your ~/public_html directory is served at
|
||||||
|
https://tilde.team/~newusername/
|
||||||
|
(you can also use https://newusername.tilde.team)
|
||||||
|
|
||||||
|
check out our wiki at https://tilde.team/wiki/ for more information (and
|
||||||
|
maybe help us write a new wiki article:)
|
||||||
|
|
||||||
|
our irc is tilde.chat, an irc network connecting several
|
||||||
|
tilde servers. the `chat` command on your ~team shell will open up
|
||||||
|
weechat with some nice default configs and plugins.
|
||||||
|
see our wiki article (https://tilde.team/wiki/?page=irc)
|
||||||
|
or https://tilde.chat site for information on how to connect from elsewhere.
|
||||||
|
we also have a webclient at https://irc.tilde.team that you can
|
||||||
|
register for by running the `webirc` command from a shell session.
|
||||||
|
|
||||||
|
we look forward to seeing you around! welcome to the ~team!
|
||||||
|
|
||||||
|
~tilde.team admins
|
||||||
|
|
121
makeuser
121
makeuser
|
@ -1,11 +1,116 @@
|
||||||
#!/usr/bin/python3
|
#!/bin/bash
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# makeuser - tilde.team new user creation
|
||||||
|
|
||||||
import os,argparse
|
# Copyright 2018, Ben Harris <ben@tilde.team>
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.")
|
# This program is free software: you can redistribute it and/or modify
|
||||||
parser.add_argument("username",help="Username of user.")
|
# it under the terms of the GNU General Public License as published by
|
||||||
parser.add_argument("email",help="Email of user.")
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
parser.add_argument("key",help="The user's SSH pubkey.")
|
# (at your option) any later version.
|
||||||
args = parser.parse_args()
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License at <http://www.gnu.org/licenses/> for
|
||||||
|
# more details.
|
||||||
|
|
||||||
|
# Usage: makeuser [-h|--help]
|
||||||
|
|
||||||
|
# Revision history:
|
||||||
|
# 2018-09-20 Created by new_script ver. 3.3
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PROGNAME=${0##*/}
|
||||||
|
VERSION="0.1"
|
||||||
|
|
||||||
|
clean_up() { # Perform pre-exit housekeeping
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
error_exit() {
|
||||||
|
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
|
||||||
|
clean_up
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
graceful_exit() {
|
||||||
|
clean_up
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
signal_exit() { # Handle trapped signals
|
||||||
|
case $1 in
|
||||||
|
INT)
|
||||||
|
error_exit "Program interrupted by user" ;;
|
||||||
|
TERM)
|
||||||
|
echo -e "\n$PROGNAME: Program terminated" >&2
|
||||||
|
graceful_exit ;;
|
||||||
|
*)
|
||||||
|
error_exit "$PROGNAME: Terminating on unknown signal" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo -e "usage: $PROGNAME [-h|--help] <username> <email> <pubkey>"
|
||||||
|
}
|
||||||
|
|
||||||
|
help_message() {
|
||||||
|
cat <<- _EOF_
|
||||||
|
$PROGNAME ver. $VERSION
|
||||||
|
tilde.team new user creation
|
||||||
|
|
||||||
|
$(usage)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Display this help message and exit.
|
||||||
|
|
||||||
|
NOTE: You must be the superuser to run this script.
|
||||||
|
|
||||||
|
_EOF_
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Trap signals
|
||||||
|
trap "signal_exit TERM" TERM HUP
|
||||||
|
trap "signal_exit INT" INT
|
||||||
|
|
||||||
|
# Check for root UID
|
||||||
|
if [[ $(id -u) != 0 ]]; then
|
||||||
|
error_exit "you must be the superuser to run this script."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Parse command-line
|
||||||
|
while [[ -n $1 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h | --help)
|
||||||
|
help_message; graceful_exit ;;
|
||||||
|
-* | --*)
|
||||||
|
usage
|
||||||
|
error_exit "unknown option $1" ;;
|
||||||
|
*)
|
||||||
|
user=$1
|
||||||
|
email=$2
|
||||||
|
sshkey="$3"
|
||||||
|
echo "adding new user $user with and pubkey $sshkey"
|
||||||
|
|
||||||
|
newpw=$(pwgen -1B 10)
|
||||||
|
pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');")
|
||||||
|
|
||||||
|
useradd -m -p $pwcrypt -s /bin/bash $user || exit 1
|
||||||
|
|
||||||
|
sed -e 's/newusername/$user/g' -e 's/newpassword/$newpw/' email.tmpl | sendmail $email sudoers@tilde.team
|
||||||
|
|
||||||
|
echo "$sshkey" | sudo tee /home/$user/.ssh/authorized_keys
|
||||||
|
toot "welcome new user ~$user!"
|
||||||
|
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
graceful_exit
|
||||||
|
|
||||||
print(args.username,args.email,args.key)
|
|
||||||
|
|
Loading…
Reference in New Issue