#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
LOG_FILE="/var/tmp/yum-update-review.txt"
ADMINS="levans@binghamton.edu,chouck@binghamton.edu,jramsay@binghamton.edu"
exec 3>&1 4>&2 >$LOG_FILE 2>&1
REL_UPDATE="`yum check-update oraclelinux-release | awk '/oraclelinux-release/{print $2}'`"
if [ ! "${REL_UPDATE:-x}" = "x" ]
then
   echo "WARNING: Linux Release Update for host: `hostname -s` ..."
   echo "Current: `cat /etc/redhat-release | awk '{print $7}'`"
   echo "    New: `echo $REL_UPDATE | sed -e 's/-.*//;s/^.*://'`"
   echo ""
   echo "Recommendation: perform manual update."
   echo ""
else
   echo "The following patches are now available for host: `hostname -s` ..."
   echo ""
   yum check-update | sed '1,3d' | awk '{print $1}' | cat -n
   echo ""
fi
exec 1>&3 2>&4
if [ -f $LOG_FILE ]
then
   [ -x `which email` ] && \
   cat $LOG_FILE | \
   email -q -b -s "`hostname -s`: yum-update" \
   -n "NO REPLY" -f "noreply@binghamton.edu" "$ADMINS"
   rm -f $LOG_FILE
else
   cat $LOG_FILE | mailx -s "`hostname -s`: yum-update" "$ADMINS"
fi
exit 0
