ref: 9c704c0dff7b774d613448e51cc6e7d01004b5d3
parent: 38171a269fe92f773d9cffea1e1cb879b239260e
author: sirjofri <sirjofri@sirjofri.de>
date: Wed Jul 1 12:42:14 EDT 2020
adds guidedreplica files
--- /dev/null
+++ b/pub/files/guidedreplica/README
@@ -1,0 +1,7 @@
+USAGE
+
+Bind your server $home to /n/rserver and your client $home to
+/n/rclient. Then run guidedreplica.rc
+
+Enter your servername (name only, no port). If you need to make
+deeper adjustments do that after the script finishes.
--- /dev/null
+++ b/pub/files/guidedreplica/guidedreplica.rc
@@ -1,0 +1,177 @@
+#!/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