#!/bin/bash
#
#  NAME
#	gls-grade-rootpw - confirm the system
#
#  USAGE
#	gls-grade-rootpw
#
#  DESCRIPTION
#	This script changes the root account password to an unknown
#	string then reboots the system.  This script is used in the
#	assessment lab that teaches learners how to boot into a specific
#	run-level.
#
#	The --noreboot option prevents the system from rebooting.
#
#  CHANGELOG
#	* Mon Jul 05 2010 George Hacker <ghacker@redhat.com>
#	- Original code

PATH=/bin:/usr/bin:/sbin:/usr/sbin

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

if [[ ! -f ${timestampfile} ]]
then
	echo "Error: You didn't run gls-munge-rootpw 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

