]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/boot/net.rc
audiohda: fix syntax error
[plan9front.git] / sys / src / 9 / boot / net.rc
1 #!/bin/rc
2
3 fn confignet{
4         # get primary default interface if not specified
5         if(~ $#* 0){
6                 e=/net/ether*
7                 if(! ~ $e '/net/ether*')
8                         *=(ether $e(1))
9         }
10
11         # setup wifi encryption if any
12         if(~ $1 ether && test -x /bin/aux/wpa){
13                 essid=`{grep '^essid: ' $2/ifstats >[2]/dev/null | sed 's/^essid: //; q'}
14                 if(! ~ $#essid 0){
15                         if(! ~ $#wpapsk 0 || grep -s '^status: need authentication' $2/ifstats >[2]/dev/null){
16                                 x=(aux/wpa -s $"essid)
17                                 if(! ~ $#wpapsk 0){
18                                         echo 'key proto=wpapsk' `{!password=$"wpapsk whatis essid !password} > /mnt/factotum/ctl
19                                         wpapsk=()
20                                 }
21                                 if not {
22                                         x=($x -p)               
23                                 }
24                                 $x $2
25                         }
26                         essid=()
27                 }
28                 rm -f /env/^(essid wpapsk)
29         }
30
31         if(~ $1 ether gbe && ~ $#* 2) @{
32                 ip/ipconfig -6 $*
33                 test -e /env/nora6 || ip/ipconfig $* ra6 recvra 1 &
34                 ip/ipconfig -p $* &
35                 wait
36         }
37         if not {
38                 ip/ipconfig -p $*
39         }
40
41         if(~ $#fs 0)
42                 fs=`{awk -F'=' '/^[     ]*fs=/{print $2}' /net/ndb}
43         if(~ $#auth 0)
44                 auth=`{awk -F'=' '/^[   ]*auth=/{print $2}' /net/ndb}
45         if(~ $#fs 0)
46                 ask fs ' address is? ' $auth(1)
47         if(~ $#auth 0)
48                 ask auth ' address is? ' $fs(1)
49
50         # resolve dns names
51         if(test -x /bin/ndb/dnsgetip){
52                 for(i in fs auth secstore){
53                         x=`{for(x in $$i) ndb/dnsgetip -a $x}
54                         ~ $#x 0 || $i=$x
55                 }
56         }
57
58         # publish info in /net/ndb for factotum
59         >> /net/ndb {
60                 echo
61                 echo 'ipbootinfo='
62                 for(i in $fs)   echo '  fs='^$i
63                 for(i in $auth) echo '  auth='^$i
64         } 
65 }
66
67 fn connecttcp{
68         while(! ~ $#fs 0 && ! srv -q tcp!$fs(1)^!564 boot)
69                 fs=$fs(2-);
70         fs=$fs(1)
71 }
72
73 fn connecttls{
74         while(! ~ $#fs 0 && ! srvtls -q tcp!$fs(1)^!17020 boot)
75                 fs=$fs(2-);
76         fs=$fs(1)
77 }
78
79 fn connectil{
80         while(! ~ $#fs 0 && ! srv -q il!$fs(1)^!17008 boot)
81                 fs=$fs(2-);
82         fs=$fs(1)
83 }
84
85 mtcp=(confignet connecttcp)
86 mtls=(confignet connecttls)
87 mil=(confignet connectil)
88
89 mt=(mtcp mtls mil $mt)