#! /bin/sh
#
# Install script for the ch_gm (mpd) device
# This script is called by mpiinstall to install the device.
# It should add commands to the file named by UNINSTALLFILE to remove
# any file that it adds.  It creates the mpichboot and mpichstop scripts
if [ -z "$MAKE" -o -z "$XMODE" ] ; then
    echo "This script must be invoked from mpiinstall"
    exit 1
fi
if [ -f mpid/mpd/Makefile ] ; then
    export XMODE
    cp ${bindir}/mpirun ${bindir}/mpirun.save
    (cd mpid/mpd ; $MAKE install UNINSTALLFILE=$UNINSTALLFILE )
    rm -f ${bindir}/mpirun
    cp ${bindir}/mpirun.save ${bindir}/mpirun
    rm -f ${bindir}/mpichboot
    cat >${bindir}/mpichboot <<EOF
#! /bin/sh
if [ ! -s $HOME/.mpdpasswd -a ! -s $HOME/.mpd.conf ] ; then
    echo "In mpichboot:"
    echo "A .mpd.conf file is required before starting an mpd demon."
    echo "See the documentation on mpd in the User Manual."
    exit 1
fi
# Use the -b option to force mpd into the background, orphaned from the 
# calling process.  
${bindir}/mpd -b &
EOF
    chmod $XMODE ${bindir}/mpichboot
    echo "rm -f ${bindir}/mpichboot" >>$UNINSTALLFILE
    rm -f ${bindir}/mpichstop
    cat >${bindir}/mpichstop <<EOF
#! /bin/sh
${bindir}/mpdallexit
EOF
    chmod $XMODE ${bindir}/mpichstop
    echo "rm -f ${bindir}/mpichstop" >>$UNINSTALLFILE
else
    echo "Could not find Makefile for mpid/mpd!"
    echo "Install not completed"
    exit 1
fi
#
