#!/bin/sh
#
#  createshared owner filename [client...]
#
#  Creates empty files in the client root partitions of a Sun disk server
#  for later installation of x-kernels by "owner".  When possible, files
#  are shared among the client partitions using (hard) links.
#
#  If no client is named, all files in /export/root are taken as client names.
#
#  This script must be run as root on the disk server.
#
#  We set protection modes to 700, but of course the owner can relax those.

if [ `whoami` != root ]
then
    echo "$0: must be run by root" 1>&2
    exit 1
fi

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


OWNER=$1
FILE=$2
shift
shift

cd /export/root

if [ $# = 0 ]
then
    set `ls`
fi


MADE=
for i
do
    rm -f $i/$FILE
    for j in $MADE
    do
	if ln $j/$FILE $i/$FILE 2>/dev/null
	then
	    echo linking $i/$FILE to $j/$FILE
	    continue 2
	fi
    done
    echo creating $i/$FILE
    cp /dev/null $i/$FILE
    chown $OWNER $i/$FILE
    chmod 700    $i/$FILE
    MADE="$MADE $i"
done
