Plan 9 from Bell Labs’s /usr/web/sources/contrib/rminnich/package/bin/rc/pull

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork ne
path=/bin

fn fatal {
	echo $*
	exit $"*
}

fn must {
	$* || fatal $"*^': '^$status
}

flags=()
force=false
while (~ $1 -*) {
	switch ($1) {
	case -f
		force=true
	case -s -c
		flags=($flags $1 $2)
		shift
	case -*
		usage
	}
	shift
}

if (! ~ $#* 1)
	fatal 'usage: contrib/pull [-c file] [-s file] name' >[1=2]

#remove "user" from "user/replica"
name=`{basename $1}
repl=/dist/replica/$name
if (! test -x $repl)
	fatal no such replica: $name

. $repl

# set this here as we redefine s when we compare sizes
if (~ $#serverchg 0) {
	serverchg=$s/$name/chg
	clientchg=$c/client/$name.chg
}
if (~ $#serveriso 0)
	serveriso=$s/$name/iso.bz2

must servermount

# check if we are updated
if (~ $force false && cmp $clientlog $serverlog >/dev/null >[2=1] ) {
	exit ''
}

# check changes
if ( test -e $serverchg) {
	n=`{ls -l $clientchg >[2]/dev/null |awk '{print $6}'}
	s=`{ls -l $serverchg >[2]/dev/null |awk '{print $6}'}
	if (~ $n 0 || ~ $#n 0 || test $s -lt $n) {
		must fcp $serverchg $clientchg
		cat $clientchg
	}
	if not {
		m=`{echo $n-1024 | hoc}
		if(~ $m -*)
			m=0
		cmp -s $serverchg $clientchg $m $m
		x=$status
		switch($x){
		case *': EOF'
			tail +^$n^c $serverchg >>$clientchg
			tail +^$n^c $clientchg
		case *': differ'
			fcp $serverchg $clientchg
			cat $clientchg
		}
	}
}

# if the iso exists override some variables
# and mount it so we can pull from there
clientiso=/tmp/$name.iso
if (test -e $serveriso) {
	must fcp $serveriso $clientiso.bz2
	must bunzip2  < $clientiso.bz2 > $clientiso
	rm -f $clientiso.bz2
	must 9660srv  9660.$name
	must mount -c /srv/9660.$name /n/dist $clientiso
	serverroot=/n/dist
	serverlog=/n/dist/$name.log
}

# download the log
n=`{ls -l $clientlog >[2]/dev/null |awk '{print $6}'}
s=`{ls -l $serverlog >[2]/dev/null |awk '{print $6}'}
if(~ $n 0 || ~ $#n 0 || test $s -lt $n){
	if(test -e $clientlog) must rm $clientlog
	must fcp $serverlog $clientlog
}
if not{
	m=`{echo $n-1024 | hoc}
	if(~ $m -*)
		m=0
	cmp -s $serverlog $clientlog $m $m
	x=$status
	switch($x){
	case *': EOF'
		must tail +^$n^c $serverlog >>$clientlog
	case *': differ'
		must rm $clientlog
		must fcp $serverlog $clientlog
	case ''
		;
	case *
		fatal cmp: $x
	}
}

# normally we'd do this after applylog, but we want
# applylog to be the last thing in this script, so we'll
# do it here instead, compacting changes from the
# _last_ applylog.
ndb=`{echo $clientdb | sed 's;(.*)/(.*);\1/_\2;'}
must replica/compactdb $clientdb >$ndb
mv $ndb $clientdb

# now call applylog
replica/applylog -v $flags $clientdb $clientroot $serverroot <$clientlog
unmount /n/dist >/dev/null >[2=1]
rm -f  /srv/9660.$name 
rm -f $clientiso

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.