Use subdirectories.
[nethome.git] / bin / rpmmerge
index 87c2297..c61a6b7 100755 (executable)
@@ -1,32 +1,63 @@
 #! /bin/sh
 # $Id$
 
+
 set -ex
-for base in "$@";do
+ok=true
+l="$*"
+[ -z "$l" ] && l="$(rpm -qla|perl -lne 'chomp;s/$/.rpmnew/;print if -f;')"
+for base in $l;do
        base=`echo $base|sed 's/[.]rpmnew$//'`
        test -f $base
        test -f $base.rpmnew
        test ! -f $base.orig
        test ! -f $base.rej
 
-       if test ! -f $base-orig
+       test ! -f $base-orig
+       # The old `-orig' format should be converted by:
+       # rpm -qla|perl -lne 'chomp;s/$/-orig/;next if ! -e;$o=$_;$o=~s/-orig$//;$o=~tr{/}{-};$o="/root/rpmmerge/$o";die $o if -e $o;$_="mv -f '\''$_'\'' '\''$o'\''";system $_ and die "$_: $!";'
+
+       orig="/root/rpmmerge/$base"
+
+       if test ! -f $orig
        then
                cmp $base $base.rpmnew
                mv -f $base.rpmnew $base
                continue
        fi
 
-       if diff -u $base-orig $base.rpmnew | patch -f $base
+       # Local changes present in new rpm?
+       if cmp -s $base $base.rpmnew
+       then
+               mv -f $base.rpmnew $base
+               cp -p $base $orig
+               continue
+       fi
+
+       if diff -u $orig $base.rpmnew | patch -N $base
        then
                test ! -f $base.rej
                rm -f $base.orig
-               mv -f $base.rpmnew $base-orig
+               mv -f $base.rpmnew $orig
                continue
        fi
        test -f $base.orig
        test -f $base.rej
        mv -f $base.orig $base
        rm -f $base.rej
-       exit 1
+
+       #exit 1
+       ok=false
+       continue
 done
-echo OK
+
+if $ok
+then
+       mkdir -p /root/rpmmerge
+       rpm -qac|perl -ne 'chomp;next if $_ eq "(contains no files)";next if m{^/var/lib/rpm/};next if $_ eq "/usr/lib/locale/locale-archive";next if ! -f $_;$o=$_;$o="/root/rpmmerge/$o";next if -e $o;$od=$o;$od=~s{[^/]*$}{};system "mkdir -p '\''$od'\''" and die "dir $_: $!";system "cp -i -p '\''$_'\'' '\''$o'\''" and die "$_: $!";'
+
+       echo OK
+else
+       echo ERRORS
+       exit 1
+fi