-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmkdiff
More file actions
168 lines (134 loc) · 4.19 KB
/
Copy pathmkdiff
File metadata and controls
168 lines (134 loc) · 4.19 KB
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
#!/bin/sh
signing_key="0x4F25E3B6"
signing_options=" --digest-algo SHA384"
opt_sign=yes
ext=bz2
extz=j
opt_with_po=no
if [ "$1" = "--gzip-source" ]; then
ext=gz
extz=z
shift
fi
if [ "$1" = "--no-sign" ]; then
opt_sign=no
shift
fi
if [ "$1" = "--with-po" ]; then
opt_with_po=yes
shift
fi
if [ $# = 1 ]; then
pack="$1"
vprf=""
elif [ $# = 2 ] ; then
pack="$1"
vprf="$2"
else
echo "usage: mkdiff [--no-sign] [--with-po] package-name [version-prefix]" >&2
exit 1
fi
set -e
curr_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\
| sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -1 )
if [ ! -f $pack-$curr_ver.tar.$ext ]; then
echo "mkdiff: no current version of package $pack found" >&2
exit 1
fi
prev_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\
| sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -2 | tail -1 )
if [ "$prev_ver" = "$curr_ver" ]; then
echo "mkdiff: no previous version of package $pack found" >&2
exit 1
fi
echo "Current is: $pack-$curr_ver"
echo "Previous is: $pack-$prev_ver"
[ $opt_sign != yes ] && echo "signing disabled"
echo "Removing old directories"
[ -d "$pack-$curr_ver" ] && rm -rf "$pack-$curr_ver"
[ -d "$pack-$prev_ver" ] && rm -rf "$pack-$prev_ver"
echo "Unpacking previous and current tar"
tar x${extz}f "$pack-$curr_ver.tar.$ext"
tar x${extz}f "$pack-$prev_ver.tar.$ext"
# We remove some files from the directories because we assume
# that they are either binary or can be build using the proper tools:
# .tlb - Windows Type Library
# .dvi
# .ps
# .eps
# .pdf
# .gmo - compiled gettext files
# .der - DER encoded test stuff
# .ber - BER encoded test stuff
# .png
# .jpg
tmp="dvi ps eps pdf gmo der ber png jpg"
find_args="-type f -name *.tlb -or -name *.info -or -name *.info-[0-9]"
for i in dvi ps eps pdf gmo der ber png jpg; do
find_args="$find_args -or -name *.$i"
done
[ $opt_with_po = no ] && find_args="$find_args -or -name *.po -or -name *.pot"
find $pack-${curr_ver} $pack-${prev_ver} `echo $find_args` 2>/dev/null \
| xargs rm -f 2>/dev/null || true
echo "Diffing"
tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp"
diff_name="$pack-$prev_ver-$curr_ver.diff"
LC_ALL=C TZ=UTC0 diff -urpP "$pack-$prev_ver/" "$pack-$curr_ver/" > $tmp_name || true
echo "Making patch file"
cat <<EOF > $diff_name
This is a patch file to create version $curr_ver from $prev_ver.
Please check the signature of this patch file:
bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg --verify
Change to directory $pack-$prev_ver (or however you renamed it)
and give this command:
bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg | patch -p1
It is a good idea to rename your current directory to $pack-$curr_ver now.
Prereq: $prev_ver
EOF
#sed -ne '/^diff.*VERSION/,/^+[0-9][0-9]*/ p' $tmp_name >> $diff_name
#echo >> $diff_name
#sed -e '/^diff.*VERSION/,/^+[0-9][0-9]*/ d' $tmp_name >> $diff_name
awk '/^diff.*\/VERSION/ {x=1; print; next}; /^diff.*/ && x == 1 {x = 2}; x == 1 {print}' $tmp_name >> $diff_name
awk '/^diff.*\/VERSION/ {x=1; next}; /^diff.*/ && x == 1 {x = 2; print}; x != 1 {print}' $tmp_name >> $diff_name
rm $tmp_name
if [ $opt_sign = yes ]; then
echo "Signing and compressing patch file"
gpg2 --clearsign --not-dash-escaped -u $signing_key $signing_options \
< $diff_name | bzip2 --best > $diff_name.bz2
else
echo "compressing patch file"
cat $diff_name | bzip2 --best > $diff_name.bz2
fi
rm $diff_name
echo "Checking patch file"
cd $pack-$prev_ver
bzcat ../$diff_name.bz2 | patch -s -p1
rm $(find . -name "*.orig") 2>/dev/null || true
cd ..
if ! diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then
echo "compare failed"
while :; do
echo "what shall we do: (v)iew, (i)gnore, (a)bort ?" >&2
read
case "$REPLY" in
v|V)
diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" | less
;;
i|I)
break
;;
a|A)
exit 1
;;
esac
done
fi
if [ $opt_sign = yes ]; then
if ! bzcat $diff_name.bz2 | gpg2 --batch --verify ; then
exit 1
fi
fi
echo "cleaning up"
rm -rf "$pack-$curr_ver"
rm -rf "$pack-$prev_ver"
echo "Patch file $diff_name.bz2 is good."