annotate contrib/builddeb @ 29738:4f1dac94b53f stable

builddeb: use sed -i Notice that there is no space after '-i'. This makes it work on both GNU and BSD versions of sed.
author Sean Farley <sean@farley.io>
date Sat, 16 Apr 2016 12:33:21 -0700
parents ef9301ce6046
children a8256e3701be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25362
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
25363
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 25362
diff changeset
7 . $(dirname $0)/packagelib.sh
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 25362
diff changeset
8
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
9 BUILD=1
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
10 CLEANUP=1
27852
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27851
diff changeset
11 DISTID=`(lsb_release -is 2> /dev/null | tr '[:upper:]' '[:lower:]') || echo debian`
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27851
diff changeset
12 CODENAME=`lsb_release -cs 2> /dev/null || echo unknown`
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
13 while [ "$1" ]; do
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
14 case "$1" in
27850
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
15 --distid )
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
16 shift
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
17 DISTID="$1"
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
18 shift
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
19 ;;
27849
7fbab10f812f builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents: 27473
diff changeset
20 --codename )
26695
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26677
diff changeset
21 shift
27849
7fbab10f812f builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents: 27473
diff changeset
22 CODENAME="$1"
26695
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26677
diff changeset
23 shift
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26677
diff changeset
24 ;;
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
25 --cleanup )
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
26 shift
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
27 BUILD=
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
28 ;;
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
29 --build )
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
30 shift
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
31 CLEANUP=
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
32 ;;
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
33 * )
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
34 echo "Invalid parameter $1!" 1>&2
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
35 exit 1
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 esac
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
38 done
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
39
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
40 trap "if [ '$CLEANUP' ] ; then rm -r '$PWD/debian' ; fi" EXIT
26695
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26677
diff changeset
41
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
42 set -u
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
43
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
44 if [ ! -d .hg ]; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
45 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
46 exit 1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
47 fi
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
48
25363
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 25362
diff changeset
49 gethgversion
27473
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
50 debver="$version"
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
51 if [ -n "$type" ] ; then
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
52 debver="$debver~$type"
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
53 fi
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
54 if [ -n "$distance" ] ; then
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
55 debver="$debver+$distance-$node"
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
56 fi
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
57
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
58 control=debian/control
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
59 changelog=debian/changelog
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
60
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
61 if [ "$BUILD" ]; then
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
62 if [ -d debian ] ; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
63 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: 26695
diff changeset
64 exit 1
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
65 fi
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
66
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
67 cp -r $PWD/contrib/debian debian
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
68 chmod -R 0755 debian
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
69
29738
4f1dac94b53f builddeb: use sed -i
Sean Farley <sean@farley.io>
parents: 27852
diff changeset
70 sed -i.tmp "s/__VERSION__/$debver/" $changelog
4f1dac94b53f builddeb: use sed -i
Sean Farley <sean@farley.io>
parents: 27852
diff changeset
71 sed -i.tmp "s/__DATE__/$(date --rfc-2822)/" $changelog
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
72 rm $changelog.tmp
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
73
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
74 debuild -us -uc -b
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
75 if [ $? != 0 ]; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
76 echo 'debuild failed!'
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
77 exit 1
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
78 fi
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
79
25362
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
80 fi
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
81 if [ "$CLEANUP" ] ; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
82 echo
27850
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27849
diff changeset
83 OUTPUTDIR=${OUTPUTDIR:=packages/$DISTID-$CODENAME}
27852
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27851
diff changeset
84 mkdir -p "$OUTPUTDIR"
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
85 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: 26695
diff changeset
86 -type f -newer $control -print0 | \
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
87 xargs -Inarf -0 mv narf "$OUTPUTDIR"
27473
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26744
diff changeset
88 echo "Built packages for $debver:"
26744
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26695
diff changeset
89 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: 26695
diff changeset
90 fi