#!/bin/bash
#
# by: Robert Locke (20101130)
# based on: Brian Butler
#
# Grade the second packages criterion
# 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=centralstoreGrade
DEBUG=false
ERROR_MESSAGE="FAILED."
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
userInput="no"
set -o pipefail
RPM=/bin/rpm

# 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 new packages
PACKAGES="xsane-gimp"
echo
echo -n "Checking for ${PACKAGES}..."
success=1
for package in ${PACKAGES} ; do
  $RPM -q ${package} &>/dev/null || success=0
done
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

# Check for updated package
PACKAGES="bzip2"
# Original: bzip2-1.0.5-6.1.el6.x86_64
# Updated: bzip2-1.0.5-7.el6_0.x86_64
echo
echo -n "Checking for updates to ${PACKAGES}..."
success=1
for package in ${PACKAGES} ; do
  $RPM -q ${package} | grep "el6_0" &>/dev/null || success=0
done
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

# Check for properly updated kernel
KERNELVER="2.6.32-71.el6"
echo
echo -n "Checking update of kernel..."
success=1
numkernels=$($RPM -q kernel | wc -l)
[ ${numkernels} -gt 1 ] || success=0 # More than one kernel
$RPM -q kernel | grep ${KERNELVER} &>/dev/null || success=0 # Original kernel
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

# Check for removed package
PACKAGES="xinetd"
echo
echo -n "Checking for removal of ${PACKAGES}..."
success=1
for package in ${PACKAGES} ; do
  $RPM -q ${package} &>/dev/null && success=0
done
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

exit 0
