|
1 #!/bin/sh -e |
|
2 # |
|
3 # Build a Mercurial debian package from the current repo |
|
4 # |
|
5 # Tested on Jessie (stable as of original script authoring.) |
|
6 |
|
7 . $(dirname $0)/packagelib.sh |
|
8 |
|
9 BUILD=1 |
|
10 CLEANUP=1 |
|
11 DISTID=`(lsb_release -is 2> /dev/null | tr '[:upper:]' '[:lower:]') || echo debian` |
|
12 CODENAME=`lsb_release -cs 2> /dev/null || echo unknown` |
|
13 DEBFLAGS=-b |
|
14 while [ "$1" ]; do |
|
15 case "$1" in |
|
16 --distid ) |
|
17 shift |
|
18 DISTID="$1" |
|
19 shift |
|
20 ;; |
|
21 --codename ) |
|
22 shift |
|
23 CODENAME="$1" |
|
24 shift |
|
25 ;; |
|
26 --cleanup ) |
|
27 shift |
|
28 BUILD= |
|
29 ;; |
|
30 --build ) |
|
31 shift |
|
32 CLEANUP= |
|
33 ;; |
|
34 --source-only ) |
|
35 shift |
|
36 DEBFLAGS=-S |
|
37 ;; |
|
38 * ) |
|
39 echo "Invalid parameter $1!" 1>&2 |
|
40 exit 1 |
|
41 ;; |
|
42 esac |
|
43 done |
|
44 |
|
45 trap "if [ '$CLEANUP' ] ; then rm -r '$PWD/debian' ; fi" EXIT |
|
46 |
|
47 set -u |
|
48 |
|
49 if [ ! -d .hg ]; then |
|
50 echo 'You are not inside a Mercurial repository!' 1>&2 |
|
51 exit 1 |
|
52 fi |
|
53 |
|
54 gethgversion |
|
55 debver="$version" |
|
56 if [ -n "$type" ] ; then |
|
57 debver="$debver~$type" |
|
58 fi |
|
59 if [ -n "$distance" ] ; then |
|
60 debver="$debver+$distance-$CODENAME-$node" |
|
61 elif [ "$DEBFLAGS" = "-S" ] ; then |
|
62 # for building a ppa (--source-only) for a release (distance == 0), we need |
|
63 # to version the distroseries so that we can upload to launchpad |
|
64 debver="$debver~${CODENAME}1" |
|
65 fi |
|
66 |
|
67 control=debian/control |
|
68 changelog=debian/changelog |
|
69 |
|
70 if [ "$BUILD" ]; then |
|
71 if [ -d debian ] ; then |
|
72 echo "Error! debian control directory already exists!" |
|
73 exit 1 |
|
74 fi |
|
75 |
|
76 cp -r "$PWD"/contrib/debian debian |
|
77 |
|
78 sed -i.tmp "s/__VERSION__/$debver/" $changelog |
|
79 sed -i.tmp "s/__DATE__/$(date --rfc-2822)/" $changelog |
|
80 sed -i.tmp "s/__CODENAME__/$CODENAME/" $changelog |
|
81 rm $changelog.tmp |
|
82 |
|
83 # remove the node from the version string |
|
84 SRCFILE="mercurial_$(echo $debver | sed "s,-$node,,").orig.tar.gz" |
|
85 "$PWD/hg" archive $SRCFILE |
|
86 mv $SRCFILE .. |
|
87 debuild -us -uc -i -I $DEBFLAGS |
|
88 if [ $? != 0 ]; then |
|
89 echo 'debuild failed!' |
|
90 exit 1 |
|
91 fi |
|
92 |
|
93 fi |
|
94 if [ "$CLEANUP" ] ; then |
|
95 echo |
|
96 OUTPUTDIR=${OUTPUTDIR:=packages/$DISTID-$CODENAME} |
|
97 mkdir -p "$OUTPUTDIR" |
|
98 find ../mercurial*.deb ../mercurial_*.build ../mercurial_*.changes \ |
|
99 ../mercurial*.dsc ../mercurial*.gz \ |
|
100 -type f -newer $control -print0 2>/dev/null | \ |
|
101 xargs -Inarf -0 mv narf "$OUTPUTDIR" |
|
102 echo "Built packages for $debver:" |
|
103 find "$OUTPUTDIR" -type f -newer $control -name '*.deb' |
|
104 fi |