mkdiff 2.83 KB
Newer Older
1 2
#!/bin/sh

Niels Möller's avatar
Niels Möller committed
3
# Copied from gnupg-1.0.4, and hacked somewhat by Niels Möller
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

if [ $# != 1 ] ; then
    echo "usage: mkdiff package-name" >&2
    exit 1
fi

pack="$1"
gpguser=A8F4C2FD

set -e

curr_ver=$(ls $pack-*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
	   | sort -r -t '.' -n +0 -1 +1 -2 +2 | head -1 )
if [ ! -f $pack-$curr_ver.tar.gz ]; then
    echo "mkdiff: no current version of package $pack found" >&2
    exit 1
fi
prev_ver=$(ls $pack-*.tar.gz 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.gz/\1/"\
	   | sort -r -t '.' -n +0 -1 +1 -2 +2 | 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"

echo "Checking signature of $pack-$curr_ver.tar.gz..."
if gpg --batch --verify $pack-$curr_ver.tar.gz.asc $pack-$curr_ver.tar.gz ; then
    echo "   Ok"
else
    echo "   Failed"
    exit 1
fi

echo "Checking signature of $pack-$prev_ver.tar.gz... "
if gpg --batch --verify $pack-$prev_ver.tar.gz.asc $pack-$prev_ver.tar.gz ; then
    echo "   Ok"
else
    echo "   Failed"
    exit 1
fi

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 xzf "$pack-$curr_ver.tar.gz"
rm -f $pack-${curr_ver}/po/*.gmo
tar xzf "$pack-$prev_ver.tar.gz"
rm -f $pack-${prev_ver}/po/*.gmo


echo "Diffing"
tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp"
diff_name="$pack-$prev_ver-$curr_ver.diff"

diff -urN "$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:

    zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | gpg --verify

Change to directory $pack-$prev_ver (or however you renamed it)
and give this command:

     zcat somepath/$pack-$prev_ver-$curr_ver.diff.gz | 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

rm $tmp_name

echo "Signing and compressing patch file"
gpg --clearsign --not-dash-escaped -u $gpguser \
    < $diff_name | gzip --best > $diff_name.gz
rm $diff_name

echo "Checking patch file"
cd $pack-$prev_ver
zcat ../$diff_name.gz | patch -s -p1
rm $(find . -name "*.orig") 2>/dev/null || true
cd ..

if ! diff -urN "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then
   echo "compare failed"
   exit 1
fi

if ! zcat $diff_name.gz | gpg --batch --verify ; then
    exit 1
fi


echo "cleaning up"

rm -rf "$pack-$curr_ver"
rm -rf "$pack-$prev_ver"

echo "Patch file $diff_name.gz is good."