#!/bin/bash
#
######################################################################
#
# Shell script to start/stop Dialogic Runtime Software
#
# Copyright (C) 2001-2008 Dialogic Corporation.  All Rights Reserved.
#
# All names, products, and services mentioned herein are the
# trademarks or registered trademarks of their respective
# organizations and are the sole property of their respective
# owners.
#
######################################################################

# Check for file containing our environment variables.
# If it is not found, abort the script execution.
OURVARS=/etc/profile.d/ct_intel.sh
if [ ! -x ${OURVARS} ]
then
	echo "$0: FATAL ERROR: Unable to find ${OURVARS}."
	echo "$0: FATAL ERROR: Startup/shutdown aborted due to invalid installation."
	echo "$0: FATAL ERROR: Please reinstall the software by running install.sh."
	exit 5
fi

if [ -z "${INTEL_DIALOGIC_DIR}" ] 
then
   # get our environment variables
   . ${OURVARS} 
fi

DLGCSTARTKILLSCRIPT=/etc/init.d/ct_intel

if [ ! -x ${DLGCSTARTKILLSCRIPT} ]
then
	echo "$0: FATAL ERROR: Unable to find ${DLGCSTARTKILLSCRIPT}."
	echo "$0: FATAL ERROR: Startup/shutdown aborted due to invalid installation."
	echo "$0: FATAL ERROR: Please reinstall the software by running install.sh."
	exit 5
fi

#
# Determine if I am being called to start or stop.
#

SCRIPTNAME=`basename $0`

case $SCRIPTNAME in
dlstop)
    USAGE="$SCRIPTNAME: stops all telephony boards and system software"
    EXE1="${DLGCSTARTKILLSCRIPT} stop"
    ;;
dlstart)
    USAGE="$SCRIPTNAME: starts all telephony boards and system software"
    EXE1="${DLGCSTARTKILLSCRIPT} start"
    ;;
dlstatus)
    USAGE="$SCRIPTNAME: display the system status"
    EXE1="${DLGCSTARTKILLSCRIPT} status"
    ;;

*)
    echo "Illegal script name: $SCRIPTNAME"
    exit 1
esac

# Check command line options
while getopts "h" Option
do
    case $Option in
       h     ) 
               echo $USAGE;
               exit 1;; 
       *     ) echo "Unimplemented option chosen.";
               echo $USAGE;
               exit 3;; 
    esac
done 
shift $(($OPTIND - 1))

$EXE1

exit 0
