aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-11-17 10:30:37 +0200
committerTimo Teräs <timo.teras@iki.fi>2011-11-17 10:30:37 +0200
commite21aa81e21e52fd618dc5d7cae48f5d788c8991f (patch)
tree527f9994d79df7c86fdd719c6ece68fe031696d3
parentaf8f7454a4f2858316a5fb832da2a91ae0b4f890 (diff)
downloadaports-e21aa81e21e52fd618dc5d7cae48f5d788c8991f.tar.bz2
aports-e21aa81e21e52fd618dc5d7cae48f5d788c8991f.tar.xz
testing/asterisk: copied from main with upgrade to 10.0.0-rc2
-rw-r--r--testing/asterisk/100-uclibc-daemon.patch44
-rw-r--r--testing/asterisk/101-caps-uclibc.patch17
-rw-r--r--testing/asterisk/102-gsm-pic.patch54
-rw-r--r--testing/asterisk/400-bug-227.patch15
-rw-r--r--testing/asterisk/APKBUILD168
-rw-r--r--testing/asterisk/asterisk.confd91
-rw-r--r--testing/asterisk/asterisk.initd251
-rw-r--r--testing/asterisk/asterisk.logrotate17
-rw-r--r--testing/asterisk/asterisk.post-install11
-rw-r--r--testing/asterisk/asterisk.pre-install12
-rw-r--r--testing/asterisk/asterisk.pre-upgrade12
11 files changed, 692 insertions, 0 deletions
diff --git a/testing/asterisk/100-uclibc-daemon.patch b/testing/asterisk/100-uclibc-daemon.patch
new file mode 100644
index 0000000000..4956791d4d
--- /dev/null
+++ b/testing/asterisk/100-uclibc-daemon.patch
@@ -0,0 +1,44 @@
+diff -Nru asterisk-1.6.1-beta4.org/main/asterisk.c asterisk-1.6.1-beta4/main/asterisk.c
+--- asterisk-1.6.1-beta4.org/main/asterisk.c 2008-12-12 23:05:58.000000000 +0100
++++ asterisk-1.6.1-beta4/main/asterisk.c 2008-12-23 15:28:21.000000000 +0100
+@@ -3295,9 +3295,40 @@
+ #if HAVE_WORKING_FORK
+ if (ast_opt_always_fork || !ast_opt_no_fork) {
+ #ifndef HAVE_SBIN_LAUNCHD
++#ifndef __UCLIBC__
+ if (daemon(1, 0) < 0) {
+ ast_log(LOG_ERROR, "daemon() failed: %s\n", strerror(errno));
+ }
++#else
++ /*
++ * workaround for uClibc-0.9.29 mipsel bug:
++ * recursive mutexes do not work if uClibc daemon() function has been called,
++ * if parent thread locks a mutex
++ * the child thread cannot acquire a lock with the same name
++ * (same code works if daemon() is not called)
++ * but duplication of uClibc daemon.c code in here does work.
++ */
++ int fd;
++ switch (fork()) {
++ case -1:
++ exit(1);
++ case 0:
++ break;
++ default:
++ _exit(0);
++ }
++ if (setsid() == -1)
++ exit(1);
++ if (fork())
++ _exit(0);
++ if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
++ dup2(fd, STDIN_FILENO);
++ dup2(fd, STDOUT_FILENO);
++ dup2(fd, STDERR_FILENO);
++ if (fd > 2)
++ close(fd);
++ }
++#endif
+ ast_mainpid = getpid();
+ /* Blindly re-write pid file since we are forking */
+ unlink(ast_config_AST_PID);
diff --git a/testing/asterisk/101-caps-uclibc.patch b/testing/asterisk/101-caps-uclibc.patch
new file mode 100644
index 0000000000..bb32d1ece1
--- /dev/null
+++ b/testing/asterisk/101-caps-uclibc.patch
@@ -0,0 +1,17 @@
+--- asterisk-1.6.0.18/configure.ac.orig Mon Oct 26 23:13:28 2009
++++ asterisk-1.6.0.18/configure.ac Fri Nov 27 21:42:36 2009
+@@ -627,9 +627,11 @@
+
+ AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
+
+-if test "x${OSARCH}" = "xlinux-gnu" ; then
+- AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
+-fi
++case "${OSARCH}" in
++ linux*)
++ AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
++ ;;
++esac
+
+ AST_C_DEFINE_CHECK([DAHDI], [DAHDI_CODE], [dahdi/user.h])
+
diff --git a/testing/asterisk/102-gsm-pic.patch b/testing/asterisk/102-gsm-pic.patch
new file mode 100644
index 0000000000..71370ec0b7
--- /dev/null
+++ b/testing/asterisk/102-gsm-pic.patch
@@ -0,0 +1,54 @@
+--- a/codecs/gsm/Makefile.org 2008-03-29 11:33:09.000000000 +0100
++++ b/codecs/gsm/Makefile 2008-03-29 11:44:40.000000000 +0100
+@@ -37,23 +37,6 @@
+ ######### ppro's, etc, as well as the AMD K6 and K7. The compile will
+ ######### probably require gcc.
+
+-ifeq (, $(findstring $(OSARCH) , Darwin SunOS ))
+-ifeq (, $(findstring $(PROC) , x86_64 amd64 ultrasparc sparc64 arm armv5b armeb ppc powerpc ppc64 ia64 s390 bfin mipsel mips))
+-ifeq (, $(findstring $(shell uname -m) , ppc ppc64 alpha armv4l s390 ))
+-OPTIMIZE+=-march=$(PROC)
+-endif
+-endif
+-endif
+-
+-#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
+-#This works for even old (2.96) versions of gcc and provides a small boost either way.
+-#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesn't support it.
+-#So we go lowest common available by gcc and go a step down, still a step up from
+-#the default as we now have a better instruction set to work with. - Belgarath
+-ifeq ($(PROC),ultrasparc)
+-OPTIMIZE+=-mcpu=v8 -mtune=$(PROC) -O3
+-endif
+-
+ PG =
+ #PG = -g -pg
+ ######### Profiling flags. If you don't know what that means, leave it blank.
+@@ -208,12 +191,10 @@
+ # XXX Keep a space after each findstring argument
+ # XXX should merge with GSM_OBJECTS
+ ifeq ($(OSARCH),linux-gnu)
+-ifeq (,$(findstring $(shell uname -m) , x86_64 amd64 ppc ppc64 alpha armv4l sparc64 parisc s390 ))
+-ifeq (,$(findstring $(PROC) , arm armv5b armeb powerpc ia64 s390 bfin mipsel mips ))
++ifneq ($(K6OPT),)
+ GSM_SOURCES+= $(SRC)/k6opt.s
+ endif
+ endif
+-endif
+
+ TOAST_SOURCES = $(SRC)/toast.c \
+ $(SRC)/toast_lin.c \
+@@ -260,12 +241,10 @@
+ $(SRC)/table.o
+
+ ifeq ($(OSARCH),linux-gnu)
+-ifeq (,$(findstring $(shell uname -m) , x86_64 amd64 ppc ppc64 alpha armv4l sparc64 parisc ))
+-ifeq (,$(findstring $(PROC) , arm armv5b armeb powerpc ia64 bfin mipsel mips ))
++ifneq ($(K6OPT),)
+ GSM_OBJECTS+= $(SRC)/k6opt.o
+ endif
+ endif
+-endif
+
+ TOAST_OBJECTS = $(SRC)/toast.o \
+ $(SRC)/toast_lin.o \
diff --git a/testing/asterisk/400-bug-227.patch b/testing/asterisk/400-bug-227.patch
new file mode 100644
index 0000000000..f8187379e1
--- /dev/null
+++ b/testing/asterisk/400-bug-227.patch
@@ -0,0 +1,15 @@
+Index: channels/chan_sip.c
+===================================================================
+--- a/channels/chan_sip.c (revision 212243)
++++ b/channels/chan_sip.c (working copy)
+@@ -3675,8 +3675,8 @@
+ char method_str[31];
+ ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
+ append_history(p, "ReliableXmit", "timeout");
+- if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) {
+- if (method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) {
++ if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Init: %30s", method_str) == 1) {
++ if (method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str) || method_match(SIP_INVITE, method_str)) {
+ pvt_set_needdestroy(p, "autodestruct");
+ }
+ }
diff --git a/testing/asterisk/APKBUILD b/testing/asterisk/APKBUILD
new file mode 100644
index 0000000000..d237a45f0b
--- /dev/null
+++ b/testing/asterisk/APKBUILD
@@ -0,0 +1,168 @@
+# Contributor: Timo Teras <timo.teras@iki.fi>
+# Maintainer: Timo Teras <timo.teras@iki.fi>
+pkgname=asterisk
+pkgver=10.0.0_rc2
+pkgrel=0
+pkgdesc="Asterisk: A Module Open Source PBX System"
+url="http://www.asterisk.org/"
+arch="all"
+license="GPL"
+depends=
+makedepends="autoconf automake libtool ncurses-dev popt-dev newt-dev zlib-dev
+ postgresql-dev unixodbc-dev dahdi-tools-dev libpri-dev tar
+ freetds-dev openssl-dev lua-dev alsa-lib-dev spandsp-dev tiff-dev
+ libresample sqlite-dev wget speex-dev"
+install="$pkgname.pre-install $pkgname.pre-upgrade $pkgname.post-install"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-pgsql $pkgname-odbc
+ $pkgname-tds $pkgname-fax $pkgname-sample-config:sample $pkgname-sqlite
+ $pkgname-sounds-moh:sound_moh $pkgname-sounds-en:sound_en"
+source="http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-${pkgver/_/-}.tar.gz
+ 100-uclibc-daemon.patch
+ 101-caps-uclibc.patch
+ 400-bug-227.patch
+ asterisk.initd
+ asterisk.confd
+ asterisk.logrotate"
+
+_builddir="$srcdir/$pkgname-${pkgver/_/-}"
+
+prepare() {
+ cd "$_builddir"
+ for i in ../[1-9]*.patch; do
+ msg "Apply $i"
+ patch -p1 < $i || return 1
+ done
+
+ sed -i -e 's:lua5.1/::' pbx/pbx_lua.c
+ sed -i -e 's/PBX_ICONV=1/PBX_ICONV=0/g' configure.ac
+
+ ./bootstrap.sh
+}
+
+build() {
+ cd "$_builddir"
+ SHA1SUM="$PWD"/build_tools/sha1sum-sh ./configure --prefix=/usr \
+ --sysconfdir=/etc \
+ --mandir=/usr/share/man \
+ --infodir=/usr/share/info \
+ --libdir=/usr/lib \
+ --localstatedir=/var \
+ --disable-xmldoc --with-gsm=internal \
+ --without-iconv --with-popt --with-z --with-newt \
+ --with-odbc --with-postgres --with-tds \
+ --with-dahdi --with-pri --with-tonezone \
+ --with-resample \
+ --with-sqlite3 \
+ --with-speex \
+ --with-asound \
+ --without-x11 \
+ --with-spandsp \
+ || return 1
+
+ # and figure out which modules to build
+ rm menuselect.makeopts
+ make menuselect.makeopts
+ make ASTLDFLAGS="$LDFLAGS" || return 1
+}
+
+package() {
+ cd "$_builddir"
+ make -j1 DESTDIR="$pkgdir" install
+
+ install -d "$pkgdir"/var/run/asterisk
+ install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
+ install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
+ install -m644 -D "$srcdir"/$pkgname.logrotate \
+ "$pkgdir"/etc/logrotate.d/$pkgname
+}
+
+_move_dir() {
+ for DIR in "$@"; do
+ local dest=`dirname "$subpkgdir/$DIR"`
+ echo mkdir -p $dest
+ mkdir -p "$dest"
+ echo mv "$pkgdir"/$DIR $dest
+ mv "$pkgdir"/"$DIR" "$dest"
+ done
+}
+
+_find_and_move() {
+ local pattern="$1"
+ cd "$pkgdir" || return 1
+ find -name "$pattern" -type f | while read f; do
+ local dest="$subpkgdir/${f%/*}"
+ mkdir -p "$dest"
+ mv "$f" "$dest"
+ done
+}
+
+doc() {
+ default_doc
+}
+
+dev() {
+ default_dev
+ depends="asterisk"
+}
+
+pgsql() {
+ depends=
+ install=
+ _find_and_move '*_pgsql*'
+}
+
+sqlite() {
+ depends=
+ install=
+ _find_and_move '*_sqlite*'
+}
+
+odbc() {
+ depends=
+ install=
+ _find_and_move '*odbc*'
+}
+
+tds() {
+ depends=
+ install=
+ _find_and_move '*_tds*'
+}
+
+fax() {
+ depends=
+ install=
+ _find_and_move '*_fax*'
+}
+
+sample() {
+ arch="noarch"
+ pkgdesc="Sample configuration files for asterisk"
+ cd "$_builddir"
+ mkdir -p "$subpkgdir"/var/lib/asterisk/phoneprov
+ make -j1 samples DESTDIR="$subpkgdir"
+}
+
+sound_moh() {
+ arch="noarch"
+ pkgdesc="Default on-hold music files for asterisk"
+ depends=
+ install=
+ _move_dir var/lib/asterisk/moh
+}
+
+sound_en() {
+ arch="noarch"
+ pkgdesc="English sound files for asterisk"
+ depends=
+ install=
+ _move_dir var/lib/asterisk/sounds/en
+}
+
+md5sums="72e0df43d5bcf44400dcf0014fd40a3f asterisk-10.0.0-rc2.tar.gz
+b00c9d98ce2ad445501248a197c6e436 100-uclibc-daemon.patch
+6e1129e30c4fd2c25c86c81685a485a9 101-caps-uclibc.patch
+79e9634b5054bceb3b8dc246654bb243 400-bug-227.patch
+0ce3219e05f55af884a7dc6b99c2b276 asterisk.initd
+ed31d7ba37bcf8b0346dcf8593c395f0 asterisk.confd
+3e65172275684373e1a25c8a11224411 asterisk.logrotate"
diff --git a/testing/asterisk/asterisk.confd b/testing/asterisk/asterisk.confd
new file mode 100644
index 0000000000..fe9f138ab7
--- /dev/null
+++ b/testing/asterisk/asterisk.confd
@@ -0,0 +1,91 @@
+#
+# Additional options for asterisk
+#
+# see "asterisk -h" for a list of options
+#
+ASTERISK_OPTS=""
+
+#
+# User and group to run asterisk as
+#
+# Value: double-colon separated list of user and group, or empty to run as root:
+#
+#
+# "asterisk:asterisk" to run as user "asterisk" and group "asterisk"
+# "asterisk" to run as user "asterisk" and all groups that user "asterisk" is a member of
+# ":asterisk" to run as user "root" and group "asterisk"
+# "" to run as user "root" and group "root"
+#
+ASTERISK_USER="asterisk"
+
+#
+# Nicelevel
+#
+# Set the priority of the asterisk process
+#
+# Value: (highest) -20..19 (lowest)
+#
+#ASTERISK_NICE="19"
+
+#
+# Wrapper script
+#
+# Value: yes or no/empty
+#
+ASTERISK_WRAPPER="no"
+
+############# Wrapper script settings #############
+
+#
+# Send crash notifications emails to this address
+# (needs a working mail service and /usr/sbin/sendmail to do so (e.g. ssmtp))
+#
+# Value: Email address or empty to disable
+#
+#ASTERISK_NOTIFY_EMAIL="root"
+
+#
+# Send asterisk's output to this terminal
+#
+# Value: Full path to device node or a number
+#
+#ASTERISK_TTY="/dev/tty9"
+
+#
+# Start an asterisk console on the terminal specified by ASTERISK_TTY
+#
+# Warning! Use only for debugging, this is a potential security issue!
+#
+# Value: yes or no/empty
+#
+ASTERISK_CONSOLE="no"
+
+#
+# Maximum size of core files.
+#
+# Value: Size in bytes, unlimited for no limit or empty to disable.
+#
+#ASTERISK_CORE_SIZE="unlimited"
+
+#
+# ASTERISK_CORE_DIR
+#
+# Value: Directory (will be created if non-existant), default is /tmp
+#
+ASTERISK_CORE_DIR="/var/lib/asterisk/coredump"
+
+#
+# Max number of filedescriptors
+#
+# Value: Number of descriptors
+#
+#ASTERISK_MAX_FD="1024"
+
+#
+# Kill these tasks after asterisk crashed (ASTERISK_WRAPPER=yes only!)
+#
+# Warning! This will kill _ALL_ tasks with the specified names!
+#
+# Value: Space separated list of names in double quotes (e.g. "mpg123 mad")
+#
+#ASTERISK_CLEANUP_ON_CRASH="mpg123 asterisk-mpg123 mad"
diff --git a/testing/asterisk/asterisk.initd b/testing/asterisk/asterisk.initd
new file mode 100644
index 0000000000..284898ae22
--- /dev/null
+++ b/testing/asterisk/asterisk.initd
@@ -0,0 +1,251 @@
+#!/sbin/runscript
+
+opts="${opts} forcestop reload"
+
+depend() {
+ need net
+ after firewall
+ use nscd dns zaptel mysql postgresql slapd capi
+}
+
+is_running() {
+ if [ -z "$(pidof asterisk)" ]; then
+ return 1
+ else
+ PID="$(cat /var/run/asterisk/asterisk.pid 2>/dev/null)"
+ for x in $(pidof asterisk); do
+ if [ "${x}" = "${PID}" ]; then
+ return 0
+ fi
+ done
+ fi
+
+ return 1
+}
+
+asterisk_run_loop() {
+ local OPTS ARGS MSG NICE=""
+ local result=0 signal=0
+
+ # default options
+ OPTS="-f" # don't fork / detach breaks wrapper script...
+
+ # filter (redundant) arguments
+ ARGS="$(echo "${@}" | sed -e "s:-c\|-f::g")"
+
+ # mangle yes/no options
+ ASTERISK_CONSOLE="$(echo ${ASTERISK_CONSOLE} | tr '[:lower:]' '[:upper:]')"
+
+ if [ -n "${ASTERISK_CORE_SIZE}" ] &&
+ [ "${ASTERISK_CORE_SIZE}" != "0" ]; then
+ ulimit -c ${ASTERISK_CORE_SIZE}
+
+ if [ -n "${ASTERISK_CORE_DIR}" ] && \
+ [ ! -d "${ASTERISK_CORE_DIR}" ]
+ then
+ mkdir -m750 -p "${ASTERISK_CORE_DIR}"
+
+ if [ -n "${ASTERISK_USER}" ]; then
+ chown -R "${ASTERISK_USER}" "${ASTERISK_CORE_DIR}"
+ fi
+ fi
+ ASTERISK_CORE_DIR="${ASTERISK_CORE_DIR:-/tmp}"
+
+ cd "${ASTERISK_CORE_DIR}"
+ echo " Core dump size : ${ASTERISK_CORE_SIZE}"
+ echo " Core dump location : ${ASTERISK_CORE_DIR}"
+ fi
+
+ if [ -n "${ASTERISK_MAX_FD}" ]; then
+ ulimit -n ${ASTERISK_MAX_FD}
+ echo " Max open filedescriptors : ${ASTERISK_MAX_FD}"
+ fi
+
+ if [ -n "${ASTERISK_NICE}" ]; then
+ echo " Nice level : ${ASTERISK_NICE}"
+ NICE="nice -n ${ASTERISK_NICE} --"
+ fi
+
+ if [ -n "${ASTERISK_NOTIFY_EMAIL}" ]; then
+ if [ -x /usr/sbin/sendmail ]; then
+ echo " Email notifications go to : ${ASTERISK_NOTIFY_EMAIL}"
+ else
+ echo " Notifications disabled, /usr/sbin/sendmail doesn't exist or is not executable!"
+ unset ASTERISK_NOTIFY_EMAIL
+ fi
+ fi
+
+ if [ -n "${ASTERISK_TTY}" ]; then
+ for x in ${ASTERISK_TTY} \
+ /dev/tty${ASTERISK_TTY} \
+ /dev/vc/${ASTERISK_TTY}
+ do
+ if [ -c "${x}" ]; then
+ TTY="${x}"
+ fi
+ done
+ [ -n "${TTY}" ] && \
+ echo " Messages are sent to : ${TTY}"
+ fi
+
+ if [ "${ASTERISK_CONSOLE}" = "YES" ] && [ -n "${TTY}" ]; then
+ echo " Starting Asterisk console : ${ASTERISK_CONSOLE}"
+ OPTS="${OPTS} -c"
+ fi
+
+ OPTS="${OPTS} ${ARGS}"
+
+ while :; do
+
+ if [ -n "${TTY}" ]; then
+ /usr/bin/stty -F ${TTY} sane
+ ${NICE} /usr/sbin/asterisk ${OPTS} >${TTY} 2>&1 <${TTY}
+ result=$?
+ else
+ ${NICE} /usr/sbin/asterisk ${OPTS} &>/dev/null
+ result=$?
+ fi
+
+ if [ $result -eq 0 ]; then
+ echo "Asterisk terminated normally"
+ break
+ else
+ if [ $result -gt 128 ]; then
+ signal=$((result - 128))
+ MSG="Asterisk terminated with Signal: $signal"
+
+ CORE_TARGET="core-$(date "+%Y%m%d-%h%M%s")"
+
+ local CORE_DUMPED=0
+ if [ -f "${ASTERISK_CORE_DIR}/core" ]; then
+ mv "${ASTERISK_CORE_DIR}/core" \
+ "${ASTERISK_CORE_DIR}/${CORE_TARGET}"
+ CORE_DUMPED=1
+
+ elif [ -f "${ASTERISK_CORE_DIR}/core.${PID}" ]; then
+ mv "${ASTERISK_CORE_DIR}/core.${PID}" \
+ "${ASTERISK_CORE_DIR}/${CORE_TARGET}"
+ CORE_DUMPED=1
+
+ fi
+
+ [ $CORE_DUMPED -eq 1 ] && \
+ MSG="${MSG}\n\rCore dumped: ${ASTERISK_CORE_DIR}/${CORE_TARGET}"
+ else
+ MSG="Asterisk terminated with return code: $result"
+ fi
+
+ # kill left-over tasks
+ for X in ${ASTERISK_CLEANUP_ON_CRASH}; do
+ kill -9 $(pidof ${X});
+ done
+ fi
+
+ [ -n "${TTY}" ] \
+ && echo "${MSG}" >${TTY} \
+ || echo "${MSG}"
+
+
+ if [ -n "${ASTERISK_NOTIFY_EMAIL}" ] && \
+ [ -x /usr/sbin/sendmail ]; then
+ echo -e -n "Subject: Asterisk crashed\n\r${MSG}\n\r" |\
+ /usr/sbin/sendmail "${ASTERISK_NOTIFY_EMAIL}"
+ fi
+ sleep 5
+ echo "Restarting Asterisk..."
+ done
+ return 0
+}
+
+start() {
+ local OPTS USER GROUP PID
+ local tmp x
+
+ if [ -n "${ASTERISK_NICE}" ]; then
+ if [ ${ASTERISK_NICE} -ge -20 ] && \
+ [ ${ASTERISK_NICE} -le 19 ]; then
+ OPTS="--nicelevel ${ASTERISK_NICE}"
+ else
+ eerror "Nice value must be between -20 and 19"
+ return 1
+ fi
+ fi
+
+ if [ -n "${ASTERISK_USER}" ]; then
+ USER=$(echo $ASTERISK_USER | sed 's/:.*//')
+ GROUP=$(echo $ASTERISK_USER | awk -F: '/.*:.*/ { print $2 }')
+ if [ -n "${USER}" ]; then
+ ASTERISK_OPTS="${ASTERISK_OPTS} -U ${USER}"
+ fi
+ if [ -n "${GROUP}" ]; then
+ ASTERISK_OPTS="${ASTERISK_OPTS} -G ${GROUP}"
+ GROUP=":${GROUP}" # make it look nice...
+ fi
+ ebegin "Starting asterisk PBX (as ${USER}${GROUP})"
+ else
+ ebegin "Starting asterisk PBX (as root)"
+ fi
+
+ if [ "$(echo ${ASTERISK_WRAPPER} | tr '[:upper:]' '[:lower:]')" != "yes" ]; then
+ start-stop-daemon --start --exec /usr/sbin/asterisk \
+ ${OPTS} -- ${ASTERISK_OPTS}
+ result=$?
+ else
+ asterisk_run_loop ${ASTERISK_OPTS} 2>/dev/null &
+ result=$?
+ fi
+
+ if [ $result -eq 0 ]; then
+ # 2 seconds should be enough for asterisk to start
+ sleep 2
+ is_running
+ result=$?
+ fi
+
+ eend $result
+}
+
+forcestop() {
+ ebegin "Stopping asterisk PBX"
+ start-stop-daemon --stop --pidfile /var/run/asterisk/asterisk.pid
+ eend $?
+}
+
+stop() {
+ if ! is_running; then
+ eerror "Asterisk is not running!"
+ return 0
+ fi
+
+ ebegin "Stopping asterisk PBX now"
+ /usr/sbin/asterisk -r -x "core stop now" &>/dev/null
+ # Now we have to wait until asterisk has _really_ stopped.
+ sleep 1
+ if is_running; then
+ einfon "Waiting for asterisk to shutdown ."
+ local cnt=0
+ while is_running; do
+ cnt=`expr $cnt + 1`
+ if [ $cnt -gt 60 ] ; then
+ # Waited 120 seconds now. Fail.
+ echo
+ eend 1 "Failed."
+ return
+ fi
+ sleep 2
+ echo -n "."
+ done
+ echo
+ fi
+ eend 0
+}
+
+reload() {
+ if is_running; then
+ ebegin "Forcing asterisk to reload configuration"
+ /usr/sbin/asterisk -r -x "modules reload" &>/dev/null
+ eend $?
+ else
+ eerror "Asterisk is not running!"
+ fi
+}
diff --git a/testing/asterisk/asterisk.logrotate b/testing/asterisk/asterisk.logrotate
new file mode 100644
index 0000000000..30836c5c11
--- /dev/null
+++ b/testing/asterisk/asterisk.logrotate
@@ -0,0 +1,17 @@
+/var/log/asterisk/messages /var/log/asterisk/*log {
+ missingok
+ rotate 5
+ weekly
+ create 0640 asterisk asterisk
+ postrotate
+ /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
+ endscript
+}
+
+/var/log/asterisk/cdr-csv/*csv {
+ missingok
+ rotate 5
+ monthly
+ create 0640 asterisk asterisk
+}
+
diff --git a/testing/asterisk/asterisk.post-install b/testing/asterisk/asterisk.post-install
new file mode 100644
index 0000000000..fd51c7fa5d
--- /dev/null
+++ b/testing/asterisk/asterisk.post-install
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+chown -R asterisk:asterisk /var/*/asterisk
+chown -R asterisk:asterisk /etc/asterisk
+chmod -R u=rwX,g=rX,o= /etc/asterisk
+
+# set IP ToS
+# iptables -A OUTPUT -t mangle -p udp -m udp --dport 5060 -j DSCP --set-dscp 0x28
+#iptables -A OUTPUT -t mangle -p udp -m udp --sport 10000:20000 -j DSCP --set-dscp 0x28
+# more info: http://www.voip-info.org/wiki-Asterisk+non-root
+
diff --git a/testing/asterisk/asterisk.pre-install b/testing/asterisk/asterisk.pre-install
new file mode 100644
index 0000000000..09985d7cdb
--- /dev/null
+++ b/testing/asterisk/asterisk.pre-install
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+user=asterisk
+home=/var/lib/asterisk
+adduser -h $home -s /bin/false -D $user 2>/dev/null
+mkdir -p $home
+chown $user:$user $home
+
+addgroup dialout 2>/dev/null
+addgroup $user dialout 2>/dev/null
+exit 0
+
diff --git a/testing/asterisk/asterisk.pre-upgrade b/testing/asterisk/asterisk.pre-upgrade
new file mode 100644
index 0000000000..09985d7cdb
--- /dev/null
+++ b/testing/asterisk/asterisk.pre-upgrade
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+user=asterisk
+home=/var/lib/asterisk
+adduser -h $home -s /bin/false -D $user 2>/dev/null
+mkdir -p $home
+chown $user:$user $home
+
+addgroup dialout 2>/dev/null
+addgroup $user dialout 2>/dev/null
+exit 0
+