#!/bin/bash
#
# by: Brian Butler (20100907)
#     George Hacker (20100705) Munge root password grading code
#
# Grading script for the munged root password 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=bootbreak4
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"

runlevel=$(runlevel | sed 's/.* //')
timestampfile=/tmp/.lab-munge-rootpw

if [[ ! -f ${timestampfile} ]]
then
	echo "Error: You didn't run lab-setup-rootbreak-4 to break the system!"
	exit 1

elif [[ "${runlevel}" != 5 ]]
then
	echo 'FAIL: Not in run level 5'
	exit 1
else
	now=$(date +%s)
	start_time=$(stat -c %Z ${timestampfile})
	seconds=$((now - start_time))
	echo "PASS: Time since broken = ${seconds} seconds"
	rm -f ${timestampfile}
fi

exit 0
