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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#!/bin/sh
# Copyright 2002 Patrick J. Volkerding, Concord, CA, USA
# Copyright 2018 Patrick J. Volkerding, Sebeka, Minnesota, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
CWD=$(pwd)
# Display usage for basic usage errors:
usage() {
cat << EOF
pkgdiff: missing file arguments
Try 'pkgdiff --help' for more information.
EOF
}
# Display full --help if requested:
helpme() {
cat << EOF
Usage: pkgdiff [OPTION] FILE1 FILE2
Show which files are new and which are removed between two tar archives.
The tar archives may be uncompressed, or compressed with gzip, bzip2,
xz, or lzip. Also works with .rpm and .deb.
--help display this help and exit
-c use ANSI color with default tree mode
-a show simple text (ASCII) diff of package file lists
By default, the trees are drawn with in crude ASCII with no color. For
the full-color effect, try something like this:
pkgdiff -c package1 package2 | less -r
EOF
# --help doesn't return
exit 22
}
# How the heck do I open this?
explode() {
tar xf $1 1> /dev/null 2> /dev/null
# Check for common extensions and do additional magic:
if [ ! "$(basename $1)" = "$(basename $1 .zip)" ]; then
unzip $1 1> /dev/null 2> /dev/null
fi
if [ ! "$(basename $1)" = "$(basename $1 .rpm)" ]; then
cp $1 .
rpm2tgz $(basename $1) 1> /dev/null 2> /dev/null
rm -f $(basename $1)
tar xzf $(basename $1 .rpm).tgz 1> /dev/null 2> /dev/null
rm -f $(basename $1 .rpm).tgz
fi
if [ ! "$(basename $1)" = "$(basename $1 .deb)" ]; then
cp $1 .
ar x $(basename $1) 1> /dev/null 2> /dev/null
tar xf data.tar.xz 1> /dev/null 2> /dev/null
rm -f * 2> /dev/null
fi
# Diffs for other archive formats are welcome.
}
# Parse options.
# -c turns on colorization ala dircolors:
unset COLOR
if [ "$1" = "-c" ]; then
COLOR="-C"
shift 1
fi
if [ "$1" = "-a" ]; then
ASCII=true
shift 1
fi
if [ "$1" = "--help" ]; then
helpme
fi
TMPDIR=$(mktemp -d)
cd $TMPDIR
if [ ! -r "$1" ]; then
if [ -d "$CWD/$1" ]; then
usage
exit 99
else
PKG1="$CWD/$1"
fi
else
PKG1="$1"
fi
if [ ! -r "$2" ]; then
if [ -d "$CWD/$2" ]; then
usage
#echo "pkgdiff -- find the difference between two tar archives"
#echo "usage: pkgdiff [ -C ] pkg1 pkg2"
exit 99
else
PKG2="$CWD/$2"
fi
else
PKG2="$2"
fi
# We have to account for the possibility that the packages have the
# same name, but different contents...
if [ "$(basename $PKG1)" = "$(basename $PKG2)" ]; then
PKG1=${PKG1}.orig
fi
# This will be mighty safe even if we ended up in /tmp.
PKG=.pkgdiff.$(mcookie)
( mkdir -p $TMPDIR/$PKG/1
cd $TMPDIR/$PKG/1
if [ -r $PKG1 ]; then
explode $PKG1
elif [ -r $(dirname $PKG1)/$(basename $PKG1 .orig) ]; then
explode $(dirname $PKG1)/$(basename $PKG1 .orig)
fi
if [ ! "$ASCII" = "true" ]; then
tree $COLOR -a --noreport > ../$(basename $PKG1)
else
find ./ | sed '2,$s,^\./,,' | tar --no-recursion -T - -cf - | tar tf - | sort > ../$(basename $PKG1)
fi
)
( mkdir -p $TMPDIR/$PKG/2
cd $TMPDIR/$PKG/2
explode $PKG2
if [ ! "$ASCII" = "true" ]; then
tree $COLOR -a --noreport > ../$(basename $PKG2)
else
find ./ | sed '2,$s,^\./,,' | tar --no-recursion -T - -cf - | tar tf - | sort > ../$(basename $PKG2)
fi
)
# Always going that extra mile... ;)
if [ -r $PKG1 ]; then
touch -r $PKG1 $TMPDIR/$PKG/$(basename $PKG1)
elif [ -r $(dirname $PKG1)/$(basename $PKG1 .orig) ]; then
touch -r $(dirname $PKG1)/$(basename $PKG1 .orig) $TMPDIR/$PKG/$(basename $PKG1)
fi
touch -r $PKG2 $TMPDIR/$PKG/$(basename $PKG2)
rm -rf $TMPDIR/$PKG/{1,2}
( cd $TMPDIR/$PKG ; diff -d -u $(basename $PKG1) $(basename $PKG2) )
# cleanup:
rm -rf $PKG $TMPDIR
|