Fixed bug 479. Not a real good fix but a reliable one which limits possible
[gnupg.git] / scripts / mkdiff
1 #!/bin/sh
2 # Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 #
4 # This file is free software; as a special exception the author gives
5 # unlimited permission to copy and/or distribute it, with or without
6 # modifications, as long as this notice is preserved.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
12 # Please note that this script is now maintained outside of GNUPG.
13 # To get the most up to date version use
14 # cvs -d :pserver:anoncvs@cvs.gnupg.org:/cvs/wk checkout misc-scripts/mkdiff
15
16 if [ $# != 1 ] ; then
17     echo "usage: mkdiff package-name" >&2
18     exit 1
19 fi
20
21 pack="$1"
22
23 set -e
24
25 curr_ver=$(ls $pack-*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
26            | sort -r -t '.' -n +0 -1 +1 -2 +2 | head -1 )
27 if [ ! -f $pack-$curr_ver.tar.gz ]; then
28     echo "mkdiff: no current version of package $pack found" >&2
29     exit 1
30 fi
31 prev_ver=$(ls $pack-*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
32            | sort -r -t '.' -n +0 -1 +1 -2 +2 | head -2 | tail -1 )
33 if [ "$prev_ver" = "$curr_ver"  ]; then
34     echo "mkdiff: no previous version of package $pack found" >&2
35     exit 1
36 fi
37
38 echo "Current  is: $pack-$curr_ver"
39 echo "Previous is: $pack-$prev_ver"
40
41
42 echo "Removing old directories"
43 [ -d "$pack-$curr_ver" ] && rm -rf "$pack-$curr_ver"
44 [ -d "$pack-$prev_ver" ] && rm -rf "$pack-$prev_ver"
45
46 echo "Unpacking previous and current tar"
47 tar xzf "$pack-$curr_ver.tar.gz"
48 rm -f $pack-${curr_ver}/po/*.gmo
49 tar xzf "$pack-$prev_ver.tar.gz"
50 rm -f $pack-${prev_ver}/po/*.gmo
51
52
53 echo "Diffing"
54 tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp"
55 diff_name="$pack-$prev_ver-$curr_ver.diff"
56
57 diff -urN "$pack-$prev_ver/" "$pack-$curr_ver/"  > $tmp_name || true
58
59 echo "Making patch file"
60
61 cat <<EOF > $diff_name
62
63 This is a patch file to create version $curr_ver from $prev_ver.
64
65 Please check the signature of this patch file:
66
67     zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | gpg --verify
68
69 Change to directory $pack-$prev_ver (or however you renamed it)
70 and give this command:
71
72      zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | patch -p1
73
74 It is a good idea to rename your current directory to $pack-$curr_ver now.
75
76
77
78 Prereq: $prev_ver
79
80 EOF
81
82 sed -ne '/^diff.*VERSION/,/^+[0-9][0-9]*/ p' $tmp_name >> $diff_name
83 echo  >> $diff_name
84 sed -e '/^diff.*VERSION/,/^+[0-9][0-9]*/ d'  $tmp_name >> $diff_name
85
86 rm $tmp_name
87
88 echo "Signing and compressing patch file"
89 gpg --clearsign --not-dash-escaped -u 57548DCD \
90     < $diff_name | gzip --best > $diff_name.gz
91 rm $diff_name
92
93 echo "Checking patch file"
94 cd $pack-$prev_ver
95 zcat ../$diff_name.gz | patch -s -p1
96 rm $(find . -name "*.orig") 2>/dev/null || true
97 cd ..
98
99 if ! diff -urN "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then
100    echo "compare failed"
101    exit 1
102 fi
103
104 if ! zcat $diff_name.gz | gpg --batch --verify ; then
105     exit 1
106 fi
107
108
109 echo "cleaning up"
110
111 rm -rf "$pack-$curr_ver"
112 rm -rf "$pack-$prev_ver"
113
114 echo "Patch file $diff_name.gz is good."
115