shithub: riscv

ref: e01577f8f61023ab90d8022e75cb00027399428c
dir: /rc/bin/rimport/

View raw version
#!/bin/rc
rfork e

argv0=$0
fn usage {
	echo 'usage:' $argv0 '[-abcCnq] [-s name] [-u user] [-k keypattern] [-p] host tree [mountpoint]' >[1=2]
	exit 'usage'
}

fn domount {
	if(~ $#sname 1){
		rm -f /srv/$sname
		echo -n 0 >/srv/$sname
	}
	~ $#mtpt 0 || mount -n $mopt /fd/0 $mtpt
}

tree=()
mopt=()
mtpt=()
sname=()
exportfs=/bin/exportfs
connect=/bin/rconnect

while(~ $1 -*){
	switch($1){
	case -p; connect=($connect $1)
	case -[abcCnq]*; mopt=($mopt $1)
	case *
		~ $#* 1 && usage
		switch($1){
		case -[uk]; connect=($connect $1 $2)
		case -s; sname=`{basename $2}
		case *; usage
		}
		shift
	}
	shift
}
switch($#*){
case 2 3; tree=$2; mtpt=$$#*
case *; usage
}

fn pvar {
	while(! ~ $#* 0){
		~ $#$1 0 || path=/dev/null builtin whatis $1
		shift
	}
}

exec $connect $1 <{pvar tree; echo exec $exportfs -r '$tree'} domount