debian / packaging asterisk 13

debian / packaging asterisk 13

  • Written by
    Walter Doekes
  • Published on

As of this writing, Debian testing (stretch) contains Asterisk version 13.1.0. The Debian source as GIT repository is here: https://anonscm.debian.org/git/pkg-voip/asterisk.git (browse)

Packaging a newer version is not that hard, if we start out with the debian/ directory kindly supplied by the Debian maintainers.

Hints to get things running:

Use a local git repository

By using a local git repository in your unpacked Asterisk dir, you can quickly restart from scratch any time you mess anything up.

$ tar zxf asterisk-13.5.0.tar.gz
$ cd asterisk-13.5.0
$ git init; git add -A; git commit -m 'clean version'

Instead of manually cleaning up the build dir with make clean and quilt pop -a, you use git to reset everything efficiently.

$ git reset; git checkout .; git clean -xf
$ rm -rf addons/mp3/ autom4te.cache/ .pc
$ touch configure  # fix timestamp

Update changelog and rename orig tar

Move the (separately versioned) debian directory into the unpacked source directory. Then edit the changelog, using your own versioning scheme.

--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+asterisk (1:13.5.0-test1) wheezy; urgency=medium
+
+  * Test.
+
+ -- Walter Doekes <wjdoekes@example.com>  Tue, 18 Aug 2015 12:32:52 +0200
+
 asterisk (1:13.1.1~dfsg-1) UNRELEASED; urgency=medium

   * New upstream bugfix release: fixes AST-2015-001 and AST-2015-002.

Rename the original tarball, like this:

$ mv asterisk-13.5.0.tar.gz asterisk_13.5.0.orig.tar.gz

Now the package should build

$ cd asterisk-13.5.0
$ dpkg-buildpackage -us -uc -sa

Restart when convenient

But we can do better, for starters by altering the prerm and postinst scripts so Asterisk doesn’t forcefully restart after an upgrade. It’s kinder to have it restart when convenient.

Add --noscript to dh_installinit so it doesn’t auto-generate the service asterisk stop code:

--- a/debian/rules
+++ b/debian/rules
@@ -173,6 +173,9 @@ override_dh_fixperms:
 override_dh_strip:
        dh_strip -a --dbg-package=asterisk-dbg

+override_dh_installinit:
+       dh_installinit --noscripts
+
 print-version:
        @@echo "Debian version:          $(DEBVERSION)"
        @@echo "Upstream version:        $(UPVERSION)"

Manually put the altered “restart” code into the supplied scripts:

--- a/debian/asterisk.prerm
+++ b/debian/asterisk.prerm
@@ -5,4 +5,15 @@ set -e
 rmdir /usr/local/share/asterisk/sounds 2>/dev/null || true
 rmdir /usr/local/share/asterisk        2>/dev/null || true

+# The following bit is placed here manually instead of through the
+# <hash>DEBHELPER<hash> replacement.
+# # if [ -x "/etc/init.d/asterisk" ]; then
+# #     invoke-rc.d asterisk stop || exit $?
+# # fi
+# Only for "prerm remove" do we stop asterisk. In all other cases we
+# wait for the postinst of the new version to "restart when convenient".
+if [ "$1" = "remove" -a -z "$2" ]; then
+    invoke-rc.d asterisk stop || exit $?
+fi
+
 #DEBHELPER#
diff --git a/debian/asterisk.postinst b/debian/asterisk.postinst
index a2a6dc0..06fd4a0 100644
--- a/debian/asterisk.postinst
+++ b/debian/asterisk.postinst
@@ -101,6 +101,21 @@ case "$1" in
     ;;
 esac

+# Since we use a dh_installinit --noscripts in rules, the following is
+# added here manually.
+# (The <hash>DEBHELPER<hash> comment below will get replaced by void.)
+if [ -x "/etc/init.d/asterisk" ]; then
+    update-rc.d asterisk defaults >/dev/null
+    # Regular DEBHELPER code would do this:
+    #invoke-rc.d asterisk start || exit $?
+    # We do this:
+    if ! invoke-rc.d asterisk status >/dev/null 2>&1; then
+        invoke-rc.d asterisk start || exit $?
+    else
+        invoke-rc.d asterisk restart-convenient
+    fi
+fi
+
 # dh_installdeb will replace this with shell code automatically
 # generated by other debhelper scripts.

--- a/debian/asterisk.postrm
+++ b/debian/asterisk.postrm
@@ -8,4 +8,10 @@ if [ "$1" = purge ]; then

 fi

+# The following bit is placed here manually instead of through the
+# <hash>DEBHELPER<hash> replacement.
+if [ "$1" = "purge" ] ; then
+    update-rc.d asterisk remove >/dev/null
+fi
+
 #DEBHELPER#

Speeding up the build

Who settles for single-process builds when we can have more cores at work?

--- a/debian/rules
+++ b/debian/rules
@@ -48,6 +48,13 @@ endif
 ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
        INSTALL_PROGRAM += -s
 endif
+# You can now do this:
+# DEB_BUILD_OPTIONS=parallel=6 dpkg-buildpackage -us -uc
+# See: https://www.debian.org/doc/debian-policy/ch-source.html
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+       NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+       BUILDFLAGS += -j$(NUMJOBS)
+endif

 DEBVERSION:=$(shell dpkg-parsechangelog | sed -n -e 's/Version: //p')
 DEB_NOEPOCH_VERSION:=$(shell echo $(DEBVERSION) | cut -d':' -f 2)

