#!/bin/bash #% Usage: add-user [-l ] [-N ] [-e ] [-g - Set the user's login name. It will be stored in the 'uid' LDAP field #% -N - Set the full name of the user. It will be stored in the the 'givenName' and 'surname' LDAP fields #% -e - Set the email address of the user. It will be stored in the 'mailRoutingAddress' and 'mail' LDAP fields #% -g - 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) . $LIB_DIR/common.sh function readvar() { vname=$1 prompt=${2:-$1} echo -n "$prompt: " read $vname } function confirm() { read -p "$* [Y] " -n 1 -r echo # (optional) move to a new line [[ $REPLY =~ ^([Yy]|)$ ]] } 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 uid=$((`maxuid`+1)) [ ! "$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" readvar mifare_hash "Mifare card hash" 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 raw-add-user $login "$cn" "$email" add-to-wiki $login create-posix-group $login $uid if [ "$membership_group" ]; then grant-member-privileges -g $membership_group $login fi if [ "$mifare_hash" ]; then set-mifare-hash $login $mifare_hash fi msg "After commiting, please issue welcome-email $login to activate the mailbox" if confirm "Commit?"; then commit 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 # confirm "Setup password?" && kadmin add_principal fi