#!/bin/bash
#
# by: Robert Locke (20101130)
# based on: Brian Butler
#
# Grade the first packages assessment
# 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="samba-client"
# Original: samba-client-3.5.4-68.el6.x86_64
# Updated: samba-client-3.5.4-68.el6_0.1.x86_64
echo
echo -n "Checking for updates to ${PACKAGES}..."
success=1
for package in ${PACKAGES} ; do
  $RPM -q ${package} | grep "el6_0\.1" &>/dev/null || success=0
done
[ ${success} -eq 1 ] && echo "PASSED." || exit 1

# Check for removed package
PACKAGES="vsftpd"
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
