#! /bin/bash #USEAGE: update-distr [-f] [-v] path/to/updates # update rpms found in path/to/updates/RPMS # -f use --nodeps on second try to update rpms # -v verbose output # Note that -f and -v must be used in that order and cannot be combined # into -fv or -vf # This script updates the system from the files found in the first # arguement. if [ $# -lt 1 -o $# -gt 3 ]; then echo "Usage: update-distr updates_dir " echo " where updates_dir has the updated files in the RPMS directory," exit 1 fi VERBOSE=0 REDIR=">/dev/null" QUAL="" if [ "$1" = "-f" ]; then QUAL="--nodeps" shift fi if [ "$1" = "-v" ]; then VERBOSE=1 REDIR="" shift fi UPROOT="$1" UPDDIR=${UPROOT}/RPMS if [ ! -d $UPDDIR ] ; then echo Update directory $UPDDIR does not exit >&2 exit 1 fi shopt -s nullglob NDO=0 for rpm in ${UPDDIR}/*.rpm ; do # Get the short name of the rpm file NAME=`rpm --queryformat "%{NAME}" -qp $rpm 2>/dev/null` VERSION=`rpm -qp $rpm 2>/dev/null` if [ -n "$NAME" ]; then # find files in the distributions which start with that name if OVERSION=`rpm -q $NAME 2>/dev/null ` ; then if rpm -q $VERSION >/dev/null 2>&1 ; then if [ $VERBOSE -eq 1 ]; then echo $VERSION already installed fi else echo Updating $OVERSION from $rpm if [ $VERBOSE -eq 1 ]; then rpm -Fhv $rpm else rpm -Fhv $rpm >/dev/null fi if [ $? -ne 0 ]; then NDO=$[NDO +1] REDO[$NDO]=$rpm fi fi fi fi done if [ $NDO -gt 0 ];then if [ $VERBOSE -eq 1 ]; then echo echo "Trying again with problem rpms" fi echo NC=1 while [ $NC -le $NDO ]; do rpm=${REDO[$NC]} NC=$[NC+1] rpm -Fhv $rpm if [ $? -ne 0 ]; then echo echo Unable to update $rpm on second round. >&2 if [ -n "$QUAL" ]; then echo Look at the errors above: Do you want to echo -n force the installation of this package{y/n}: read RESP if [ -z "$RESP" ]; then RESP=n fi case $RESP in [Yy]*) rpm -Uhv $QUAL $rpm ;; esac else echo " Check error and try again" >&2 fi echo else if [ $VERBOSE -eq 1 ]; then echo "Updated $rpm" fi fi done fi exit 0