summaryrefslogtreecommitdiffhomepage
path: root/contrib.sh
blob: 501b539ab8d3f85b4edb56bc26a98a3192e66b0c (plain)
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
#!/bin/sh

# init vars
commit=$1; [ -z "$commit" ] && commit='HEAD'
blank=
bline=
fname=

# source.patch
git format-patch -1 $commit --stdout > source.patch	|| exit 2
cat contrib.msg >> source.patch				|| exit 2

# source.patch without the (noisy) first line
tail -n +2 source.patch > contrib.patch 		|| exit 2

# contrib.patch: first blank line
blank=`grep -n ^$ contrib.patch | head -n1`
[ -z "$blank" ] && exit 2

bline=`echo $blank | cut -f1 -d':'`
[ -z "$bline" ] && exit 2

# use sha256sum of the above for patch file name
fname=`sha256sum contrib.patch | cut -f1 -d' '`		|| exit 2
[ -z "$fname" ] && exit 2

# prepare for submission, sign the patch
mv   contrib.patch $fname.patch				|| exit 2
head -n$bline $fname.patch | tail -n +2 > $fname.sig	|| exit 2

[ -z "$PAGER" ] && PAGER='less'
$PAGER $fname.patch					|| exit 2
cat contrib.msg						|| exit 2

echo
echo 'press <enter> to continue, <ctrl-c> to abort>'
echo

read enter

gpg  --armor --detach-sign $fname.patch			|| exit 2
cat  $fname.patch.asc >> $fname.sig			|| exit 2

# verify
gpg --verify $fname.sig $fname.patch			|| exit 2

# clean up
rm source.patch
rm $fname.patch.asc

# info
echo
echo "commit $commit was successfully prepared for submission."
echo "$fname.patch: a patch file that can be imported by git-am."
echo "$fname.sig:   a gpg signature file of the above patch."
echo

# all done
exit 0