#!/bin/rc rfork ne path=/bin fn fatal { echo $* exit $"* } fn usage { echo 'usage: contrib/create [-d depend] [-f] [-m] [-r root] [-u user] [-x file] name proto' >[1=2] exit usage } root=/ usr=$user force=false master=false exclude=() depend=() while (~ $1 -*) { switch ($1) { case -d depend=($depend $2) shift case -f force=true case -m master=true case -r root=$2 shift case -u usr=$2 shift case -x exclude=($exclude `{cleanname -d `{pwd} $2}) shift case -* usage } shift } if (! ~ $#* 2) usage repl=$home/lib/replica # setup dirs if(! test -d $repl) mkdir -p $repl for(i in cfg db log) { if(! test -d $repl/$i) mkdir -p $repl/$i } name=$1 proto=`{cleanname -d `{pwd} $2} if (! test -f $proto) fatal cannot find proto: $proto cfg=$repl/cfg/$name if (test -x $cfg && ~ $force false) fatal name conflict: replica $name already exists. if (~ $master true && ! test -x /dist/replica/$name) fatal cannot master $name is not installed contrib=/n/sources/contrib/$usr x='$' cat > $cfg < $repl/db/$name > $repl/log/$name if (~ $master true) { cp /dist/replica/client/$name.log $repl/log/$name cp /dist/replica/client/$name.db $repl/db/$name exit '' } . $cfg servermount || fatal cant mount server mkdir -p $contrib/root mkdir -p $contrib/replica mkdir -p $contrib/replica/$name > $serverdb > $serverlog > $serverdep > $serverchg for (i in $clientdepend) echo $i >> $serverdep if (test -w /dev/consctl) { >/dev/consctl { echo holdon cat >$serverinf } } if not cat >$serverinf exec contrib/push $name