#!/bin/sh
#
#  usage:  installboot destname host...
#
#  Installs an x-kernel by copying it to one or more destinations.
#
#  The source file is ./xkernel
#  The destination is /destname on each of the listed hosts.

if [ $# -lt 2 ]
then
    echo "usage: $0 destname host..." 1>&2
    exit 1
fi

CONFIG=`echo $0 | sed 's=/bin/[^/]*$=/etc/servers='`

SOURCE=./xkernel
TARGET=/xk/$1
shift

for HOST
do
    if SERVER=`awk <$CONFIG "
	/^#/	{ next; }
	NF > 1	{ for (i=2; i<=NF; i++)
			if (\\$i == \"$HOST\") {
				print \\$1;
				exit 1;
			}
		}
    "`
    then
	# no server
	DEST=$HOST:$TARGET
    else
	# served by $SERVER
	DEST=$SERVER:/export/root/$HOST$TARGET
	HOST=$SERVER
    fi
    echo "    copying $SOURCE to $DEST"
    rcp $SOURCE $DEST
    rsh -n $HOST sync
done
