#!/bin/bash
#
# by: George Hacker (20101029)
#
# Setup script for the command line file management lab/criterion test.
# 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
LOG_FACILITY=local0
LOG_PRIORITY=info
LOG_TAG=filemgmt
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"

# Create users and folders/directories featured in the student guide.
for user in bowe brad mark
do
	useradd ${user}
	echo password | passwd --stdin ${user} >& /dev/null
	chmod 755 /home/${user}
done

# Set up Bowe's lab writeups.
mkdir -p ~bowe/{chemistry,physics}
for file in lab{1..3}.txt
do
	path=~bowe/chemistry/$file
	echo "This file was originally $path" > $path
	path=~bowe/physics/$file
	echo "This file was originally $path" > $path
done

# Set up Brad's photos for the criterion test.
mkdir -p ~brad/camera ~brad/photos/{family,places,work}
for file in redhat_0{1..3}.jpg new_york_0{4..9}.jpg new_york_bad_10.jpg \
	tokyo_{11..15}.jpg redhat_bad_{16..18}.jpg redhat_{19..25}.jpg \
	jenny_{26..31}.jpg jenny_bad_32.jpg 
do
	path=~brad/camera/$file
	echo "This file was originally $path" > $path
done

# Set up Mark's music collection for examples and lab work.
mkdir -p ~mark/{docs,pics} ~mark/mp3/{abba,beethoven,blondie,mozart,the-police}
for file in ~mark/mp3/mozart/{call-me,symphony11,requiem,roxanne}.mp3 \
    ~mark/mp3/abba/{fernando,dancing-queen}.mp3 ~mark/mp3/playlist.txt
do
	echo "This file was originally $file" > $file
done

chown -R bowe:bowe ~bowe
chown -R brad:brad ~brad
chown -R mark:mark ~mark


echo "done!"

exit 0
