Listing 1 Grabpatch
#!/sbin/sh
#############################################################
#
# grabpatch.sh
#
# Description: This script examines the system determines
# whether the system is development or production, from
# this information the host will download the patch
# cluster for it's o/s and unpack it in the appropriate
# directory defined in the hosts_type file located on the
# patch server.
#
# production machines get a older patch cluster, developement
# machines get the lastest patch cluster.
#
# Author: James Hartley
# Date: 09/06/2006
#
# Special Requirements:
# patchdir is a share on the patch server where patches
# are located. This share must exist and the directory
# must have the format defined as follows.
#
# patchdir ----
# | Production -----
# |5.8
# |5.9
# |5.10
# | Development -----
# |5.8
# |5.9
# |5.10
# | host_type
#
# where Production is the earlier patch cluster directory
# where Development is the latest patch cluster directory
# and host_type is a file containing a list of servers and
# it's type, either Production, or Development, and it's
# installpatch directory:
#
# example
#
# santafe development /var/tmp
# killbill2.ymp.gov development /var/tmp
#
# The directories Solaris8, Solaris9, and Solaris10 contain
# the patchclusters.
#
# The script should be installed in the /admin/software/patches
# directory and roots crons should be edited to execute this
# script before cron runs the patch script.
#
# Basic Operation:
#
# if [ -f /etc/patchflag ] is true
#
# The system will attempt to grab the correct patch cluster
# from the patch directory. The system creates a file
#
# /etc/patchlog
#
# and logs the success or failure of the script. If the
# script is successful then the patch clusters are logged.
# if the script is unsuccessful the reason for the failure
# is noted and the script removes the /etc/patchflag so
# the install script does not run. The system also moves
# the file
#
# /etc/patchlog
# to
# /etc/patchlog.`date +%y%m%d`
#
# This file can then be examined for failure.
#
###############################################
# this line for testing.
set -x
#
# Grab some environment information
#
PATH=/usr/sbin:/usr/bin
export PATH
HOSTNAME=`/usr/bin/hostname`
OS=`/usr/bin/uname -r`
LOGFILE="/etc/patchlog"
PATCHFLAG="/etc/patchflag"
PATCHDIR="/patches"
HOSTTYPE="host_type"
FROM="unixdude_from_mars@ymp.gov"
SUBJECT="grabpatch $HOSTNAME"
RECIPIENT="root"
CURRENT_RUNLEVEL=`/usr/bin/who -r | /usr/bin/awk '{print $7}'`
mailmessage ()
{
echo $1 | mailx -r $FROM -s $SUBJECT $RECIPIENT
}
#
# Begin execution
#
if [ $CURRENT_RUNLEVEL = 3 -a -f $PATCHFLAG ];then
echo "making current $LOGFILE"
if [ -f "$LOGFILE" ]; then
rm $LOGFILE
fi
touch $LOGFILE
if [ ! -f "$PATCHDIR/$HOSTTYPE" ]; then
echo -x "ERROR:unable to find the patch host and/or \
host_type file\n" >> $LOGFILE
echo "patch failed" >> $LOGFILE
mailmessage "grabpatch failed: unable to find the patch host \
and/or host_type file"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 1
fi
SYSTEMTYPE=`grep "^$HOSTNAME" $PATCHDIR/$HOSTTYPE | awk '{ print $2 }'`
INSTALLDIR=`grep "^$HOSTNAME" $PATCHDIR/$HOSTTYPE | awk '{ print $3 }'`
SOL=`echo $OS | sed 's/5.//'`
if [ -z "$SYSTEMTYPE" ]; then
echo "undefined variable: check host_type file" >> $LOGFILE
mailmessage "grabpatch failed: undefined varible: check host_type file"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 1
fi
if [ -z "$INSTALLDIR" ]; then
echo "undefined variable: check host_type file" >> $LOGFILE
mailmessage "grabpatch failed: undefined varible: check host_type file"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 1
fi
if [ -z "$SOL" ]; then
echo "OS undefined: check uname binary switch -r" >> $LOGFILE
mailmessage "grabpatch failed: OS undefined: check uname \
binary switch -r"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 1
fi
echo "$HOSTNAME $OS $PATCHDIR $LOGFILE $SYSTEMTYPE $INSTALLDIR" \
>> $LOGFILE
echo "INSTALLDIRECTORY $INSTALLDIR" >> $LOGFILE
#
# clean up the Install directory, we want
# NO .zip files and
# NO patch cluster directories.
#
if [ -d $INSTALLDIR ]; then
rm $INSTALLDIR/*.zip
for file in `ls -l $INSTALLDIR | grep '^d' | awk '{ print $9}'`;
do
if [ -f $INSTALLDIR/$file/install_cluster ]; then
rm -r $INSTALLDIR/$file
fi
done
else
echo "$INSTALLDIR does not exist patch failed" >> $PATCHLOG
mailmessage "grabpatch failed: $INSTALLDIR does not exist"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 2
fi
#
# grab the recommended patches
#
echo "copying patch files onto the host" >> $LOGFILE
GOOD="no"
if cp $PATCHDIR/$SYSTEMTYPE/$OS/${SOL}_Recommended.zip \
$INSTALLDIR; then
echo "downloaded $PATCHDIR/$SYSTEMTYPE/$OS/${SOL}_Recommended.zip" \
>> $PATCHLOG
GOOD="yes"
fi
if cp $PATCHDIR/$SYSTEMTYPE/$OS/J2SE_Solaris_${SOL}_Recommended.zip \
$INSTALLDIR; then
echo "downloaded $PATCHDIR/$SYSTEMTYPE/$OS/ \
J2SE_Solaris_${SOL}_Recommended.zip" >> $PATCHLOG
GOOD="yes"
fi
if [ $GOOD = "no" ]; then
echo "Did not get any patches downloaded so exit" >> $PATCHLOG
mailmessage "grabpatch failed: nothing to grab or copy failed"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
exit 3
fi
#
# unzip the files in the install directory
#
cd $INSTALLDIR
if [ -f ${SOL}_Recommended.zip ]; then
unzip ${SOL}_Recommended.zip
if [ $? -ne 0 ]; then
echo "error unpacking ${SOL}_Recommended.zip" >> $LOGFILE
mailmessage "grabpatch failed: error unpacking \
${SOL}_Recommended.zip"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
rm -r ${SOL}_Recommended
exit 4
fi
fi
if [ -f J2SE_Solaris_${SOL}_Recommended.zip ]; then
unzip J2SE_Solaris_${SOL}_Recommended.zip
if [ $? -ne 0 ]; then
echo "error unpacking J2SE_Solaris_${SOL}_Recommended.zip" \
>> $LOGFILE
mailmessage "grabpatch failed: error unpacking \
J2SE_Solaris_${SOL}_Recommended.zip"
mv $LOGFILE $LOGFILE.`date +%y%m%d`
rm $PATCHFLAG
rm -r J2SE_Solaris_${SOL}_Recommended
exit 4
fi
fi
#
# log the cluster directories for future reference
#
for file in `ls -l | grep '^d' | awk '{ print $9 }'`;
do
cd $file
if [ -f install_cluster ]; then
echo "PATCHCLUSTER $file" >> $LOGFILE
fi
cd $INSTALLDIR
done
#*****************************#
# successful grab exit script #
# so exit script #
#*****************************#
#*******************************#
# we do not mv the $LOGFILE but #
# leave it for the patch script #
# to use for logging #
#*******************************#
mailmessage "grabpatch sucessful CONGRADULATION"
exit 0
else
exit 0
fi
|