Mercurial > hg
annotate contrib/packaging/builddeb @ 40106:930bce0741de
packaging: cleanup() did not read the value of $CLEANUP
When the original author put CLEANUP in a conditional statement he was probably
willing to use it to control the "if". This change tries to restore that
behaviour: the "rm" clause is triggered if and only if CLEANUP is defined and
not empty.
author | muxator <a.mux@inwind.it> |
---|---|
date | Tue, 09 Oct 2018 22:24:38 +0200 |
parents | d3780c8f3180 |
children | 212a52d8e9d8 |
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 |
38006
64b086f0ebb5
packaging: move builddeb into contrib/packaging/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38005
diff
changeset
|
7 . $(dirname $0)/packagelib.sh |
24972
56c64c91b429
packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
24971
diff
changeset
|
8 |
38013
917f635b5c6a
packaging: make packaging scripts less reliant on pwd
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38009
diff
changeset
|
9 ROOTDIR=$(cd $(dirname $0)/../.. > /dev/null; pwd) |
917f635b5c6a
packaging: make packaging scripts less reliant on pwd
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38009
diff
changeset
|
10 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 BUILD=1 |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
12 CLEANUP=1 |
27212
ef9301ce6046
builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents:
27211
diff
changeset
|
13 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:
27211
diff
changeset
|
14 CODENAME=`lsb_release -cs 2> /dev/null || echo unknown` |
28994
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
15 DEBFLAGS=-b |
40104
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
16 |
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
17 cleanup() { |
40106
930bce0741de
packaging: cleanup() did not read the value of $CLEANUP
muxator <a.mux@inwind.it>
parents:
40105
diff
changeset
|
18 if [ "$CLEANUP" ]; then |
40105
d3780c8f3180
packaging: builddeb's cleanup needs to expand PWD, safely
muxator <a.mux@inwind.it>
parents:
40104
diff
changeset
|
19 rm -r "$PWD/debian"; |
40104
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
20 fi |
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
21 } |
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
22 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 while [ "$1" ]; do |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 case "$1" in |
27210
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
25 --distid ) |
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
26 shift |
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
27 DISTID="$1" |
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
28 shift |
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
29 ;; |
27209
7fbab10f812f
builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents:
26833
diff
changeset
|
30 --codename ) |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
31 shift |
27209
7fbab10f812f
builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents:
26833
diff
changeset
|
32 CODENAME="$1" |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
33 shift |
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
34 ;; |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
35 --cleanup ) |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 shift |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 BUILD= |
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 --build ) |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
40 shift |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
41 CLEANUP= |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
42 ;; |
28994
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
43 --source-only ) |
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
44 shift |
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
45 DEBFLAGS=-S |
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
46 ;; |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 * ) |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 echo "Invalid parameter $1!" 1>&2 |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 exit 1 |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 ;; |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 esac |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 done |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
53 |
40104
338230555429
packaging: blindly factor out trap's cleanup function in builddeb
muxator <a.mux@inwind.it>
parents:
40103
diff
changeset
|
54 trap 'cleanup' EXIT |
26108
05306b9359d3
builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents:
26090
diff
changeset
|
55 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 set -u |
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 if [ ! -d .hg ]; then |
40102
f9c5f7b048b0
packaging: print more specific error messages when builddeb fails
muxator <a.mux@inwind.it>
parents:
38013
diff
changeset
|
59 printf "You are inside %s, which is not the root of a Mercurial repository\n" $(pwd) 1>&2 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 exit 1 |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 fi |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
24972
56c64c91b429
packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
24971
diff
changeset
|
63 gethgversion |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
64 debver="$version" |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
65 if [ -n "$type" ] ; then |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
66 debver="$debver~$type" |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
67 fi |
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
68 if [ -n "$distance" ] ; then |
29045
52f71214efce
builddeb: use codename in version
Sean Farley <sean@farley.io>
parents:
28994
diff
changeset
|
69 debver="$debver+$distance-$CODENAME-$node" |
29093
c4f0e764b231
builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents:
29046
diff
changeset
|
70 elif [ "$DEBFLAGS" = "-S" ] ; then |
c4f0e764b231
builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents:
29046
diff
changeset
|
71 # for building a ppa (--source-only) for a release (distance == 0), we need |
c4f0e764b231
builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents:
29046
diff
changeset
|
72 # to version the distroseries so that we can upload to launchpad |
c4f0e764b231
builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents:
29046
diff
changeset
|
73 debver="$debver~${CODENAME}1" |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
74 fi |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
76 control=debian/control |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
77 changelog=debian/changelog |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 |
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 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
|
80 if [ -d debian ] ; then |
40102
f9c5f7b048b0
packaging: print more specific error messages when builddeb fails
muxator <a.mux@inwind.it>
parents:
38013
diff
changeset
|
81 printf "Error! debian control directory already exists at %s/debian\n" $(pwd) |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
82 exit 1 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 fi |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
84 |
38013
917f635b5c6a
packaging: make packaging scripts less reliant on pwd
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38009
diff
changeset
|
85 cp -r "$ROOTDIR"/contrib/packaging/debian debian |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
86 |
28988 | 87 sed -i.tmp "s/__VERSION__/$debver/" $changelog |
88 sed -i.tmp "s/__DATE__/$(date --rfc-2822)/" $changelog | |
28989
a8256e3701be
builddeb: use the os codename instead of 'unstable'
Sean Farley <sean@farley.io>
parents:
28988
diff
changeset
|
89 sed -i.tmp "s/__CODENAME__/$CODENAME/" $changelog |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
90 rm $changelog.tmp |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
91 |
28993
837119bf7f01
builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents:
28992
diff
changeset
|
92 # remove the node from the version string |
837119bf7f01
builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents:
28992
diff
changeset
|
93 SRCFILE="mercurial_$(echo $debver | sed "s,-$node,,").orig.tar.gz" |
38013
917f635b5c6a
packaging: make packaging scripts less reliant on pwd
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38009
diff
changeset
|
94 "$ROOTDIR/hg" archive $SRCFILE |
28993
837119bf7f01
builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents:
28992
diff
changeset
|
95 mv $SRCFILE .. |
28994
8797f03db5b6
builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents:
28993
diff
changeset
|
96 debuild -us -uc -i -I $DEBFLAGS |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
97 if [ $? != 0 ]; then |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
98 echo 'debuild failed!' |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
99 exit 1 |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
100 fi |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
101 |
24971
ab75baaf81d5
builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 fi |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
103 if [ "$CLEANUP" ] ; then |
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
104 echo |
27210
9b86d29867a5
builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents:
27209
diff
changeset
|
105 OUTPUTDIR=${OUTPUTDIR:=packages/$DISTID-$CODENAME} |
27212
ef9301ce6046
builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents:
27211
diff
changeset
|
106 mkdir -p "$OUTPUTDIR" |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
107 find ../mercurial*.deb ../mercurial_*.build ../mercurial_*.changes \ |
28991
1967c6b714e6
builddeb: copy over .gz and .dsc files
Sean Farley <sean@farley.io>
parents:
28990
diff
changeset
|
108 ../mercurial*.dsc ../mercurial*.gz \ |
28990
62c245c59433
builddeb: ignore errors about find not finding files
Sean Farley <sean@farley.io>
parents:
28989
diff
changeset
|
109 -type f -newer $control -print0 2>/dev/null | \ |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
110 xargs -Inarf -0 mv narf "$OUTPUTDIR" |
26833
6474b64045fb
packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents:
26148
diff
changeset
|
111 echo "Built packages for $debver:" |
40103
01425e3c2645
packaging: print full path to the packages when builddeb finishes successfully
muxator <a.mux@inwind.it>
parents:
40102
diff
changeset
|
112 find "$PWD"/"$OUTPUTDIR" -type f -newer $control -name '*.deb' |
26148
7f49efcaa9b4
debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents:
26108
diff
changeset
|
113 fi |