#!/bin/bash
#
# by: Robert Locke (20101207) 
#
# Setup script for the basic permissions 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 ateam bteam
do
    if grep "^$group:" /etc/group >& /dev/null
    then
    	echo "$group already exists"
    else
	groupadd -r $group
    fi
done

for user in alice andy
do
    if id -u $user >& /dev/null
    then
    	echo "$user already exists"
    else
	useradd $user
    fi
    usermod -a -G ateam $user
    echo "password" | passwd --stdin $user
done

for user in betty bill
do
    if id -u $user >& /dev/null
    then
    	echo "$user already exists"
    else
	useradd $user
    fi
    usermod -a -G bteam $user
    echo "password" | passwd --stdin $user
done

echo "done!"

exit 0
