shithub: sirjofri_de

ref: 3805c2b34bf8671de0626a55ca4e5c17251eea5d
dir: /pub/files/guidedreplica/guidedreplica.rc/

View raw version
#!/bin/rc

echo Make sure that:
echo '  - server home is mounted at /n/rserver'
echo '  - client home is mounted at /n/rclient'
echo you can do that with bind/rimport, e. g.
echo '  bind $home /n/rclient'
echo '  rimport $servername $home /n/rserver'
echo
echo Abort now if you still need to do that! '(Del/Enter)'
read

while(~ $#servername 0 || ~ $servername ''){
	echo Enter your server name '(ndb compatible).'
	echo -n 'servername (no default): '
	servername=`{read}
}

if(~ $#helperscripts 0 || ~ $helperscripts ''){
	echo Enter the path to the helper scripts.
	echo These helper scripts can help you using replica.
	echo -n 'helperscripts ($home/bin/rc/replica): '
	helperscripts=`{read}
	if(~ $#helperscripts 0 || ~ $helperscripts '')
		helperscripts=$home/bin/rc/replica
}

servicefile='servername='^$servername^'

fn servermount{
	echo servermount $sysname
	if(~ $sysname $servername)
		bind / /n/rserver
	if not
		rimport $servername / /n/rserver
}
fn serverupdate{
	echo serverupdate $sysname
	if(~ $sysname $servername)
		replica/scan -v $servername
	if not
		rcpu -h $servername -c replica/scan -v $servername
}
serverroot=/n/rserver
s=/n/rserver/lib/rep
serverlog=$s/server.log
serverproto=$s/server.proto
serverdb=$s/server.db

fn clientmount{
	echo clientmount $sysname
	if(~ $sysname $servername)
		bind /mnt/term/usr/$user /n/rclient
	if not
		bind / /n/rclient
}
clientroot=/n/rclient
c=/n/rclient/lib/rep
clientlog=$c/client.log
clientproto=$c/client.proto
clientdb=$c/client.db
clientexclude=()'

creplica=/n/rclient/lib/replica
crep=/n/rclient/lib/rep
sreplica=/n/rserver/lib/replica
srep=/n/rserver/lib/rep

mkdir -p $creplica
mkdir -p $crep
mkdir -p $sreplica
mkdir -p $srep

echo $servicefile > $creplica/$servername
echo $servicefile > $sreplica/$servername

echo
echo Created files
echo '    ' $creplica/$servername
echo ' and' $sreplica/$servername
echo please adjust them and make sure that they are the same.

touch $crep/^(client.proto client.log client.db)
touch $srep/^(server.proto server.log server.db)

# install helperscripts
mkdir -p $helperscripts

echo '#!/bin/rc

fn usage{
	echo ''usage: reproto -s|-c server'' >[1=2]
	exit ''usage''
}

if(! ~ $#* 2)
	usage

if(! test -r $home/lib/replica/$2)
	usage

. $home/lib/replica/$2

clientmount
servermount

switch($1){
case -c
{
	echo using client proto
	cp $clientproto $serverproto
}
case -s
{
	echo using server proto
	cp $serverproto $clientproto
}
case *
	usage
}' >$helperscripts/reproto

echo '#!/bin/rc

fn usage{
	echo ''usage: reupdate server file...'' >[1=2]
	exit ''usage''
}

if(test $#* -lt 2)
	usage

server=$1

rfork
ramfs

nl=''
''

. /usr/$user/lib/replica/$server

servermount
clientmount

shift

todelete=''''

while(! ~ $#* 0){
	todelete=$todelete^''s:''^$1^'':########:g;''

	shift
}

todelete=$todelete^''/########/d''

userverdb=`{
	basename -d $serverdb | tr -d $nl
	echo -n /_
	basename $serverdb | tr -d $nl
}

sed $todelete $clientlog > /tmp/clientlog
sed $todelete $clientdb > /tmp/clientdb
sed $todelete $serverlog > /tmp/serverlog
sed $todelete $serverdb >/tmp/serverdb
sed $todelete $userverdb >/tmp/userverdb
cp /tmp/clientlog $clientlog
cp /tmp/clientdb $clientdb
cp /tmp/serverlog $serverlog
cp /tmp/serverdb $serverdb
cp /tmp/userverdb $userverdb

echo replica/push $server' >$helperscripts/reupdate

# clean up
rm /env/servername /env/helperscripts