#!/bin/sh
# This script implements the CLI setmodem command which is
# used to enable or disable modem dial to the switch

# first check for the RBAC permissions for this role.
/fabos/libexec/rbac_check `/bin/basename $0`

if [ $? -ne 0 ]; then
	exit 127
fi

. /etc/init.d/functions

ENABLE_PARAMETER="-e"
DISABLE_PARAMETER="-d"

# setmodem only functions on systems with the extra serial port
HWMODEL=`/sbin/sin | /bin/grep "Platform" | /bin/sed -e"s/[ ]*//g" | /usr/bin/cut -d, -f1 | /usr/bin/cut -d: -f2 2> /dev/null`
case "$HWMODEL" in
"SWBD10"|"SWBD21"|"SWBD42")
	# allow execution
	;;
*)
	echo "setmodem not supported on this system"
	exit 1
	;;
esac

# if no command line argument specified
# display current modem enabled state
if [ -z "$1" ]
then
	if $CHECK setmodem
	then
		echo "modem is currently enabled"
	else
		echo "modem is currently disabled"
	fi
	exit 0
fi

# -e says to enabled the modem
if [ "$1" = "$ENABLE_PARAMETER" ]
then
	echo "enabling modem, please wait, this can take a couple of minutes..."
	chkconfig setmodem on
	setmodem.sh
	echo "modem enabled"
	exit 0
fi

# -d says to disable the modem
if [ "$1" = "$DISABLE_PARAMETER" ]
then
	echo "disabling modem, please wait, this can take a couple of minutes..."
	chkconfig setmodem off
	setmodem.sh
	echo "modem disabled"
	exit 0
fi

# anything else is not valid, display usage
echo "usage: `basename $0`        to display current modem state"
echo "       `basename $0` $ENABLE_PARAMETER     to enable the modem"
echo "       `basename $0` $DISABLE_PARAMETER     to disable the modem"

exit 1
