#! /bin/sh

gm_echo "**************************************************"
gm_echo "Begin GM_INSTALL "`date`
gm_echo "Installing from "`pwd`
gm_echo "**************************************************"
gm_echo "Beginning one-time installation steps."
gm_echo "**************************************************"
gm_echo "This script makes the following assumptions:"
gm_echo "- superuser privileges (because subdirectories will be created in /usr/)"
gm_echo "- GM build has completed successfully"
gm_echo "- current working directory is the binary subdirectory of the GM source tree"

gm_echo "Creating myricom software directory /usr/myricom/."
gm_echo "Should fail harmlessly if it already exists."
mkdir /usr/myricom
mkdir /usr/myricom/lib64

gm_echo "Creating device names in /dev/."
gm_echo "The following ln commands will fail if the links already exist."
gm_echo "This is OK, provided the existing links are correct."
ln -s /hw/gm0 /dev/gm0
ln -s /hw/gm1 /dev/gm1
ln -s /hw/gm2 /dev/gm2
ln -s /hw/gm3 /dev/gm3
ln -s /hw/gmp0 /dev/gmp0
ln -s /hw/gmp1 /dev/gmp1
ln -s /hw/gmp2 /dev/gmp2
ln -s /hw/gmp3 /dev/gmp3
# Add more 'ln' statements if you will have Myrinet cards with unit
# numbers greater than 3.

ls -l /dev/gm*

gm_echo "Installing configuration files in /var/sysgen/master.d, /var/sysgen/ioconfig,"
gm_echo "/var/sysgen/system, /etc/init.d, and /etc/config"
cp -p var/sysgen/master.d/myrigm        /var/sysgen/master.d/myrigm
cp -p var/sysgen/ioconfig/myrigm        /var/sysgen/ioconfig/myrigm
cp -p var/sysgen/system/myrigm.sm       /var/sysgen/system/myrigm.sm
cp -p etc/init.d/myrinet                /etc/init.d/myrinet
cp -p etc/config/myrinet_mapper         /etc/config/myrinet_mapper
cp -p etc/config/myrinet_mapper.options /etc/config/myrinet_mapper.options

gm_echo "**************************************************"
gm_echo "Beginning installation steps that are needed after every build."
gm_echo "**************************************************"

gm_echo "Installing GM driver as /var/sysgen/boot/myrigm.o."
cp -i -p var/sysgen/boot/myrigm.o /var/sysgen/boot/myrigm.o
ls -l /var/sysgen/boot/myrigm.o

gm_echo "Installing mapper, test programs, et al. in /usr/myricom/."
cp -pr GM_INSTALL bin doc etc include info lib sbin var /usr/myricom
mkdir /usr/myricom/etc/rc2.d
ln -s /usr/myricom/etc/init.d/myrinet /usr/myricom/etc/rc2.d/S99myrinet
cp -pr lib/* /usr/myricom/lib64

ls -lFAR /usr/myricom

gm_echo "NOTE: ml load or reboot needed to load and attach GM."
gm_echo "NOTE: ifconfig command was not issued -- issue it manually if desired."

gm_echo "**************************************************"
gm_echo "End GM_INSTALL "`date`
gm_echo "**************************************************"
