#!/bin/bash
#
# by: Brian Butler (20100907)
#
# Grading script for the samba lab
# this script is to be installed and run on both 
# desktopX.exmaple.com and 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=bloomin
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

# Determine which host we are running on
stationNum="$(hostname -s | grep -o "[0-9]*")"
if (hostname -s | grep -q "^server$stationNum$"); then 
# Check that aide is installed
    echo -n "Checking that aide is installed... "
    PACKAGES=( aide )
    check_packages
    echo "PASSED."
# Check to see if the aide database is initialized and renamed
    echo
    echo -n "Checking that the aide database has been setup... "
    [ -s /var/lib/aide/aide.db.gz ] && echo "PASSED." || exit 1
# Send log event to syslog for testing on desktopX
    echo "REMOTE LOG TEST" > log
elif (hostname -s | grep -q "^desktop$stationNum$"); then
# Check /var/log/messages for log messages from serverX
    echo -n "Checking that rsyslogd is receiving remote logs... "
    (grep -q "server$stationNum" /var/log/messages) && echo "PASSED." || exit 1
fi
