#!/bin/sh
#
# picdrv:   This shell script takes care of starting and stopping
#		the ICEPIC driver
#
#	for 64 bit kernels, set b64=1, else b64=0
#
KDIR="/usr/kernel"
module="icepic"
device="icepic"
devnos="0 1 2 3 4 5 6 7 8 9 10 11"
group="sys"
mode="666"
b64=0

case "$1" in
  make)
	# compile files
#	if [ $b64 != 0 ]; then
#	  /usr/ccs/bin/cc -I../../inc -I/usr/conf/h \
#		-w -D_KERNEL_BUILD -DKERNEL  -D__ROSE__ -DVARIABLE_UAREA \
#		-DSTCP -DPGPROF -DLWSYSCALL   -DIVT_INTERCEPT -DIPSEC \
#		-DIDDS -DHPONCPLUS -DAUDIT -DACLS    -D__STDC_EXT__ \
#		-D__NO_PA_HDRS -D_XPG4_EXTENDED -D_UNSUPPORTED   \
#		-D_SYSCALL_64 -D_KERNEL -D_HPUX_SOURCE -D_CLEAN_BE \
#		-DKERNEL_DEBUGGER     -U__hp9000s700   -I/usr/conf -I. \
#		-Wp,-H300000  +kernel    +DD64  -c -o mod.o  picdrv.c
#	else
	  /opt/ansic/bin/cc +legacy_hpc -Ae -I../../inc -I/usr/conf/h \
		-w -D_KERNEL_BUILD -DKERNEL  -D__ROSE__ -DVARIABLE_UAREA \
		-DSTCP -DPGPROF -DLWSYSCALL   -DIVT_INTERCEPT -DIPSEC \
		-DIDDS -DHPONCPLUS -DAUDIT -DACLS    -D__STDC_EXT__ \
		-D__NO_PA_HDRS -D_XPG4_EXTENDED -D_UNSUPPORTED   \
		-D_SYSCALL_64 -D_KERNEL -D_HPUX_SOURCE -D_CLEAN_BE \
		-DKERNEL_DEBUGGER     -U__hp9000s700   -I/usr/conf -I. \
		+ES1.Xindirect_calls \
		-Wp,-H300000  +kernel    +DD64  -c -o mod.o  picdrv.c
#	fi
	;;
  install)
	# copy to the system area
	/usr/sbin/kminstall -a icepic
	/usr/sbin/kmsystem -c Y -l Y icepic
	/usr/sbin/config -M icepic -u

	#Add module name "icepic" to /etc/loadmods
	if [ ! -e /etc/loadmods ]; then
	  echo "icepic" > /etc/loadmods
	else
	  grep -q icepic /etc/loadmods
	  if [ $? -eq 1 ]; then
	    echo "icepic" >> /etc/loadmods
	  fi
	fi
	;;
  remove)
	# remove from the system area - also removes from /etc/loadmods
	/usr/sbin/kminstall -d icepic
	# remove stale nodes
	rm -f /dev/${device}[0-9]
	rm -f /dev/${device}1[0-9]
	;;
  start)
	# load driver module
	/usr/sbin/kmadmin -L icepic
	major=`/usr/sbin/lsdev -h -d icepic | awk '{print $1}'`
        # create new nodes
        if [ "$major" = "" ]; then
          echo "No icepic driver found"
        else
          for i in $devnos
          do
            mknod /dev/${device}${i} c $major $i
          done
          chgrp $group /dev/${device}?
          chmod $mode /dev/${device}?
        fi
	# Force a rescan of the bus for ICEPICs
	/usr/sbin/ioscan -d icepic
	;;
  stop)
	# unload driver module
	/usr/sbin/kmadmin -U icepic

        # remove stale nodes
        rm -f /dev/${device}[0-9]
        rm -f /dev/${device}1[0-1]
	;;
  restart)
	$0 stop
	$0 start
	;;
  status)
	/usr/sbin/kmadmin -Q icepic
        ;;
  *)
	echo "Usage: icepic {make|install|remove|start|stop|restart|status}"
	exit 1
esac

exit 0
