#!/bin/bash # # Automatically fetch and upgrade the latest rpm packages. # Run this from cron every night to stay up to date on patches. # # This script runs rpmwatcher to get any new rpm updates, then # tries to install them. It first tries to install packages # individually, but if any fail then it tries to install them # all at once. # # Any packages in the rpm working directory are "upgraded" # using rpm -U so you can also put rpm's in the directory by hand # and they will be installed automatically. # # Eric Myers # @(#) $Id: rpmupdate,v 2.6 2004/04/03 15:45:58 myers Exp myers $ ######################################################################## PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin NAME=`basename $0` # Working directory for rpmwatcher. This should be the same directory in # your .rpmwatcher file, probably /root/rpm. Taken from .rpmwatcher file. if [ -f /root/.rpmwatcher ]; then LOCAL=`awk '$1 ~ /^local/ { print $2 }' /root/.rpmwatcher ` else echo "$NAME: cannot find the local rpm working direcotry." exit 1 fi ##### # Command line arguments FLAGS="" FILES="" QUIET="-hv" while [ $# != 0 ] do case "$1" in -q|-quiet) QUIET=" --quiet " ;; -*) FLAGS="$FLAGS $1" ;; *) FILES="$FILES $1" ;; esac shift done ################################################## # BEGIN: if [ -d $LOCAL ]; then cd $LOCAL else echo "$NAME: Cannot use $LOCAL" exit 2 fi ##### # Go and get any newer packages using rpmwatcher rpmwatcher -c -f /root/.rpmwatcher ##### # Loop through them and install them, one by one. Delete those that worked. LIST=`ls -A1 *.rpm 2>/dev/null` for PKG in $LIST do if rpm -U $QUIET $FLAGS $PKG then if rpm -V $PKG then /bin/rm -f $PKG fi fi done ##### # Individual installation may fail for linked packages, so try to # install remaining packages all at once. LIST=`ls -A1 *.rpm 2>/dev/null` if [ -z "$LIST" ]; then exit 0 fi if rpm -U $QUIET $FLAGS $LIST then if rpm -V $LIST then /bin/rm -f $LIST fi fi ##### # If anything remains now then they must be done by hand LIST=`ls -A1 *.rpm 2>/dev/null` if [ ! -z "$LIST" ]; then echo " " echo "#######" echo "$NAME: automatic update failed for these packages in ${LOCAL}" echo " " ls -1 $LIST echo " " echo "You will have to update these by hand." exit 3 fi exit 0