#!/bin/bash
#
# by: Robert Locke (20101130)
# based on: Brian Butler
#
# Grade the third file management 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
LOG_FACILITY=local0
LOG_PRIORITY=info
LOG_TAG=fm3Grade
DEBUG=false
ERROR_MESSAGE="FAILED."
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"

# Check for files distributed to proper places.
echo
echo -n "Checking for files to be moved to photos subdirs... "
success=1
( find /home/brad -name 'jenny*.jpg' | grep -v photos/family &>/dev/null ) && success=0
( find /home/brad -name 'newyork*.jpg' | grep -v photos/places &>/dev/null ) && success=0
( find /home/brad -name 'tokyo*.jpg' | grep -v photos/places &>/dev/null ) && success=0
( find /home/brad -name 'redhat*.jpg' | grep -v photos/work &>/dev/null ) && success=0
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

# Check that all files with bad in the name are gone.
echo
echo "Checking that all bad files are gone... "
list=$(find /home/brad -name '*bad*.jpg' 2>/dev/null)
[ -z "${list}" ] && echo "PASSED." || exit 1

# Check for symbolic link
echo
echo "Checking for symbolic link... "
[ -L /home/brad/photos/jenny ] || exit 1
( ls -l /home/brad/photos/jenny | grep '/home/brad/photos/jenny -> family' &>/dev/null ) && echo "PASSED." || exit 1

exit 0
