summaryrefslogtreecommitdiff
path: root/rc/bin/rimport
blob: b09ef8eeb1244de63fd8d6146f2ccf0df9e4bfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/rc
rfork e

argv0=$0
fn usage {
	echo 'usage:' $argv0 '[options] 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