#!/bin/csh 

gm_echo "Installing gm driver."

#gm_echo "ifconfig myri0 down - just in case"
/sbin/ifconfig myri0 down   >& /dev/null
/sbin/ifconfig myri0 abort  >& /dev/null
/sbin/ifconfig myri0 delete >& /dev/null

#to delete the entry
gm_echo "Unloading the driver if it is loaded"
/sbin/sysconfig -u gm >& /dev/null
/sbin/sync

gm_echo "Removing a gm module from sysconfigtab if it exists"
/sbin/sysconfigdb -d gm >& /dev/null
/sbin/sync

/sbin/init.d/autosysconfig delete gm >& /dev/null
/sbin/sync

reenter:
gm_echo " "
gm_echo "Install the GM driver now?"
gm_echo "0) No:  exit script (driver has been unloaded and unconfigured)"
gm_echo "1) Yes: install the driver now"

set COUNT = $<

if ($COUNT == 0) then
	exit
endif

if ($COUNT < 0) then
    gm_echo "Choice '$COUNT' not understood, please type '0' or '1' "
    goto reenter
endif

if ($COUNT > 1) then
    gm_echo "Choice '$COUNT' not understood, please type '0' or '1' "
    goto reenter
endif

if ($COUNT == 1) then
gm_echo "Running /sbin/sysconfigdb to add module"
/sbin/sysconfigdb -a -f sbin/sysconfigtab gm
endif

/sbin/sync

#to delete the entry
#/sbin/sysconfigdb -d gm

gm_echo "Copying gm.mod to /sys/BINARY and linking to /usr/sys/BINARY"
rm -f /usr/sys/BINARY/gm.mod
rm -f /sys/BINARY/gm.mod
rm -f /var/subsys/gm.mod
rm -f /var/subsys/gm.mth

cp -p sbin/gm.mod /sys/BINARY/gm.mod
ln -s /sys/BINARY/gm.mod /usr/sys/BINARY/gm.mod
ln -s /sys/BINARY/gm.mod /var/subsys/gm.mod
ln -s /subsys/device.mth /var/subsys/gm.mth
/sbin/sync
/sbin/init.d/autosysconfig add gm 
/sbin/sync

gm_echo "Installing the module using sysconfig -c"
/sbin/sysconfig -c gm
/sbin/sync

#If sysconfig fails, try this and watch the console
#/sbin/sysconfig -v -c gm


#To unload the driver
#/sbin/sysconfig -u gm

#/sbin/ifconfig myri0 <myri-hostname> netmask <netmask> broadcast <broadcast> up

if (! -f /sbin/init.d/gm_set_permissions ) then
	gm_echo "Installing gm_set_permissions startup script in /sbin/rc3.d"
	cp gm_set_permissions /sbin/init.d/gm_set_permissions
	chmod 700 /sbin/init.d/gm_set_permissions
	( cd /sbin/rc3.d; ln -s ../init.d/gm_set_permissions S99gm_set_permissions)
else
    gm_echo ""
    gm_echo "An existing gm_set_permissions startup script was found. If you have"
    gm_echo "not made local customizations to this script and wish to use the"
    gm_echo "latest version of the script, please manually remove"
    gm_echo "/sbin/init.d/gm_set_permissions and /sbin/rc3.d/S99gm_set_permissions"
    gm_echo "and re-run this installation script."
    gm_echo ""
endif

if ( -f /sbin/rc3.d/S99gm_set_permissions ) then
    /sbin/rc3.d/S99gm_set_permissions start
endif

