#! /bin/sh
#
# Install script for the ch_p4mpd 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
    (cd mpid/mpd ; $MAKE install UNINSTALLFILE=$UNINSTALLFILE DESTDIR=$DESTDIR )
    rm -f $DESTDIR${bindir}/mpichboot
    cat >$DESTDIR${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 $DESTDIR${bindir}/mpichboot
    echo "rm -f ${bindir}/mpichboot" >>$UNINSTALLFILE
    rm -f $DESTDIR${bindir}/mpichstop
    cat >$DESTDIR${bindir}/mpichstop <<EOF
#! /bin/sh
${bindir}/mpdallexit
EOF
    chmod $XMODE $DESTDIR${bindir}/mpichstop
    echo "rm -f ${bindir}/mpichstop" >>$UNINSTALLFILE
else
    echo "Could not find Makefile for mpid/mpd!"
    echo "Install not completed"
    exit 1
fi
#
