#! /bin/sh
# Copyright (c) 2000-2001, AEP Ltd. 

# All rights reserved.

# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, 
# this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation 
# and/or other materials provided with the distribution.

# 3. Neither the name of AEP Ltd. nor the names of its contributors 
# may be used to endorse or promote products derived from this software 
# without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

# *****************************************************************************
#****************************************************************************/

#/**********************************************************************
#*                                                                     *
#* AEP Ltd.                                                            *
#*                                                                     *
#* This software is supplied under the terms of the license included   *
#* above.  All use of this software must be in accordance with the     *
#* terms of that license.                                              *
#*                                                                     *
#**********************************************************************/
 

INSTALL_DIR="/usr/local/aep"

DRIVER="paep"
DEVICE_NAME="/dev/paep0"
TARGET_IMAGE="aeptarg.bin"

PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:${PATH}
export PATH

rval=0

#AEPC- Check user is root
if id | grep "uid=0(root)" > /dev/null 2>&1 ; then
	: 
else
	echo "ERROR:   Only root can run this script. "
	exit 1
fi

#AEPC- Check syntax and see how we were called...
case "$1" in
  start)
	if insmod -f ${DRIVER} > /dev/null 2>&1 ; then
	    :
	else
	    echo "ERROR:   Failed to load AEP driver \"${DRIVER}\" ." 
	    exit 1
	fi       

	if [ -n "${TARGET_IMAGE}" ] ; then
		if [ -x "${INSTALL_DIR}/bin/aepload" ] ; then
			if ${INSTALL_DIR}/bin/aepload -device ${DEVICE_NAME} -image ${INSTALL_DIR}/target/${TARGET_IMAGE} > /dev/null 2>&1 ; then
				sleep 5
			else
				echo "ERROR:   Failed to load AEP target image \"${INSTALL_DIR}/target/${TARGET_IMAGE}\" ."
				exit 1
			fi
		else
			echo "ERROR:   AEP Loader \"${INSTALL_DIR}/bin/aepload\" not found."
			exit 1
		fi
	fi

	if aepctrl start > /dev/null 2>&1 ; then
	    exit 0
	else
	    echo "ERROR:   Failed to start AEP daemon." 2>&1
	    exit 1
	fi

        ;;

  stop)

	if aepctrl stop > /dev/null 2>&1 ; then
	    :
	else
	    echo "ERROR:   Failed to stop AEP daemon." 2>&1
	    exit 1
	fi

	if rmmod ${DRIVER} > /dev/null 2>&1 ; then
	    :
	else
	    echo "ERROR:   Failed to unload AEP driver \"${DRIVER}\" ."  
	    rval=1
	fi       
        ;;

  start_msg)
	echo "Loading AEP driver and starting AEP daemon"
	;; 
    
  stop_msg)
	echo "Stopping AEP daemon and unloading AEP driver"
	;;
  *)
        echo "ERROR:    Usage: $0 {start|stop|start_msg|stop_msg}" 
        rval=1
	;;
esac                      

exit $rval

#/*AEPCPB								   	*/
#/* COPYRIGHT (c) 1999-2001 BY ACCELERATED ENCRYPTION PROCESSING LTD (AEP).  	*/
#/* 39/40 UPPER MOUNT STREET,DUBLIN 2,IRELAND				   	*/
#/* ALL RIGHTS RESERVED.						   	*/
#/* THIS SOFTWARE OR DOCUMENTATION IS THE CONFIDENTIAL AND PROPRIETARY  	*/
#/* INFORMATION OF AEP ("CONFIDENTIAL INFORMATION") YOU SHALL NOT DISCLOSE	*/
#/* SUCH CONFIDENTIAL INFORMATION AND SHALL USE IT ONLY IN ACCORDANCE WITH THE  */
#/* TERMS OF WRITTEN LICENCE AGREEMENTS AND/OR NON-DISCLOSURE AGREEMENTS   	*/
#/* ENTERED INTO WITH AEP.						   	*/
#/* AEP PROVIDES NO WARRANTY AS TO THE QUALITY OF THIS SOFTWARE OR		*/
#/* DOCUMENTATION OR ITS SUITABILITY FOR ANY PARTICULAR PURPOSE AND TO THE	*/
#/* EXTENT PERMITTED BY LAW YOU HEREBY WAIVE ANY RIGHTS TO COMPENSATION FOR	*/
#/* DAMAGES WHETHER DIRECT OR CONSEQUENTIAL CAUSED BY THIS SOFTWARE. NO PART	*/
#/* OF THIS SOFTWARE OR DOCUMENTATION MAY BE REPRODUCED; TRANSMITTED;		*/
#/* TRANSCRIBED; STORED IN A RETRIEVAL SYSTEM; OR TRANSLATED INTO ANY		*/
#/* LANGUAGE OR COMPUTER  LANGUAGE IN ANY FORM OR BY ANY MEANS ELECTRONIC;	*/
#/* MECHANICAL; MAGNETIC; OPTICAL; CHEMICAL; MANUAL OR OTHERWISE, EXCEPT IN	*/
#/* ACCORDANCE WITH LICENSE AGREEMENTS YOU HAVE ENTERED INTO, WITHOUT THE 	*/
#/* PRIOR WRITTEN PERMISSION OF AEP.						*/
#/*									  AEPCPE*/