Now you start the build like this:

$ DEB_BUILD_OPTIONS=parallel=6 dpkg-buildpackage -us -uc -sa

Fixing relocation errors

Perhaps you get this error:

/usr/bin/ld: app_voicemail_imapstorage.o: relocation R_X86_64_PC32
  against symbol `mm_log' can not be used when making a shared object;
  recompile with -fPIC

While I’m not entirely sure why, we can fix the problem by doing this:

--- a/debian/rules
+++ b/debian/rules
@@ -13,7 +13,7 @@
 %:
        dh "$@" --with autotools_dev,autoreconf,systemd

-export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
 DPKG_EXPORT_BUILDFLAGS = 1
 include /usr/share/dpkg/buildflags.mk

Updating the ABI hash

At this point, you should almost have a working build. Except for the updated ABI hash. Since we’re not using external modules, we can simply update the hash whenever we like.

So, if you see this:

# Sanity check: don't break the ABI for modules:
Debian packaging problem: ABI checksum changed.
  Was: 32b00085fac294c16fcde5db8ce7e676
  Now: fa819827cbff2ea35341af5458859233

You change this:

--- a/debian/rules
+++ b/debian/rules
@@ -18,7 +18,7 @@ DPKG_EXPORT_BUILDFLAGS = 1
 include /usr/share/dpkg/buildflags.mk

 # Sanity check for a stable release:
-SAVED_ABI_HASH = 32b00085fac294c16fcde5db8ce7e676
+SAVED_ABI_HASH = fa819827cbff2ea35341af5458859233

 export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
 export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

Update 2015-10-27

The hash calculation was changed in Asterisk 11.18 and 13.4 with the fixes from ASTERISK-25028.

The default hash is now simply:

$ echo LOADABLE_MODULES | md5sum
f450f61f60e761b3aa089ebed76ca8a5  -

Optionally disable systemd

Perhaps your system has no systemd. In that case you need to remove a few more items.

--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,6 @@ Section: comm
 Maintainer: Debian VoIP Team <pkg-voip-maintainers@lists.alioth.debian.org>
 Uploaders: Mark Purcell <msp@debian.org>, Tzafrir Cohen <tzafrir@debian.org>, Jeremy Lainé <jeremy.laine@m4x.org>, Daniel Pocock <daniel@pocock.com.au>
 Build-Depends: debhelper (>= 9),
- dh-systemd,
  dpkg-dev (>= 1.16.1.1),
  lsb-base (>= 3.2-14),
  libreadline-dev | libreadline5-dev,
--- a/debian/rules
+++ b/debian/rules
@@ -11,7 +11,7 @@
 #  The "all" option enables "PIE" and "BINDNOW" and future hardening flags

 %:
- dh "$@" --with autotools_dev,autoreconf,systemd
+ dh "$@" --with autotools_dev,autoreconf

 export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
 DPKG_EXPORT_BUILDFLAGS = 1

--- a/debian/patches/series
+++ b/debian/patches/series
@@ -21,5 +21,5 @@ astdatadir
 reenable
 smsq_enable.patch
 aelparse_enable.patch
-systemd.patch
+#systemd.patch
 #test_framework.patch
--- a/debian/asterisk.examples
+++ b/debian/asterisk.examples
@@ -1,4 +1,4 @@
 sample.call
 contrib/scripts/vmail.cgi
 debian/asterisk.startup.conf
-contrib/scripts/asterisk_cleanup
+#contrib/scripts/asterisk_cleanup
--- a/debian/asterisk.install
+++ b/debian/asterisk.install
@@ -4,4 +4,4 @@ usr/share/asterisk/firmware
 usr/share/asterisk/keys
 usr/share/asterisk/conf
 usr/share/asterisk/documentation
-lib/systemd/system/asterisk.service
+#lib/systemd/system/asterisk.service

Done

If all went well, your parent directory now contains these:

asterisk-13.5.0/                       asterisk-doc_13.5.0-test1_all.deb
asterisk_13.5.0.orig.tar.gz            asterisk-mobile_13.5.0-test1_amd64.deb
asterisk_13.5.0-test1_amd64.changes    asterisk-modules_13.5.0-test1_amd64.deb
asterisk_13.5.0-test1_amd64.deb        asterisk-mp3_13.5.0-test1_amd64.deb
asterisk_13.5.0-test1.debian.tar.gz    asterisk-mysql_13.5.0-test1_amd64.deb
asterisk_13.5.0-test1.dsc              asterisk-ooh323_13.5.0-test1_amd64.deb
asterisk-config_13.5.0-test1_all.deb   asterisk-voicemail_13.5.0-test1_amd64.deb
asterisk-dahdi_13.5.0-test1_amd64.deb  asterisk-voicemail-imapstorage_13.5.0-test1_amd64.deb
asterisk-dbg_13.5.0-test1_amd64.deb    asterisk-voicemail-odbcstorage_13.5.0-test1_amd64.deb
asterisk-dev_13.5.0-test1_all.deb      asterisk-vpb_13.5.0-test1_amd64.deb

Enjoy!


Back to overview Newer post: python / subprocess / winch Older post: on-the-fly encrypted backups