#!/bin/sh # replace *i686.rpm with given *i586.rpm # # Usage: # $0 ../DVD1/ RPMS/i586/pkg-1.0.i586.rpm # will replace ../DVD1/Packages/pkg-1.0.i686 with given pkg-1.0.i586 # by removing the former and hardlinking the latter # # PACKAGES=/media/IODATA40G/DVD1/Packages/ PACKAGES= test -d "$1"/CentOS && PACKAGES="$1"/CentOS test -d "$1"/Packages && PACKAGES="$1"/Packages test -d "$1"/RPMS && PACKAGES="$1"/RPMS if [ -z "$PACKAGES" ]; then echo No $1/Packages exist. 2>&1; exit 1; fi shift # arg1: "pkg" # return pkg-1.0.i686.rpm, or "" # find corresponding .i686.rpm in $PACKAGES/ get_i686_pkg () { N="$1" #linear search is slow find $PACKAGES -type f -name $N'*.rpm' | while read i686_rpm; do N6=`rpm -q --qf '%{N}' -p $i686_rpm` if [ "$N" = "$N6" ]; then echo FOUND $i686_rpm >&2; echo $i686_rpm return fi done echo "" return 1 } CTMP=/tmp/rep$$ trap "rm $CTMP" 0 1 2 15 cp /dev/null $CTMP for i586_rpm in "$@"; do ## get NAME of rpm N=`rpm -q --qf '%{N}' -p $i586_rpm` echo Finding $N ## find corresponding .i686.rpm in $PACKAGES/ i686_rpm=`get_i686_pkg $N` if [ -z "$i686_rpm" ]; then echo No corresponding $N.i686.rpm found. >&2 fi if [ -n "$i686_rpm" ]; then # Usually "rm"ing is right, but # if $i686_rpm was the same file as $i586_rpm, don't rm nor ln. if [ x`stat -c %d:%i $i586_rpm` != x`stat -c %d:%i $i686_rpm` ]; then echo rm "$i686_rpm" >> $CTMP if [ x`stat -c %d $i586_rpm` = x`stat -c %d $PACKAGES` ]; then echo ln $i586_rpm $PACKAGES >> $CTMP else echo cp -p $i586_rpm $PACKAGES >> $CTMP fi else : fi fi done echo '>>>>> preparing to do:' cat $CTMP echo '<<<<<' echo -n "Do it? [y/N] "; read yn; if [ "$yn" = "y" ]; then sh -x $CTMP fi #$CTMP erased by trap