+Find .rpmnew files automatically.
[nethome.git] / bin / rpmmerge
1 #! /bin/sh
2 # $Id$
3
4 set -ex
5 l="$*"
6 [ -z "$l" ] && l="$(rpm -qla|perl -lne 'chomp;s/$/.rpmnew/;print if -f;')"
7 for base in $l;do
8         base=`echo $base|sed 's/[.]rpmnew$//'`
9         test -f $base
10         test -f $base.rpmnew
11         test ! -f $base.orig
12         test ! -f $base.rej
13
14         if test ! -f $base-orig
15         then
16                 cmp $base $base.rpmnew
17                 mv -f $base.rpmnew $base
18                 continue
19         fi
20
21         if diff -u $base-orig $base.rpmnew | patch -f $base
22         then
23                 test ! -f $base.rej
24                 rm -f $base.orig
25                 mv -f $base.rpmnew $base-orig
26                 continue
27         fi
28         test -f $base.orig
29         test -f $base.rej
30         mv -f $base.orig $base
31         rm -f $base.rej
32         exit 1
33 done
34
35 rpm -qac|perl -ne 'chomp;next if $_ eq "(contains no files)";next if m{^/var/lib/rpm/};next if ! -f $_;$o="$_-orig";next if -e $o;system "cp -i -p '\''$_'\'' '\''$o'\''" and die "$_: $!";'
36
37 echo OK