addrutil: Re-indent.
[wk-misc.git] / mkdiff
1 #!/bin/sh
2
3 signing_key="0x4F25E3B6"
4 signing_options=" --digest-algo SHA384"
5 opt_sign=yes
6 ext=bz2
7 extz=j
8 opt_with_po=no
9 if [ "$1" = "--gzip-source" ]; then
10   ext=gz
11   extz=z
12   shift
13 fi
14 if [ "$1" = "--no-sign" ]; then
15   opt_sign=no
16   shift
17 fi
18 if [ "$1" = "--with-po" ]; then
19   opt_with_po=yes
20   shift
21 fi
22
23 if [ $# = 1 ]; then
24     pack="$1"
25     vprf=""
26 elif [ $# = 2 ] ; then
27     pack="$1"
28     vprf="$2"
29 else
30     echo "usage: mkdiff [--no-sign] [--with-po] package-name [version-prefix]" >&2
31     exit 1
32 fi
33
34 set -e
35
36 curr_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\
37            | sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -1 )
38 if [ ! -f $pack-$curr_ver.tar.$ext ]; then
39     echo "mkdiff: no current version of package $pack found" >&2
40     exit 1
41 fi
42 prev_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\
43            | sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -2 | tail -1 )
44 if [ "$prev_ver" = "$curr_ver"  ]; then
45     echo "mkdiff: no previous version of package $pack found" >&2
46     exit 1
47 fi
48
49 echo "Current  is: $pack-$curr_ver"
50 echo "Previous is: $pack-$prev_ver"
51 [ $opt_sign != yes ] && echo "signing disabled"
52
53 echo "Removing old directories"
54 [ -d "$pack-$curr_ver" ] && rm -rf "$pack-$curr_ver"
55 [ -d "$pack-$prev_ver" ] && rm -rf "$pack-$prev_ver"
56
57 echo "Unpacking previous and current tar"
58
59 tar x${extz}f "$pack-$curr_ver.tar.$ext"
60 tar x${extz}f "$pack-$prev_ver.tar.$ext"
61 # We remove some files from the directories because we assume
62 # that they are either binary or can be build using the proper tools:
63 #  .tlb - Windows  Type Library
64 #  .dvi
65 #  .ps
66 #  .eps
67 #  .pdf
68 #  .gmo - compiled gettext files
69 #  .der - DER encoded test stuff
70 #  .ber - BER encoded test stuff
71 #  .png
72 #  .jpg
73 tmp="dvi ps eps pdf gmo der ber png jpg"
74 find_args="-type f -name *.tlb -or -name *.info -or -name *.info-[0-9]"
75 for i in dvi ps eps pdf gmo der ber png jpg; do
76     find_args="$find_args -or -name *.$i"
77 done
78 [ $opt_with_po = no ] && find_args="$find_args -or -name *.po -or -name *.pot"
79 find $pack-${curr_ver} $pack-${prev_ver} `echo $find_args` 2>/dev/null \
80      | xargs rm -f 2>/dev/null || true
81
82
83 echo "Diffing"
84 tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp"
85 diff_name="$pack-$prev_ver-$curr_ver.diff"
86
87 LC_ALL=C TZ=UTC0 diff -urpP "$pack-$prev_ver/" "$pack-$curr_ver/"  > $tmp_name || true
88
89 echo "Making patch file"
90
91 cat <<EOF > $diff_name
92
93 This is a patch file to create version $curr_ver from $prev_ver.
94
95 Please check the signature of this patch file:
96
97   bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg --verify
98
99 Change to directory $pack-$prev_ver (or however you renamed it)
100 and give this command:
101
102   bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg | patch -p1
103
104 It is a good idea to rename your current directory to $pack-$curr_ver now.
105
106
107
108 Prereq: $prev_ver
109
110 EOF
111
112 #sed -ne '/^diff.*VERSION/,/^+[0-9][0-9]*/ p' $tmp_name >> $diff_name
113 #echo  >> $diff_name
114 #sed -e '/^diff.*VERSION/,/^+[0-9][0-9]*/ d'  $tmp_name >> $diff_name
115 awk '/^diff.*\/VERSION/ {x=1; print; next}; /^diff.*/ && x == 1 {x = 2}; x == 1 {print}' $tmp_name >> $diff_name
116 awk '/^diff.*\/VERSION/ {x=1; next}; /^diff.*/ && x == 1 {x = 2; print}; x != 1 {print}' $tmp_name >> $diff_name
117
118
119 rm $tmp_name
120
121 if [ $opt_sign = yes ]; then
122 echo "Signing and compressing patch file"
123 gpg2 --clearsign --not-dash-escaped -u $signing_key $signing_options \
124     < $diff_name | bzip2 --best > $diff_name.bz2
125 else
126 echo "compressing patch file"
127 cat $diff_name | bzip2 --best > $diff_name.bz2
128 fi
129 rm $diff_name
130
131 echo "Checking patch file"
132 cd $pack-$prev_ver
133 bzcat ../$diff_name.bz2 | patch -s -p1
134 rm $(find . -name "*.orig") 2>/dev/null || true
135 cd ..
136
137 if ! diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then
138    echo "compare failed"
139
140    while :; do
141      echo "what shall we do: (v)iew, (i)gnore, (a)bort ?" >&2
142      read
143      case "$REPLY" in
144        v|V)
145           diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" | less
146           ;;
147        i|I)
148           break
149           ;;
150        a|A)
151           exit 1
152           ;;
153      esac
154    done
155 fi
156
157 if [ $opt_sign = yes ]; then
158 if ! bzcat $diff_name.bz2 | gpg2 --batch --verify ; then
159     exit 1
160 fi
161 fi
162
163 echo "cleaning up"
164
165 rm -rf "$pack-$curr_ver"
166 rm -rf "$pack-$prev_ver"
167
168 echo "Patch file $diff_name.bz2 is good."