author | Siddharth Agarwal <sid0@fb.com> |
Tue, 17 Nov 2015 14:22:30 -0800 | |
changeset 27004 | a4c26918fb23 |
parent 26833 | 6474b64045fb |
child 27209 | 7fbab10f812f |
permissions | -rwxr-xr-x |
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 |
|
24972
56c64c91b429
packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
24971
diff
changeset
|
7 |
. $(dirname $0)/packagelib.sh |
56c64c91b429
packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
24971
diff
changeset
|
8 |
|
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
BUILD=1 |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
10 |
CLEANUP=1 |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
11 |
DEBVERSION=jessie |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
while [ "$1" ]; do |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
case "$1" in |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
14 |
--release ) |
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
15 |
shift |
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
16 |
DEBVERSION="$1" |
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
17 |
shift |
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
18 |
;; |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
19 |
--cleanup ) |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
shift |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 |
BUILD= |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
;; |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
23 |
--build ) |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
24 |
shift |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
25 |
CLEANUP= |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
26 |
;; |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
--debbuilddir ) |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
shift |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 |
DEBBUILDDIR="$1" |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
shift |
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 |
* ) |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
echo "Invalid parameter $1!" 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 |
;; |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
esac |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
done |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
|
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
39 |
trap "if [ '$CLEANUP' ] ; then rm -r '$PWD/debian' ; fi" EXIT |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
40 |
|
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
set -u |
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 |
if [ ! -d .hg ]; then |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 |
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
|
45 |
exit 1 |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 |
fi |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
|
24972
56c64c91b429
packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
24971
diff
changeset
|
48 |
gethgversion |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
49 |
debver="$version" |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
50 |
if [ -n "$type" ] ; then |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
51 |
debver="$debver~$type" |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
52 |
fi |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
53 |
if [ -n "$distance" ] ; then |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
54 |
debver="$debver+$distance-$node" |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
55 |
fi |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
|
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
57 |
control=debian/control |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
58 |
changelog=debian/changelog |
24971
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 |
if [ "$BUILD" ]; then |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
61 |
if [ -d debian ] ; then |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
62 |
echo "Error! debian control directory already exists!" |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
63 |
exit 1 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 |
fi |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
65 |
|
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
66 |
cp -r $PWD/contrib/debian debian |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
67 |
chmod -R 0755 debian |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
68 |
|
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
69 |
# This looks like sed -i, but sed -i behaves just differently enough |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
70 |
# between BSD and GNU sed that I gave up and did the dumb thing. |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
71 |
sed "s/__VERSION__/$debver/" < $changelog > $changelog.tmp |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
72 |
date=$(date --rfc-2822) |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
73 |
sed "s/__DATE__/$date/" < $changelog.tmp > $changelog |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
74 |
rm $changelog.tmp |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
75 |
|
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
76 |
debuild -us -uc -b |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
77 |
if [ $? != 0 ]; then |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
78 |
echo 'debuild failed!' |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
79 |
exit 1 |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
80 |
fi |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
81 |
|
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
fi |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
83 |
if [ "$CLEANUP" ] ; then |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
84 |
echo |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
85 |
OUTPUTDIR=${OUTPUTDIR:=packages/debian-$DEBVERSION} |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
86 |
find ../mercurial*.deb ../mercurial_*.build ../mercurial_*.changes \ |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
87 |
-type f -newer $control -print0 | \ |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
88 |
xargs -Inarf -0 mv narf "$OUTPUTDIR" |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
89 |
echo "Built packages for $debver:" |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
90 |
find "$OUTPUTDIR" -type f -newer $control -name '*.deb' |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
91 |
fi |