shithub: riscv

ref: 7f8246fd97a12477f9dd21c68a3d81b4c4b46852
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] [-t timeout] 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 -[ukt]; 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 && echo $1'=()' ||
			path=/dev/null builtin whatis $1
		shift
	}
}

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