#! /bin/sh
#
# This script takes a list of hosts and starts the servers on those machines
# It can handle a "hosts" file as long as the entries are sorted.
if [ $1 = "-help" ] ; then 
    echo "$0 - start the pvm daemon on the specified nodes"
    echo "$0 hostfile"
    exit
fi

# Get the list of available hosts
SERVERDIR="/home/gropp/pvm/src"
echo $SERVERDIR | \
    awk '{if (NR == 1) {
             SERVR = $1
             }
          else {
	     if (substr($1,1,1) != "#") {
                 if (V != $1) {
		     ARCH = $2
		     if (ARCH == "sun4") ARCH="SUN4"
		     else if (ARCH == "rs6000") ARCH="RIOS"
		     else if (ARCH == "IRIX")   ARCH="SGI"
		     else if (ARCH == "next")   ARCH="NEXT"
		     else next
                     printf("%s dx=%s/%s/pvmd\n",$1,SERVR,ARCH);
                     }
	         V = $1
		 }
             }
          }' - $1 > .tmp
# A complication is that the first node needs to be the local node
# Try to find that one and move it to the front.
echo `hostname` | \
    awk '{if (NR == 1) hostname = $1
	  else {
	      if ($1 != hostname) print $0
              }
	  }' - .tmp > .tmp2
echo `hostname` | \
    awk '{if (NR == 1) hostname = $1
	 else {
	      if ($1 == hostname) {
	            print $0
	            exit
		    }
	       }
	  }' - .tmp > .tmp3
cat .tmp3 .tmp2 > .tmp
/bin/rm -f .tmp[123]
# 
# This isn't quite correct; the architecture needs to be that of 
# the local host.
$SERVERDIR/SUN4/pvmd .tmp &
