+unset command_not_found_handle
[nethome.git] / bin / rpmmerge
1 #! /bin/sh
2 # $Id$
3
4
5 set -ex
6 ok=true
7 l="$*"
8 [ -z "$l" ] && l="$(rpm -qla|perl -lne 'chomp;s/$/.rpmnew/;print if -f;')"
9 for base in $l;do
10         base=`echo $base|sed 's/[.]rpmnew$//'`
11         test -f $base
12         test -f $base.rpmnew
13         test ! -f $base.orig
14         test ! -f $base.rej
15
16         test ! -f $base-orig
17         # The old `-orig' format should be converted by:
18         # 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 "$_: $!";'
19
20         orig="/root/rpmmerge/$base"
21
22         if test ! -f $orig
23         then
24                 cmp $base $base.rpmnew
25                 mv -f $base.rpmnew $base
26                 continue
27         fi
28
29         # Local changes present in new rpm?
30         if cmp -s $base $base.rpmnew
31         then
32                 mv -f $base.rpmnew $base
33                 cp -p $base $orig
34                 continue
35         fi
36
37         if diff -u $orig $base.rpmnew | patch -N $base
38         then
39                 test ! -f $base.rej
40                 rm -f $base.orig
41                 mv -f $base.rpmnew $orig
42                 continue
43         fi
44         test -f $base.orig
45         test -f $base.rej
46         mv -f $base.orig $base
47         rm -f $base.rej
48
49         #exit 1
50         ok=false
51         continue
52 done
53
54 if $ok
55 then
56         mkdir -p /root/rpmmerge
57         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 "$_: $!";'
58
59         echo OK
60 else
61         echo ERRORS
62         exit 1
63 fi