#! /bin/bash # This script updates rpms distribution trees found in one or two arguments # given to this script. The first is assumed to be in the Mandrake/RPMS # directory below this first base name, while the second is in the # Mandrake/RPMS1 directory below the second argument given # Note that you need only give the first if you wish. # The old rpms will be placed in $OLDDIR. # The new rpms should be located in $UPDDIR. # NEWFILES determines whether new files (ie files not found in the #directory tree) are added to one of the CD RPMS directories or not. # It should be set to the number of the CD to which the files should be added # if they are new. Do Not use 0 if you do not want new files copied. NEWFILES="99" if [ $NEWFILES -lt 1 -o $NEWFILES -gt $# ]; then NEWFILES="99" fi if [ $# -le 1 -o $# -gt 3 ]; then echo "Usage: update-CD updates_dir CD1dir [CD2dir]" echo " where update-CD has the updated files in the RPMS directory," echo " and CD1dir and CD2dir are the tops of the tree containing the CD files" exit 1 fi UPROOT="$1" RPMDIR[1]="$2/Mandrake/RPMS" RPMDIR[2]="" NUM_CD="1" if [ "$#" = "3" ]; then RPMDIR[2]="$3/Mandrake/RPMS2" NUM_CD="1 2" fi NEWRPM="${RPMDIR[$NEWFILES]}" for i in $NUM_CD do if [ ! -d ${RPMDIR[$i]} ]; then echo CD$i RPM directory ${RPMDIR[$i]} does not exist. exit 1 fi done UPDDIR=${UPROOT}/RPMS OLDDIR=${UPROOT}/old/RPMS if [ ! -d $UPDDIR ] ; then echo Update directory $UPDDIR does not exit exit 1 fi if [ ! -d $OLDDIR ] ; then if mkdir -p $OLDDIR then echo made backup directory $OLDDIR else echo Cannot make backup directory exit 1 fi fi shopt -s nullglob for rpm in ${UPDDIR}/*.rpm ; do # Get the short name of the rpm file NAME=`rpm --queryformat "%{NAME}" -qp $rpm` if [ -n "$NAME" ]; then for i in $NUM_CD; do unset OLDNAME # find files in the distributions which start with that name for oldrpm in ${RPMDIR[$i]}/${NAME}*.rpm ; do if [ -n "$oldrpm" ]; then # See if the short name is the same if [ `rpm --queryformat "%{NAME}" -qp $oldrpm` = "$NAME" ]; then OLDNAME=$oldrpm; break fi fi done # copy the updated rpm file to the distribution and save the old file if [ -n "$OLDNAME" ]; then if [ "`basename $rpm`" != "`basename $OLDNAME`" ]; then mv -v $OLDNAME $OLDDIR cp -pv $rpm ${RPMDIR[$i]} fi fi done # If no rpm of same name found on any distribution, place into appropriate # distribution according to NEWFILES if [ -z "$OLDNAME" ]; then if [ -n "${RPMDIR[$NEWFILES]}" ]; then echo --- $NAME is new-- copying to ${RPMDIR[$NEWFILES]} cp -pv $rpm ${RPMDIR[$NEWFILES]} fi fi fi done chmod -R a+rX $2/Mandrake/RPMS if [ $# -eq 3 ]; then chmod -R a+rX $3/Mandrake fi exit 0