]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/rimport
merge
[plan9front.git] / rc / bin / rimport
1 #!/bin/rc
2 rfork e
3
4 argv0=$0
5 fn usage {
6         echo 'usage:' $argv0 '[-abcCnq] [-s name] [-u user] [-k keypattern] [-p] [-t timeout] host tree [mountpoint]' >[1=2]
7         exit 'usage'
8 }
9
10 fn domount {
11         if(~ $#sname 1){
12                 rm -f /srv/$sname
13                 echo -n 0 >/srv/$sname
14         }
15         ~ $#mtpt 0 || mount -n $mopt /fd/0 $mtpt
16 }
17
18 tree=()
19 mopt=()
20 mtpt=()
21 sname=()
22 exportfs=/bin/exportfs
23 connect=/bin/rconnect
24
25 while(~ $1 -*){
26         switch($1){
27         case -p; connect=($connect $1)
28         case -[abcCnq]*; mopt=($mopt $1)
29         case *
30                 ~ $#* 1 && usage
31                 switch($1){
32                 case -[ukt]; connect=($connect $1 $2)
33                 case -s; sname=`{basename $2}
34                 case *; usage
35                 }
36                 shift
37         }
38         shift
39 }
40 switch($#*){
41 case 2 3; tree=$2; mtpt=$$#*
42 case *; usage
43 }
44
45 fn pvar {
46         while(! ~ $#* 0){
47                 ~ $#$1 0 && echo $1'=()' ||
48                         path=/dev/null builtin whatis $1
49                 shift
50         }
51 }
52
53 exec $connect $1 <{pvar tree; echo exec $exportfs -r '$tree'} domount