summaryrefslogtreecommitdiff
path: root/rc/bin/rimport
blob: a55f2079dea21828d8e58f2b00de54994cd4ccc0 (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
53
#!/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