#!/bin/sh
# $Id: asterisk-codec_g729a 136190 2008-08-06 20:14:54Z tilghman $
#
# asterisk-codec_g729a    Starts, Stops and Reloads Asterisk G.729 codec module.
#
# chkconfig: 2345 89 61
# description: Asterisk G.729 codec optimization selection.

ASTMODDIR=/usr/lib/asterisk/modules
SBINDIR=/usr/sbin
BENCHTOOL=${SBINDIR}/benchg729

# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0

start() {
	# Start daemons.
	echo -n $"Starting asterisk-codec_g729a: "
        if [ -x ${BENCHTOOL} ] ; then
		ARCH=$(uname -m)

		case "$ARCH" in
		    i386|i686)
			BITS="32"
			;;
		    x86_64|amd64)
			BITS="64"
			;;
		    *)
			echo "Unknown architecture found (${ARCH}); aborting."
			exit 0
			;;
		esac

		OPTFLAVOR=$(${BENCHTOOL} -q 2>/dev/null)
		RETVAL=$?
		if [ $RETVAL -eq 0 ] ; then
			ln -sf ${ASTMODDIR}/codec_g729a-${OPTFLAVOR}_${BITS}/codec_g729a.so ${ASTMODDIR}/codec_g729a.so
		fi
	fi
	echo
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down asterisk-codec_g729a: "
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  *)
	echo "Usage: asterisk-codec_g729a {start|stop|restart}"
	exit 1
esac

exit $?
