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