#!/bin/sh

fullNameShinc="/cfg/etc/config/mountnfs.shinc"

# Coupled to the operation of mountnfs.shinc.  e.g. Copying of
# 'mountnfs.shinc.onetime' is handled there.
#
# Ken Bertelson June, 2015

rebooting()
{
    echo "Rebooting MC into ARM Debugging mode using NFS..."
    reboot
    exit
}

# If no argument, see if we can use the existing *.onetime file
if [ -z "$1" ]; then

    [ -e $fullNameShinc.onetime ] && mv -f $fullNameShinc.onetime $fullNameShinc

    [ -e $fullNameShinc ] && rebooting

    echo "You need to run this script one-time with a single argument."
    echo "The argument must specify your unique NFS mount point"
    echo "Example:  10.134.16.10:/home/kbertels/src/red/build_GLM200_arm-none-linux-gnueabi"
    exit 1
fi

# show current NFS mount point -- if it is in place
if [ "$1" == "--list" ]; then
    head -n 2 $fullNameShinc.onetime
    exit
fi

# If script has an argument, create a new mountnfs.shinc based on it

echo "nfsFullPath=\"$1\"" > $fullNameShinc
AbsPath=$(readlink -f "${0%/*}")
cat $AbsPath/mountnfs.shinc >> $fullNameShinc
rebooting

