]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/boot/bootrc
bind devshr to /shr
[plan9front.git] / sys / src / 9 / boot / bootrc
1 #!/bin/rc
2
3 mntgen -s slash /mnt
4 bind /root /mnt/broot
5 unmount /root
6
7 bind -q '#p' /proc
8 for(i in S f k æ t m)
9         bind -a '#'^$i /dev >/dev/null >[2=1]
10
11 # make variables settable by copying them from #ec
12 for(i in init service sysname user nvram rootdir cfs bootdisk bootargs \
13         nobootprompt debugfactotum fs fsaddr auth authaddr){
14         a=$$i
15         $i=()
16         rm -f '#e'/$i '#ec'/$i /env/$i
17         if(! ~ $#a 0)
18                 $i=$a
19 }
20
21 fn fatal {
22         echo $*
23         exit $"*
24 }
25
26 fn must {
27         $* || fatal $"*^': '^$status
28 }
29
30 fn ask {
31         echo -n $1
32         echo -n $2
33         if(! ~ $#3 0){
34                 echo -n ' ['
35                 echo -n $3
36                 echo -n '] '
37         }
38         $1=`{dd -bs 64 -count 1 >[2]/dev/null}
39         if(~ $#$1 0)
40                 $1=$3
41         if(~ $"$1 '!rc'){
42                 rc -i
43                 $1=()
44         }
45         if(~ $#$1 0)
46                 ask $*
47 }
48
49 mt=()
50 . /rc/lib/tcp.rc
51 . /rc/lib/local.rc
52
53 fn main{
54         mp=()
55         while(~ $#mp 0){
56                 if(~ $#nobootprompt 0){
57                         echo
58                         showlocaldevs
59                         ask bootargs ' is (tcp, local!device)' $bootargs
60                 }
61                 if not bootargs=$nobootprompt
62                 nobootprompt=()
63                 mn=`{echo $bootargs | awk -F! '{print $1}'}
64                 ma=`{echo $bootargs | sed 's/[^!]*!?//'}
65                 switch(m$"mn){
66                 case $mt
67                         mp=m$mn
68                         mp=$$mp
69                 }
70         }
71
72         # config method
73         $mp(1) $ma
74
75         # authentication agent
76         if(! test -f /srv/factotum){
77                 x=(/boot/factotum -sfactotum)
78                 if(~ $service cpu){
79                         x=($x -S)
80                         if(~ -k $ff)
81                                 x=($x -k)
82                 }
83                 if not
84                         x=($x -u)
85                 if(! ~ $#authaddr 0)
86                         x=($x -a $authaddr)
87                 if(! ~ $#debugfactotum 0)
88                         x=($x -p)
89                 must $x
90         }
91         if not user=`{cat /dev/hostowner}
92
93         # connect method
94         $mp(2) $ma
95
96         # insert cfs in the pipeline
97         if(test -x /bin/cfs){
98                 if(~ $#bootdisk 1 && ~ $#cfs 0)
99                         cfs=$bootdisk/cache
100                 if(~ $#cfs 1 && ! ~ $cfs off && test -f $cfs){
101                         x=(/bin/cfs -s -f $cfs)
102                         if(~ -f $ff)
103                                 x=($x -r)
104                         {$x </srv/boot &} | echo 0 >/srv/cfs
105                         rm /srv/boot
106                         mv /srv/cfs /srv/boot
107                 }
108         }
109
110         # mount and change root in new enviroment and namespace
111         rfork ne
112
113         # mount root filesystem
114         if(~ $#rootdir 0)
115                 rootdir=/root
116         must mount -c /srv/boot $rootdir
117
118         # compile init command
119         if(~ $#init 0){
120                 init=/$cputype/init
121                 if(~ $service cpu)
122                         init=($init -c)
123                 if not
124                         init=($init -t)
125                 if(~ -m $ff)
126                         init=($init -m)
127         }
128
129         # remove enviroment variables
130         rm -f /env/^$mt /env/? /env/?? '/env/fn#'* 
131
132         # remove part of our temporary root
133         /mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
134         /mnt/broot/$cputype/bin/unmount /rc/bin /bin
135         /mnt/broot/$cputype/bin/unmount /
136
137         # create the name space, mount the root fs
138         /mnt/broot/$cputype/bin/bind / /
139         /mnt/broot/$cputype/bin/mount -ac '#s/boot' /
140
141         # remove the remaining temporary root
142         /mnt/broot/$cputype/bin/unmount /mnt/broot
143
144         exec $init
145 }
146
147 if(test -e '#b' && test -x /bin/aux/kbdfs){
148         bind -a '#b' /dev
149         a=$console(1)
150         if(! ~ $#a 0)
151                 a=/dev/eia^$a
152         aux/kbdfs -s cons $a
153 }
154
155 nusbrc
156
157 # bind in an ip interface
158 for(i in I l^(0 1 2 3))
159         bind -qa '#'$i /net
160 # add partitions and binds
161 configlocal
162
163 # boot(8) command line arguments
164 ff=()
165 aa=()
166 while(! ~ $#* 0){
167         if(~ $1 -*){
168                 if(~ $1 -u*){
169                         if(~ $1 -u){
170                                 user=$2
171                                 shift
172                         }
173                         if not {
174                                 user=`{echo $1 | sed 's,^-u,,g'}
175                         }
176                 }
177                 if not {
178                         if(~ $1 -*f*)
179                                 ff=($ff -f)
180                         if(~ $1 -*k*)
181                                 ff=($ff -k)
182                         if(~ $1 -*m*)
183                                 ff=($ff -m)
184                 }
185                 shift
186         }
187         if not {
188                 while(! ~ $#* 0){
189                         aa=($aa $1)
190                         shift
191                 }
192         }
193 }
194 if(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){
195         bootargs=$aa
196         nobootprompt=$aa
197 }
198
199 while(){
200         @{main}
201
202         # cleanup so it can be restarted
203         nobootprompt=()
204         user=()
205         rm -f /srv/cfs /srv/boot /srv/slashn /srv/cs /srv/dns
206 } </dev/cons >/dev/cons >[2]/dev/cons