xref: /aoo42x/main/sysui/desktop/util/pkgdiff.pl (revision bb113e63)
1cdf0e10cSrcweir: # -*- perl -*-
2*bb113e63SAndrew Rist# *************************************************************
3*bb113e63SAndrew Rist#
4*bb113e63SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*bb113e63SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*bb113e63SAndrew Rist#  distributed with this work for additional information
7*bb113e63SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*bb113e63SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*bb113e63SAndrew Rist#  "License"); you may not use this file except in compliance
10*bb113e63SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*bb113e63SAndrew Rist#
12*bb113e63SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*bb113e63SAndrew Rist#
14*bb113e63SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*bb113e63SAndrew Rist#  software distributed under the License is distributed on an
16*bb113e63SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*bb113e63SAndrew Rist#  KIND, either express or implied.  See the License for the
18*bb113e63SAndrew Rist#  specific language governing permissions and limitations
19*bb113e63SAndrew Rist#  under the License.
20*bb113e63SAndrew Rist#
21*bb113e63SAndrew Rist# *************************************************************
22cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
23cdf0e10cSrcweir    if 0;
24cdf0e10cSrcweir
25cdf0e10cSrcweiruse File::Temp qw/ tempdir /;
26cdf0e10cSrcweiruse File::Basename;
27cdf0e10cSrcweiruse Cwd;
28cdf0e10cSrcweir
29cdf0e10cSrcweir$tempdir = tempdir();
30cdf0e10cSrcweir$dir = cwd();
31cdf0e10cSrcweir
32cdf0e10cSrcweirsub unpack_rpm
33cdf0e10cSrcweir{
34cdf0e10cSrcweir    my ($package) = @_;
35cdf0e10cSrcweir
36cdf0e10cSrcweir    system << "EOF"
37cdf0e10cSrcweirrpm --query --queryformat "[trigger%{TRIGGERTYPE} script (through %{TRIGGERSCRIPTPROG}) -- %{TRIGGERNAME}  %{TRIGGERVERSION}\n%{TRIGGERSCRIPTS}\n]" --package $package > triggers
38cdf0e10cSrcweirrpm --query --queryformat "%{PREIN}\n" --package $package > prein
39cdf0e10cSrcweirrpm --query --queryformat "%{POSTIN}\n" --package $package > postin
40cdf0e10cSrcweirrpm --query --queryformat "%{PREUN}\n" --package $package > preun
41cdf0e10cSrcweirrpm --query --queryformat "%{POSTUN}\n" --package $package > postun
42cdf0e10cSrcweirrpm --query --queryformat "[%{FILEMODES:perms} %{FILEUSERNAME}/%{FILEGROUPNAME} .%{FILENAMES} -> %{FILELINKTOS}\n]" --package $package | sed 's/ -> \$//' | sort --key=3 -o filelist
43cdf0e10cSrcweir
44cdf0e10cSrcweirrpm2cpio $package | cpio --extract --make-directories
45cdf0e10cSrcweir
46cdf0e10cSrcweirrm --force `sed --silent 's|^lrw.r..r..-* root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
47cdf0e10cSrcweirEOF
48cdf0e10cSrcweir
49cdf0e10cSrcweir# the last step removes all symbolic links from the extracted file tree as they
50cdf0e10cSrcweir# are handled by diffing the filelist
51cdf0e10cSrcweir}
52cdf0e10cSrcweir
53cdf0e10cSrcweirsub unpack_deb
54cdf0e10cSrcweir{
55cdf0e10cSrcweir    my ($package) = @_;
56cdf0e10cSrcweir
57cdf0e10cSrcweir    system << "EOF"
58cdf0e10cSrcweirar x $package control.tar.gz data.tar.gz
59cdf0e10cSrcweirtar --extract --ungzip --file=control.tar.gz
60cdf0e10cSrcweirrm --force control control.tar.gz
61cdf0e10cSrcweirtar --extract --ungzip --file=data.tar.gz
62cdf0e10cSrcweirtar --list --verbose --ungzip --file=data.tar.gz | sed -e 's| root/root .* \./|- root/root ./|' -e 's|^d\\(.*\\)/\$|d\\1|' | sort --key=3 -o filelist
63cdf0e10cSrcweirrm --force data.tar.gz
64cdf0e10cSrcweir
65cdf0e10cSrcweirrm --force `sed --silent 's|^lrw.r..r..- root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
66cdf0e10cSrcweirEOF
67cdf0e10cSrcweir
68cdf0e10cSrcweir# the last step removes all symbolic links from the extracted file tree as they
69cdf0e10cSrcweir# are handled by diffing the filelist
70cdf0e10cSrcweir}
71cdf0e10cSrcweir
72cdf0e10cSrcweirsub unpack_solpkg
73cdf0e10cSrcweir{
74cdf0e10cSrcweir    my ($package) = @_;
75cdf0e10cSrcweir
76cdf0e10cSrcweir    system << "EOF"
77cdf0e10cSrcweirsed -e '1 d' -e 's/[0-9][0-9]* [0-9][0-9]* [0-9]\\{10\\}\$//' $package/pkgmap > filelist
78cdf0e10cSrcweirgrep -v "^PSTAMP=" $package/pkginfo > pkginfo
79cdf0e10cSrcweircp $package/install/* .
80cdf0e10cSrcweirif [ -f $package/archive/none.bz2 ]; then
81cdf0e10cSrcweir  bzcat $package/archive/none.bz2 | cpio -i -d
82cdf0e10cSrcweirelse
83cdf0e10cSrcweir  cp -pr $package/reloc/* .
84cdf0e10cSrcweirfi
85cdf0e10cSrcweirEOF
86cdf0e10cSrcweir}
87cdf0e10cSrcweir
88cdf0e10cSrcweirsub unpack_tgz {
89cdf0e10cSrcweir   my ($package) = @_;
90cdf0e10cSrcweir
91cdf0e10cSrcweir  system << "EOF"
92cdf0e10cSrcweircat $package | gunzip | tar -xf -
93cdf0e10cSrcweirEOF
94cdf0e10cSrcweir}
95cdf0e10cSrcweir
96cdf0e10cSrcweirmy $script = basename($0);
97cdf0e10cSrcweir
98cdf0e10cSrcweirdie "Usage: $script <package 1> <package 2>\n" unless $#ARGV == 1;
99cdf0e10cSrcweir
100cdf0e10cSrcweirmy @pkgroot = ();
101cdf0e10cSrcweir
102cdf0e10cSrcweirwhile ( $#ARGV >= 0 )
103cdf0e10cSrcweir{
104cdf0e10cSrcweir    my $package = shift;
105cdf0e10cSrcweir
106cdf0e10cSrcweir    # make package paths absolute if necessary
107cdf0e10cSrcweir    $package = $dir . "/" . $package unless $package =~ /^\//;
108cdf0e10cSrcweir
109cdf0e10cSrcweir    my $basename = basename($package);
110cdf0e10cSrcweir
111cdf0e10cSrcweir    # when comparing identically named packages, append a "-2"
112cdf0e10cSrcweir    unless ( mkdir "$tempdir/$basename", 0777 ) {
113cdf0e10cSrcweir        $basename = $basename . "-2";
114cdf0e10cSrcweir        mkdir "$tempdir/$basename", 0777;
115cdf0e10cSrcweir    }
116cdf0e10cSrcweir
117cdf0e10cSrcweir    # change working directory, unpack the package and change back ..
118cdf0e10cSrcweir    die "Unable to change to unpack directory $tempdir/$basename: $!\n" unless chdir "$tempdir/$basename";
119cdf0e10cSrcweir
120cdf0e10cSrcweir    if ( $package =~ /\.rpm$/ )   { unpack_rpm( $package ); }
121cdf0e10cSrcweir    elsif( $package =~ /\.deb$/ ) { unpack_deb( $package ); }
122cdf0e10cSrcweir    elsif( -f "$package/pkgmap" ) { unpack_solpkg( $package ); }
123cdf0e10cSrcweir    elsif( $package =~ /\.tgz$/ ) { unpack_tgz( $package ); }
124cdf0e10cSrcweir
125cdf0e10cSrcweir    push @pkgroot, $basename;
126cdf0e10cSrcweir    chdir $dir;
127cdf0e10cSrcweir}
128cdf0e10cSrcweir
129cdf0e10cSrcweir# print "$0\n";
130cdf0e10cSrcweir
131cdf0e10cSrcweirdie "Unable to change to working directory $tempdir: $!\n" unless chdir $tempdir;
132cdf0e10cSrcweir
133cdf0e10cSrcweirsystem "diff -ru @pkgroot[0] @pkgroot[1]";
134cdf0e10cSrcweirsystem "rm -rf *";
135cdf0e10cSrcweir
136cdf0e10cSrcweirchdir $dir;
137cdf0e10cSrcweirrmdir $tempdir;
138cdf0e10cSrcweir#print STDERR "rm -rf $tempdir\n";
139cdf0e10cSrcweir
140