#!/bin/bash
# 
# by: Brian Butler (20100902)
#
# Grading script for the Howson Heavy Clock case study
# this script is to be installed and run on desktopX.example.com
# output is logged to syslog

# Set environment variables and globals
. /usr/local/lib/labtool.shlib
trap on_exit EXIT
LOG_FACILITY=local0
LOG_PRIORITY=info
LOG_TAG=howsonclockGrade
DEBUG=false
ERROR_MESSAGE="FAILED."
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
userInput="no"

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

# Check for required packages
PACKAGES=( ntp )
check_packages

# Test to make sure ntp is peered with the correct servers
echo -n "Checking that ntp is configured correctly... "
(ntpq -pn 2>&1 | tail -n +3 | sed 's/^\*/ /' | cut -d' ' -f2 &> /tmp/ntppeers)

cat /tmp/ntppeers | while read line ; do
    case "$line" in
        "192.168.0.254")
            peers=( instructor${peers} )
            ;;
        "192.168.0."*)
            peers=( ${peers}example )
            ;;
        *)
            exit 1
            ;;
    esac
    [ "$peers" = "instructorexampleexample" ] && ( echo "PASSED." ; exit 0 )
done
exit $?
