#! /bin/sh # # Add a new user to loki # Created on 09-10-99 # admin@wickedmind.com # # Make sure only root user can run the script if [ `id -u` != 0 ]; then echo "ERROR: Only Superuser may add users. Sorry." exit 1 fi # # Check if useradd exists on the system. if [ "`/usr/bin/which useradd|awk '{print $2}'`" = no ]; then echo "ERROR: Required program [useradd] not found. Cannot continue." exit 1 fi # # If no arg, then print usage if [ $# = 0 ]; then echo "Usage: `basename $0` [user]" exit 0 fi # # Check if user exists on the system _USER=`grep $1 /etc/passwd|awk -F : '{print $1}'` if [ "$_USER" = "$1" ]; then echo "ERROR: User $1 already exists. Use a different login name." exit 1 fi # # Clear the screen and print a header when we start /usr/bin/tput clear cat <> /etc/shells fi fi # # Get comment/real name echo -n "Enter real name: [no default] " read _REALNAME # # Expire date echo -n "Enter expire date: [MM/DD/YY] " read _EXPIRE # # Clear the screen and print what's been entered. /usr/bin/tput clear echo "" echo "This in the information you entered:" echo "" echo "User ID is: [$_UIDOK]" echo "Group ID is: [$_GIDOK]" echo "Home is: [$_HOME]" echo "Login shell is: [$_SHELL]" echo "Real name is: [$_REALNAME]" echo "Expire date is: [$_EXPIRE]" echo echo -n "Is the above correct? (y/n) " read _verify if [ "$_verify" = n ]; then echo -n "Try Again? (y/n) " read _retry case $_retry in [Yy]*) $0 $1 ;; *) exit ;; esac else # This is where it really happens :-) echo "Adding user $1 to system:" echo useradd -u $_UIDOK -g $_GIDOK -d $_HOME -s $_SHELL -c "$_REALNAME" -e "$_EXPIRE" $1 && \ cp -r /etc/skel $_HOME && \ chown -R $_UIDOK:$_GIDOK $_HOME && \ passwd $1 && \ echo "User $1 [$_REALNAME] added on `date`" >> /var/adm/newuser.log && \ finger -m $1 |head -2 && \ sleep 3 && \ cat <