xref: /aoo41x/main/sysui/desktop/util/pkgdiff.pl (revision cdf0e10c)
1: # -*- perl -*-
2eval 'exec perl -wS $0 ${1+"$@"}'
3    if 0;
4
5use File::Temp qw/ tempdir /;
6use File::Basename;
7use Cwd;
8
9$tempdir = tempdir();
10$dir = cwd();
11
12sub unpack_rpm
13{
14    my ($package) = @_;
15
16    system << "EOF"
17rpm --query --queryformat "[trigger%{TRIGGERTYPE} script (through %{TRIGGERSCRIPTPROG}) -- %{TRIGGERNAME}  %{TRIGGERVERSION}\n%{TRIGGERSCRIPTS}\n]" --package $package > triggers
18rpm --query --queryformat "%{PREIN}\n" --package $package > prein
19rpm --query --queryformat "%{POSTIN}\n" --package $package > postin
20rpm --query --queryformat "%{PREUN}\n" --package $package > preun
21rpm --query --queryformat "%{POSTUN}\n" --package $package > postun
22rpm --query --queryformat "[%{FILEMODES:perms} %{FILEUSERNAME}/%{FILEGROUPNAME} .%{FILENAMES} -> %{FILELINKTOS}\n]" --package $package | sed 's/ -> \$//' | sort --key=3 -o filelist
23
24rpm2cpio $package | cpio --extract --make-directories
25
26rm --force `sed --silent 's|^lrw.r..r..-* root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
27EOF
28
29# the last step removes all symbolic links from the extracted file tree as they
30# are handled by diffing the filelist
31}
32
33sub unpack_deb
34{
35    my ($package) = @_;
36
37    system << "EOF"
38ar x $package control.tar.gz data.tar.gz
39tar --extract --ungzip --file=control.tar.gz
40rm --force control control.tar.gz
41tar --extract --ungzip --file=data.tar.gz
42tar --list --verbose --ungzip --file=data.tar.gz | sed -e 's| root/root .* \./|- root/root ./|' -e 's|^d\\(.*\\)/\$|d\\1|' | sort --key=3 -o filelist
43rm --force data.tar.gz
44
45rm --force `sed --silent 's|^lrw.r..r..- root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
46EOF
47
48# the last step removes all symbolic links from the extracted file tree as they
49# are handled by diffing the filelist
50}
51
52sub unpack_solpkg
53{
54    my ($package) = @_;
55
56    system << "EOF"
57sed -e '1 d' -e 's/[0-9][0-9]* [0-9][0-9]* [0-9]\\{10\\}\$//' $package/pkgmap > filelist
58grep -v "^PSTAMP=" $package/pkginfo > pkginfo
59cp $package/install/* .
60if [ -f $package/archive/none.bz2 ]; then
61  bzcat $package/archive/none.bz2 | cpio -i -d
62else
63  cp -pr $package/reloc/* .
64fi
65EOF
66}
67
68sub unpack_tgz {
69   my ($package) = @_;
70
71  system << "EOF"
72cat $package | gunzip | tar -xf -
73EOF
74}
75
76my $script = basename($0);
77
78die "Usage: $script <package 1> <package 2>\n" unless $#ARGV == 1;
79
80my @pkgroot = ();
81
82while ( $#ARGV >= 0 )
83{
84    my $package = shift;
85
86    # make package paths absolute if necessary
87    $package = $dir . "/" . $package unless $package =~ /^\//;
88
89    my $basename = basename($package);
90
91    # when comparing identically named packages, append a "-2"
92    unless ( mkdir "$tempdir/$basename", 0777 ) {
93        $basename = $basename . "-2";
94        mkdir "$tempdir/$basename", 0777;
95    }
96
97    # change working directory, unpack the package and change back ..
98    die "Unable to change to unpack directory $tempdir/$basename: $!\n" unless chdir "$tempdir/$basename";
99
100    if ( $package =~ /\.rpm$/ )   { unpack_rpm( $package ); }
101    elsif( $package =~ /\.deb$/ ) { unpack_deb( $package ); }
102    elsif( -f "$package/pkgmap" ) { unpack_solpkg( $package ); }
103    elsif( $package =~ /\.tgz$/ ) { unpack_tgz( $package ); }
104
105    push @pkgroot, $basename;
106    chdir $dir;
107}
108
109# print "$0\n";
110
111die "Unable to change to working directory $tempdir: $!\n" unless chdir $tempdir;
112
113system "diff -ru @pkgroot[0] @pkgroot[1]";
114system "rm -rf *";
115
116chdir $dir;
117rmdir $tempdir;
118#print STDERR "rm -rf $tempdir\n";
119
120