summaryrefslogtreecommitdiff
path: root/sysui/desktop/util/pkgdiff.pl
blob: c3435202d0cfbc5892ac28e19476f93d07ba6772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
: # -*- perl -*-
eval 'exec perl -wS $0 ${1+"$@"}'
    if 0;

#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
#   Licensed to the Apache Software Foundation (ASF) under one or more
#   contributor license agreements. See the NOTICE file distributed
#   with this work for additional information regarding copyright
#   ownership. The ASF licenses this file to you under the Apache
#   License, Version 2.0 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
#

use File::Temp qw/ tempdir /;
use File::Basename;
use Cwd;

$tempdir = tempdir();
$dir = cwd();

sub unpack_rpm
{
    my ($package) = @_;

    system << "EOF"
rpm --query --queryformat "[trigger%{TRIGGERTYPE} script (through %{TRIGGERSCRIPTPROG}) -- %{TRIGGERNAME}  %{TRIGGERVERSION}\n%{TRIGGERSCRIPTS}\n]" --package $package > triggers
rpm --query --queryformat "%{PREIN}\n" --package $package > prein
rpm --query --queryformat "%{POSTIN}\n" --package $package > postin
rpm --query --queryformat "%{PREUN}\n" --package $package > preun
rpm --query --queryformat "%{POSTUN}\n" --package $package > postun
rpm --query --queryformat "[%{FILEMODES:perms} %{FILEUSERNAME}/%{FILEGROUPNAME} .%{FILENAMES} -> %{FILELINKTOS}\n]" --package $package | sed 's/ -> \$//' | sort --key=3 -o filelist

rpm2cpio $package | cpio --extract --make-directories

rm --force `sed --silent 's|^lrw.r..r..-* root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
EOF

# the last step removes all symbolic links from the extracted file tree as they
# are handled by diffing the filelist
}

sub unpack_deb
{
    my ($package) = @_;

    system << "EOF"
ar x $package control.tar.gz data.tar.gz
tar --extract --ungzip --file=control.tar.gz
rm --force control control.tar.gz
tar --extract --ungzip --file=data.tar.gz
tar --list --verbose --ungzip --file=data.tar.gz | sed -e 's| root/root .* \./|- root/root ./|' -e 's|^d\\(.*\\)/\$|d\\1|' | sort --key=3 -o filelist
rm --force data.tar.gz

rm --force `sed --silent 's|^lrw.r..r..- root/root \\./\\(.*\\) -> .*|\\1 |p' filelist | tr -d "\\012"`
EOF

# the last step removes all symbolic links from the extracted file tree as they
# are handled by diffing the filelist
}

sub unpack_solpkg
{
    my ($package) = @_;

    system << "EOF"
sed -e '1 d' -e 's/[0-9][0-9]* [0-9][0-9]* [0-9]\\{10\\}\$//' $package/pkgmap > filelist
grep -v "^PSTAMP=" $package/pkginfo > pkginfo
cp $package/install/* .
if [ -f $package/archive/none.bz2 ]; then
  bzcat $package/archive/none.bz2 | cpio -i -d
else
  cp -pr $package/reloc/* .
fi
EOF
}

sub unpack_tgz {
   my ($package) = @_;

  system << "EOF"
cat $package | gunzip | tar -xf -
EOF
}

my $script = basename($0);

die "Usage: $script <package 1> <package 2>\n" unless $#ARGV == 1;

my @pkgroot = ();

while ( $#ARGV >= 0 )
{
    my $package = shift;

    # make package paths absolute if necessary
    $package = $dir . "/" . $package unless $package =~ /^\//;

    my $basename = basename($package);

    # when comparing identically named packages, append a "-2"
    unless ( mkdir "$tempdir/$basename", 0777 ) {
        $basename = $basename . "-2";
        mkdir "$tempdir/$basename", 0777;
    }

    # change working directory, unpack the package and change back ..
    die "Unable to change to unpack directory $tempdir/$basename: $!\n" unless chdir "$tempdir/$basename";

    if ( $package =~ /\.rpm$/ )   { unpack_rpm( $package ); }
    elsif( $package =~ /\.deb$/ ) { unpack_deb( $package ); }
    elsif( -f "$package/pkgmap" ) { unpack_solpkg( $package ); }
    elsif( $package =~ /\.tgz$/ ) { unpack_tgz( $package ); }

    push @pkgroot, $basename;
    chdir $dir;
}

# print "$0\n";

die "Unable to change to working directory $tempdir: $!\n" unless chdir $tempdir;

system "diff -ru @pkgroot[0] @pkgroot[1]";
system "rm -rf *";

chdir $dir;
rmdir $tempdir;
#print STDERR "rm -rf $tempdir\n";