2012-08-26 19:33:59 +00:00
#!/bin/bash
2012-11-25 17:40:31 +00:00
#% Usage: add-user [-l <login>] [-N <full name>] [-e <email>] [-g <membership group (fatty/starving)]
#% Adds a user to LDAP. Interactive if parameters not specified on command line
#% Switches:
#% -l <login> - Set the user's login name. It will be stored in the 'uid' LDAP field
#% -N <full name> - Set the full name of the user. It will be stored in the the 'givenName' and 'surname' LDAP fields
#% -e <email> - Set the email address of the user. It will be stored in the 'mailRoutingAddress' and 'mail' LDAP fields
#% -g <membership group> - Set the membership group name (starving/fatty). If it's defined then the user will have full hackerspace membership features unlocked (xmpp, vpn and shell)
2012-08-26 19:33:59 +00:00
. $LIB_DIR/common.sh
function readvar() {
vname=$1
prompt=${2:-$1}
echo -n "$prompt: "
read $vname
}
2018-03-14 19:32:51 +00:00
function confirm() {
read -p "$* [Y] " -n 1 -r
echo # (optional) move to a new line
[[ $REPLY =~ ^([Yy]|)$ ]]
}
2012-11-25 17:40:31 +00:00
while getopts l:N:e:g: opt; do case $opt in
l)
login="$OPTARG";;
N)
cn="$OPTARG";;
e)
email="$OPTARG";;
g)
membership_group="$OPTARG";;
--)
break;;
*)
break;;
esac
done
2012-08-26 19:33:59 +00:00
uid=$((`maxuid`+1))
2012-11-25 17:40:31 +00:00
[ ! "$login" ] && readvar login "Login"
[ ! "$cn" ] && readvar cn "Full name"
[ ! "$email" ] && readvar email "Email"
[ ! "$membership_group" ] && readvar membership_group "Membership group (starving/fatty), press Enter to not assign a membership group"
2018-03-14 19:32:51 +00:00
readvar mifare_hash "Mifare card hash"
2012-08-26 19:33:59 +00:00
2018-01-02 10:38:06 +00:00
if ! [[ "$login" =~ ^[a-z][a-z0-9_]{2,}$ ]] ; then
echo "Login most start with a small lettr and contain only small letters, numbers and underscore" >&2
exit 1
fi
2012-08-26 19:33:59 +00:00
raw-add-user $login "$cn" "$email"
add-to-wiki $login
create-posix-group $login $uid
2012-11-25 17:40:31 +00:00
if [ "$membership_group" ]; then
grant-member-privileges -g $membership_group $login
2012-08-26 19:33:59 +00:00
fi
2012-11-25 17:40:31 +00:00
2018-03-14 19:32:51 +00:00
if [ "$mifare_hash" ]; then
set-mifare-hash $login $mifare_hash
fi
2012-10-05 18:34:22 +00:00
msg "After commiting, please issue welcome-email $login to activate the mailbox"
2018-03-14 19:32:51 +00:00
if confirm "Commit?"; then
commit
2018-03-18 15:09:41 +00:00
confirm "Setup homedir?" && sudo $BIN_DIR/setup-boston-homedir $login
confirm "Setup mailbox?" && sudo $BIN_DIR/setup-boston-mailbox $login
confirm "Send email?" && $BIN_DIR/welcome-email $login
2018-03-14 19:32:51 +00:00
# confirm "Setup password?" && kadmin add_principal
fi