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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
#!/bin/bash
# -*- coding: utf-8 -*-
# msidiff - compare two MSI files table content with diff
# (originally based on rpmdev-diff)
#
# Copyright (c) 2004-2010 Ville Skyttä <ville.skytta@iki.fi>
# Copyright (c) 2013 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
set -e
unset CDPATH
tmpdir=
diffopts=
list=
long=
tables=
diffcopts=-Nup
diffoopts=-U0
trap cleanup EXIT
cleanup()
{
set +e
[ -z "$tmpdir" -o ! -d "$tmpdir" ] || rm -rf "$tmpdir"
}
version()
{
cat <<EOF
@PACKAGE_VERSION@
EOF
}
help()
{
cat <<EOF
msidiff diffs contents of two MSI files.
EOF
usage
echo ""
echo "Report bugs to <@PACKAGE_BUGREPORT@>."
}
usage()
{
cat <<EOF
Usage: msidiff [OPTION]... [DIFF-OPTIONS] FROM-MSI TO-MSI
Options:
-t, --tables Diff MSI tables as text. This is the default.
-l, --list Diff lists of files.
-L, --long-list Diff long lists (akin to 'find -ls') of files.
-h, --help Print help message and exit.
-v, --version Print version information and exit.
diff-options Options passed to diff(1). The first repeated argument of
the above or the first argument starting with a '-' but not
one of the above starts diff-options, the first one not
starting with it ends them. Default: $diffcopts for contents
(in addition to -r which will always be passed), -U0 for
others.
More than one of -t, -l or -L may be specified.
EOF
}
while true ; do
case $1 in
-t|--tables)
if [[ $tables$diffopts ]] ; then
diffopts+=" $1"
else
tables=true
fi
;;
-l|--list)
if [[ $list$diffopts ]] ; then
diffopts+=" $1"
else
list=true
fi
;;
-L|--long-list)
if [[ $long$diffopts ]] ; then
diffopts+=" $1"
else
long=true
fi
;;
-h|--help)
if [[ $diffopts ]] ; then
diffopts+=" $1"
else
help
exit 0
fi
;;
-v|--version)
if [[ $diffopts ]] ; then
diffopts+=" $1"
else
version
exit 0
fi
;;
-*)
diffopts+=" $1"
;;
*)
break
;;
esac
shift
done
if [[ $# -lt 2 ]] ; then
usage
exit 1
fi
for file in "$1" "$2" ; do
if [[ ! -f $file ]] ; then
[[ -e $file ]] && \
echo "Error: not a regular file: '$file'" >&2 ||
echo "Error: file does not exist: '$file'" >&2
exit 1
fi
done
tmpdir=`mktemp -d ${TMPDIR:-/tmp}/msidiff.XXXXXX`
mkdir "$tmpdir/old" "$tmpdir/new"
msidump --signature --tables --directory "$tmpdir/old" $1 >/dev/null
msidump --signature --tables --directory "$tmpdir/new" $2 >/dev/null
if ${list:-false} || ${long:-false} ; then
msiextract --directory "$tmpdir/old/files" $1 >/dev/null
msiextract --directory "$tmpdir/new/files" $2 >/dev/null
fi
cd "$tmpdir"
# Did the archives uncompress into base dirs?
if [[ $(ls -1d old/* | wc -l) -eq 1 ]] ; then
old=$(ls -1d old/*)
else
old=old
fi
if [[ $(ls -1d new/* | wc -l) -eq 1 ]] ; then
new=$(ls -1d new/*)
else
new=new
fi
# Fixup base dirs to the same level.
if [[ $(basename "$old") != $(basename "$new") ]] ; then
if [[ $old != old ]] ; then
mv "$old" .
old=`basename "$old"`
fi
if [[ $new != new ]] ; then
mv "$new" .
new=`basename "$new"`
fi
fi
# Tables mode is the default.
if [[ -z $list$tables$long ]] ; then
tables=true
else
tables=${tables:-false}
fi
list=${list:-false}
long=${long:-false}
# Here we go.
if $tables ; then
set +e
diff -r ${diffopts:-$diffcopts} "$old" "$new"
[[ $? -eq 0 || $? -eq 1 ]] || exit $?
set -e
fi
if $list ; then
find "$old/files" | sort | cut -d/ -f 3- -s > "$old.files"
find "$new/files" | sort | cut -d/ -f 3- -s > "$new.files"
set +e
diff ${diffopts:-$diffoopts} "$old.files" "$new.files"
[[ $? -eq 0 || $? -eq 1 ]] || exit $?
set -e
fi
if $long ; then
find "$old/files" -ls | \
perl -pe "s|^(?:[\d\s]*)(\S+)(?:\s+\d+)(.+)$|\1\2| ;
s|.*\s\Q$old/files\E$|| ; s|(\s)\Q$old/files/\E|\1|" | \
sort > "$old.files"
find "$new/files" -ls | \
perl -pe "s|^(?:[\d\s]*)(\S+)(?:\s+\d+)(.+)$|\1\2| ;
s|.*\s\Q$new/files\E$|| ; s|(\s)\Q$new/files/\E|\1|" | \
sort > "$new.files"
set +e
diff ${diffopts:-$diffoopts} "$old.files" "$new.files"
[[ $? -eq 0 || $? -eq 1 ]] || exit $?
set -e
fi
|