#!/bin/bash
#
# by: George Hacker (20101202) 
#
# Setup script for the define acl lab
# this script is to be installed and run on serverX.example.com
# output is logged to syslog

# Set environment and declare global variables
. /usr/local/lib/labtool.shlib
trap on_exit EXIT

DEBUG=false
ERROR_MESSAGE="Error running script. Contact your instructor if you continue to see this message."
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
userInput="no"

set -o pipefail

# Check to make sure we are running as root
check_root

# Check to make sure we are running on the correct host
check_host "server"

echo
echo -n "Setting up, one moment please... "

for group in profs grads interns
do
    if grep "^$group:" /etc/group >& /dev/null
    then
    	echo "$group already exists"
    else
	groupadd -r $group
    fi
done

for user in faraday juliet
do
    if id -u $user >& /dev/null
    then
    	echo "$user already exists"
    else
	useradd -G profs $user
    fi
done

for user in jack kate james
do
    if id -u $user >& /dev/null
    then
    	echo "$user already exists"
    else
	useradd -G grads $user
    fi
done

for user in walt ben clair hugo
do
    if id -u $user >& /dev/null
    then
    	echo "$user already exists"
    else
	useradd -G interns $user
    fi
done

if id -u elvis >& /dev/null
then
    echo "elvis already exists"
else
    useradd -G profs,grads,interns elvis
fi

echo "done!"

exit 0
