* pksign.c (agent_pksign): Detect whether a Smartcard is to be
[gnupg.git] / scripts / mkdiff
1 #!/bin/sh
2
3 if [ $# = 1 ]; then
4     pack="$1"
5     vprf=""
6 elif [ $# = 2 ] ; then
7     pack="$1"
8     vprf="$2"
9 else
10     echo "usage: mkdiff package-name [version-prefix]" >&2
11     exit 1
12 fi
13
14 set -e
15
16 curr_ver=$(ls $pack-${vprf}*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
17            | sort -r -t '.' -n +0 -1 +1 -2 +2 | head -1 )
18 if [ ! -f $pack-$curr_ver.tar.gz ]; then
19     echo "mkdiff: no current version of package $pack found" >&2
20     exit 1
21 fi
22 prev_ver=$(ls $pack-${vprf}*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
23            | sort -r -t '.' -n +0 -1 +1 -2 +2 | head -2 | tail -1 )
24 if [ "$prev_ver" = "$curr_ver"  ]; then
25     echo "mkdiff: no previous version of package $pack found" >&2
26     exit 1
27 fi
28
29 echo "Current  is: $pack-$curr_ver"
30 echo "Previous is: $pack-$prev_ver"
31
32
33 echo "Removing old directories"
34 [ -d "$pack-$curr_ver" ] && rm -rf "$pack-$curr_ver"
35 [ -d "$pack-$prev_ver" ] && rm -rf "$pack-$prev_ver"
36
37 echo "Unpacking previous and current tar"
38 tar xzf "$pack-$curr_ver.tar.gz"
39 rm -f $pack-${curr_ver}/po/*.gmo
40 tar xzf "$pack-$prev_ver.tar.gz"
41 rm -f $pack-${prev_ver}/po/*.gmo
42
43
44 echo "Diffing"
45 tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp"
46 diff_name="$pack-$prev_ver-$curr_ver.diff"
47
48 diff -urN "$pack-$prev_ver/" "$pack-$curr_ver/"  > $tmp_name || true
49
50 echo "Making patch file"
51
52 cat <<EOF > $diff_name
53
54 This is a patch file to create version $curr_ver from $prev_ver.
55
56 Please check the signature of this patch file:
57
58     zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | gpg --verify
59
60 Change to directory $pack-$prev_ver (or however you renamed it)
61 and give this command:
62
63      zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | patch -p1
64
65 It is a good idea to rename your current directory to $pack-$curr_ver now.
66
67
68
69 Prereq: $prev_ver
70
71 EOF
72
73 sed -ne '/^diff.*VERSION/,/^+[0-9][0-9]*/ p' $tmp_name >> $diff_name
74 echo  >> $diff_name
75 sed -e '/^diff.*VERSION/,/^+[0-9][0-9]*/ d'  $tmp_name >> $diff_name
76
77 rm $tmp_name
78
79 echo "Signing and compressing patch file"
80 gpg --clearsign --not-dash-escaped -u 57548DCD \
81     < $diff_name | gzip --best > $diff_name.gz
82 rm $diff_name
83
84 echo "Checking patch file"
85 cd $pack-$prev_ver
86 zcat ../$diff_name.gz | patch -s -p1
87 rm $(find . -name "*.orig") 2>/dev/null || true
88 cd ..
89
90 if ! diff -urN "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then
91    echo "compare failed"
92    exit 1
93 fi
94
95 if ! zcat $diff_name.gz | gpg --batch --verify ; then
96     exit 1
97 fi
98
99
100 echo "cleaning up"
101
102 rm -rf "$pack-$curr_ver"
103 rm -rf "$pack-$prev_ver"
104
105 echo "Patch file $diff_name.gz is good."
106