#!/bin/sh

#
# build-dqsx-install: install DQS XSRC on a set of hosts
#
# NOTE: Modify the block of definitions just below.
#
# -kk6/24/94 9:13am. snarfed some of this from X11R5's xrsh
#

# !!! Modify these definitions to suit yourself !!!
XSRCDIR=${HOME}/DQS/XSRC
CONFIGSDIR=${HOME}/lib/build-dqsx-Configs
# tmpdir should be a directory that's accessible to all the hosts via NFS --
# temporary compilation files shall be put here...
tmpdir=$rootdir/tmp

PROGNAME=`basename $0`

if [ $# -gt 1 ]; then
  echo Usage: $PROGNAME ConfigFileName
  echo where: ConfigFileName is the config file in the directory \"$CONFIGSDIR\" \(.dat extension will be appended automatically\)
  exit 1
fi

if [ $# -gt 0 ]; then
  CONFIGFILE=$1
else
  echo $PROGNAME: must supply ConfigFileName parameter
  exit 1
fi

# Some System V hosts have rsh as "restricted shell" and ucb rsh is remsh
if [ -r /usr/bin/remsh ]; then
  rsh=remsh
elif [ -f /usr/bin/rcmd ]; then       # SCO Unix uses "rcmd" instead of rsh
  rsh=rcmd
else
  rsh=rsh
fi

cat $CONFIGSDIR/$CONFIGFILE.dat | \
(while read HOST CONFIG CONFIGNOIMAKE ARCHITECTURE EXECPATH ACTUALDIR; do

  # skip commented lines
  if echo $HOST | grep '^#' > /dev/null; then
    continue
  fi

  echo $HOST $CONFIG $CONFIGNOIMAKE $ARCHITECTURE $EXECPATH $ACTUALDIR

  BUILDDIRNAME=$CONFIG:$CONFIGNOIMAKE

  FILENAMESUFFIX="$HOST.`date | sed 's/ /-/g'`"
  MAKELOGFILENAME="Make.log.install.$FILENAMESUFFIX"
  PIDFILENAME="Pid.install.$FILENAMESUFFIX"

  $rsh $HOST " ( cd $XSRCDIR/$BUILDDIRNAME; \
                 setenv PATH $EXECPATH; \
                 date >>& $MAKELOGFILENAME; \
                 make install >>& $MAKELOGFILENAME; \
                 date >>& $MAKELOGFILENAME ) \
                   < /dev/null > /dev/null & " \
    < /dev/null > $XSRCDIR/$BUILDDIRNAME/$PIDFILENAME &

done)

exit 0
