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