#!/bin/csh 

echo "Installing gm driver."

#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
echo "Unloading the driver if it is loaded"
/sbin/sysconfig -u gm >& /dev/null
/sbin/sync

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:
echo " "
echo "Choose the type of Myrinet board you have installed."
echo "1) PCI64A (or newer)"
echo "2) PCI32 or PCI64 (older cards)" 
echo "0) exit script (driver has been unloaded and unconfigured)"
set COUNT = $<

if ($COUNT == 0) then
	exit
endif

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

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

if ($COUNT == 2) then
echo "Running /sbin/sysconfigdb to add module (for PCI32 and PCI64 Myrinet cards)"
/sbin/sysconfigdb -a -f sbin/sysconfigtab gm
endif

if ($COUNT == 1) then
echo "Running /sbin/sysconfigdb to add module (for PCI64A Myrinet cards)"
/sbin/sysconfigdb -a -f sbin/sysconfigtab-pci64 gm
endif

/sbin/sync

#to delete the entry
#/sbin/sysconfigdb -d 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

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

