annotate contrib/builddeb @ 24971:ab75baaf81d5

builddeb: new script for building a deb package Future work will allow us to use docker to build debs. Right now this doesn't install any config files. I plan to do that as a followup, but getting something basic and working checked in seems like more of a priority than getting everything done in one big step. This also does not create a source deb yet. I haven't looked into that process. Note that this declares incompatibility with the `mercurial-common` package. It's typical for debian packages to be split between architecture-independent bits and native bits, meaning the python bits downstream live in mercurial-common and the c extension bits live in mercurial. We don't do that because we want to (ideally) give users a single deb file to install.
author Augie Fackler <augie@google.com>
date Wed, 06 May 2015 13:13:54 -0400
parents
children 56c64c91b429
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
1 #!/bin/sh -e
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
2 #
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
3 # Build a Mercurial debian package from the current repo
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
4 #
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
5 # Tested on Jessie (stable as of original script authoring.)
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
6
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
7 BUILD=1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
8 DEBBUILDDIR="$PWD/debbuild"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
9 while [ "$1" ]; do
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
10 case "$1" in
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
11 --prepare )
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
12 shift
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
13 BUILD=
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
14 ;;
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
15 --debbuilddir )
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
16 shift
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
17 DEBBUILDDIR="$1"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
18 shift
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
19 ;;
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
20 * )
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
21 echo "Invalid parameter $1!" 1>&2
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
22 exit 1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
23 ;;
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
24 esac
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
25 done
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
26
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
27 set -u
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
28
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
29 rm -rf $DEBBUILDDIR
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
30 mkdir -p $DEBBUILDDIR
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
31
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
32 if [ ! -d .hg ]; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
33 echo 'You are not inside a Mercurial repository!' 1>&2
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
34 exit 1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
35 fi
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
36
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
37 # build local hg and use it
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
38 python setup.py build_py -c -d .
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
39 HG="$PWD/hg"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
40
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
41 $HG version > /dev/null || { echo 'abort: hg version failed!'; exit 1 ; }
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
42
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
43 hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
44
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
45 if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
46 # nightly build case, version is like 1.3.1+250-20b91f91f9ca
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
47 version=`echo $hgversion | cut -d- -f1`
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
48 release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
49 else
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
50 # official tag, version is like 1.3.1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
51 version=`echo $hgversion | sed -e 's/+.*//'`
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
52 release='0'
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
53 fi
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
54
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
55 cp -r $PWD/contrib/debian $DEBBUILDDIR/DEBIAN
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
56 chmod -R 0755 $DEBBUILDDIR/DEBIAN
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
57
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
58 control=$DEBBUILDDIR/DEBIAN/control
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
59
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
60 # This looks like sed -i, but sed -i behaves just differently enough
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
61 # between BSD and GNU sed that I gave up and did the dumb thing.
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
62 sed "s/__VERSION__/$version/" < $control > $control.tmp
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
63 mv $control.tmp $control
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
64
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
65 if [ "$BUILD" ]; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
66 dpkg-deb --build $DEBBUILDDIR
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
67 mv $DEBBUILDDIR.deb $DEBBUILDDIR/mercurial-$version-$release.deb
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
68 if [ $? = 0 ]; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
69 echo
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
70 echo "Built packages for $version-$release:"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
71 find $DEBBUILDDIR/ -type f -newer $control
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
72 fi
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
73 else
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
74 echo "Prepared sources for $version-$release $control are in $DEBBUILDDIR - use like:"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
75 echo "dpkg-deb --build $DEBBUILDDIR"
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
76 fi