]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/boot/bootrc
8a05621c5392a2f3d438d47b40701e2f6d315bf3
[plan9front.git] / sys / src / 9 / boot / bootrc
1 #!/bin/rc
2
3 bind -q '#p' /proc
4
5 if(test -e '#b' && ! test -e /dev/kbd){
6         bind -a '#b' /dev
7         aux/kbdfs -s cons
8         exec /rc/bin/bootrc </dev/cons >/dev/cons >[2]/dev/cons
9 }
10
11 bind -qa '#S' /dev
12 bind -qa '#f' /dev
13 bind -qa '#k' /dev
14 bind -qa '#æ' /dev
15
16 fn set {
17         a=$$1
18         $1=()
19         rm -f '#e'/$1 '#ec'/$1 /env/$1
20         if(! ~ $#a 0)
21                 $1=$a
22 }
23
24 # convert plan9.ini variables
25 set init
26 set user
27 set nvram
28 set rootdir
29 set bootargs
30 set nobootprompt
31 set sysname
32 set debugfactotum
33 set fs
34 set fsaddr
35 set auth
36 set authaddr
37
38 fn fatal {
39         echo $*
40         exit $"*
41 }
42
43 fn must {
44         $* || fatal $"*^': '^$status
45 }
46
47 fn ask {
48         echo -n $1
49         echo -n $2
50         if(! ~ $#3 0){
51                 echo -n ' ['
52                 echo -n $3
53                 echo -n '] '
54         }
55         $1=`{read}
56         if(~ $#$1 0)
57                 $1=$3
58         if(~ $"$1 '!rc'){
59                 rc -i
60                 $1=()
61         }
62         if(~ $#$1 0)
63                 ask $*
64 }
65
66 mt=()
67 . /rc/lib/tcp.rc
68 . /rc/lib/local.rc
69
70 fn main{
71         mp=()
72         while(~ $#mp 0){
73                 if(~ $#nobootprompt 0){
74                         echo
75                         showlocaldevs
76                         ask bootargs ' is (tcp, local!device)' $bootargs
77                 }
78                 if not bootargs=$nobootprompt
79                 mn=`{echo $bootargs | awk -F! '{print $1}'}
80                 ma=`{echo $bootargs | sed 's/[^!]+!?//'}
81                 for(i in `{seq 1 $#mt}){
82                         if(~ $mt($i) m^$mn)
83                                 mp=$$mt($i)
84                 }
85         }
86
87         # config method
88         $mp(1) $ma
89
90         # authentication agent
91         if(! test -f /srv/factotum){
92                 x=(/boot/factotum -sfactotum)
93                 if(~ $cpuflag 1)
94                         x=($x -S)
95                 if not
96                         x=($x -u)
97                 if(! ~ $#authaddr 0)
98                         x=($x -a $authaddr)
99                 if(! ~ $#debugfactotum 0)
100                         x=($x -p)
101                 must $x
102         }
103         if not user=`{cat /dev/hostowner}
104
105         # connect method
106         $mp(2) $ma
107
108         # mount and change root in new enviroment and namespace
109         rfork ne
110
111         # mount root filesystem
112         if(~ $#rootdir 0)
113                 rootdir=/root
114         must mount -c /srv/boot $rootdir
115
116         # remove enviroment variables
117         rm -f /env/^$mt /env/? /env/?? '/env/fn#'* 
118
119         # remove part of our temporary root
120         /mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
121         /mnt/broot/$cputype/bin/unmount /rc/bin /bin
122         /mnt/broot/$cputype/bin/unmount /
123
124         # create the name space, mount the root fs
125         /mnt/broot/$cputype/bin/bind / /
126         /mnt/broot/$cputype/bin/mount -ac '#s/boot' /
127
128         # remove the remaining temporary root
129         /mnt/broot/$cputype/bin/unmount /mnt/broot
130
131         if(~ $#init 0){
132                 init=/$cputype/init
133                 if(~ $cpuflag 1)
134                         init=($init -c)
135                 if not
136                         init=($init -t)
137         }
138         exec $init
139 }
140
141 if(test -e '#u'){
142         bind -a '#u' /dev
143         usb/usbd
144 }
145
146 if(! ~ $#kbmap 0){
147         bind -a '#κ' /dev
148         if(test -r $"kbmap)
149                 cat $"kbmap >/dev/kbmap
150 }
151
152 # bind in an ip interface
153 for(i in I l`{seq 0 3})
154         bind -qa '#'$i /net
155
156 configlocal     # add partitions and binds
157
158 while(){
159         @{main}
160         sleep 1
161
162         # cleanup so it can be restarted
163         nobootprompt=()
164         user=()
165         rm -f /srv/boot /srv/slashn /srv/cs /srv/dns
166 }