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