]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/boot/bootrc
kernel: simplify /boot/boot: 28K down to less than 4K.
[plan9front.git] / sys / src / 9 / boot / bootrc
old mode 100644 (file)
new mode 100755 (executable)
index 5fe86ee..c0823e6
@@ -1,25 +1,42 @@
 #!/bin/rc
 
-mntgen -s slash /mnt
+# mount points
+mntgen -s slashn /n && chmod 666 /srv/slashn
+mntgen -s slashmnt /mnt && chmod 666 /srv/slashmnt
+mntgen -s mntexport /mnt/exportfs && chmod 666 /srv/mntexport
+
 bind /root /mnt/broot
 unmount /root
 
+bind -q '#σ' /shr
+bind -q '#d' /fd
 bind -q '#p' /proc
-for(i in S f k æ t)
-       bind -a '#'^$i /dev >/dev/null >[2=1]
-
-for(i in init sysname user nvram rootdir cfs bootdisk bootargs \
-       nobootprompt debugfactotum \
-       fs fsaddr auth authaddr){
-       a=$$i
-       $i=()
-       rm -f '#e'/$i '#ec'/$i /env/$i
-       if(! ~ $#a 0)
-               $i=$a
+for(i in ¶ P S f æ t b m)
+       bind -qa '#'^$i /dev
+
+# bind in an ip interface
+for(i in I l^(0 1 2 3))
+       bind -qa '#'$i /net
+
+# usually better than 1970
+cat '#r/rtc' >/dev/time >[2]/dev/null
+
+# reparse variables
+for(i in `{ls -Qp /env}){
+       switch($i){
+       case '*'* 'fn#'* e820 apm0 apid ifs path pid prompt status ?
+               # ignore these
+       case *
+               $i=`{echo $$i}
+       }
+}
+
+fn sigint {
+       status=interrupted
 }
 
 fn fatal {
-       echo $*
+       echo $* >[1=2]
        exit $"*
 }
 
@@ -31,7 +48,7 @@ fn ask {
        echo -n $1
        echo -n $2
        if(! ~ $#3 0){
-               echo -n ' ['
+               echo -n '['
                echo -n $3
                echo -n '] '
        }
@@ -47,8 +64,6 @@ fn ask {
 }
 
 mt=()
-. /rc/lib/tcp.rc
-. /rc/lib/local.rc
 
 fn main{
        mp=()
@@ -56,12 +71,13 @@ fn main{
                if(~ $#nobootprompt 0){
                        echo
                        showlocaldevs
-                       ask bootargs ' is (tcp, local!device)' $bootargs
+                       ask bootargs ' is (tcp, tls, il, local!device)' $"bootargs
                }
                if not bootargs=$nobootprompt
                nobootprompt=()
-               mn=`{echo $bootargs | awk -F! '{print $1}'}
-               ma=`{echo $bootargs | sed 's/[^!]*!?//'}
+               mn=`{echo $bootargs | sed 's,!, ,'}
+               ma=$mn(2-)
+               mn=$mn(1)
                switch(m$"mn){
                case $mt
                        mp=m$mn
@@ -69,26 +85,36 @@ fn main{
                }
        }
 
-       # config method
-       $mp(1) $ma
-
        # authentication agent
        if(! test -f /srv/factotum){
-               x=(/boot/factotum -sfactotum)
-               if(~ $cpuflag 1){
+               # we remount ip inteface after hostowner is set
+               unmount '#I' /net >[2]/dev/null
+
+               x=(/boot/factotum -n -sfactotum)
+               if(~ $service cpu)
                        x=($x -S)
-                       if(~ -k $ff)
-                               x=($x -k)
-               }
                if not
                        x=($x -u)
-               if(! ~ $#authaddr 0)
-                       x=($x -a $authaddr)
                if(! ~ $#debugfactotum 0)
                        x=($x -p)
                must $x
+
+               bind -qa '#I' /net
+       }
+
+       # config method
+       $mp(1) $ma
+
+       # load keys from secstore if $auth or $secstore is not empty
+       x=secstore
+       if(~ $#$x 0) x=auth
+       if(! ~ $#$x 0 && test -x /bin/auth/secstore && test -f /mnt/factotum/ctl){
+               x=(auth/secstore -G factotum -s^$$x)
+               if(~ $service cpu)
+                       $x -n >/mnt/factotum/ctl
+               if(~ $status *readnvram* || ! ~ $service cpu)
+                       $x >/mnt/factotum/ctl
        }
-       if not user=`{cat /dev/hostowner}
 
        # connect method
        $mp(2) $ma
@@ -98,10 +124,7 @@ fn main{
                if(~ $#bootdisk 1 && ~ $#cfs 0)
                        cfs=$bootdisk/cache
                if(~ $#cfs 1 && ! ~ $cfs off && test -f $cfs){
-                       x=(/bin/cfs -s -f $cfs)
-                       if(~ -f $ff)
-                               x=($x -r)
-                       {$x </srv/boot &} | echo 0 >/srv/cfs
+                       {/bin/cfs -s -f $cfs </srv/boot &} | echo 0 >/srv/cfs
                        rm /srv/boot
                        mv /srv/cfs /srv/boot
                }
@@ -113,21 +136,19 @@ fn main{
        # mount root filesystem
        if(~ $#rootdir 0)
                rootdir=/root
-       must mount -c /srv/boot $rootdir
+       must mount -c '#s/boot' /root $rootspec
 
        # compile init command
        if(~ $#init 0){
                init=/$cputype/init
-               if(~ $cpuflag 1)
+               if(~ $service cpu)
                        init=($init -c)
                if not
                        init=($init -t)
-               if(~ -m $ff)
-                       init=($init -m)
        }
 
        # remove enviroment variables
-       rm -f /env/^$mt /env/? /env/?? '/env/fn#'* 
+       rm -f '#e/'^$mt '#e/'? '#e/'?? '#e/fn#'* 
 
        # remove part of our temporary root
        /mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
@@ -136,7 +157,7 @@ fn main{
 
        # create the name space, mount the root fs
        /mnt/broot/$cputype/bin/bind / /
-       /mnt/broot/$cputype/bin/mount -ac '#s/boot' /
+       /mnt/broot/$cputype/bin/bind -ac $rootdir /
 
        # remove the remaining temporary root
        /mnt/broot/$cputype/bin/unmount /mnt/broot
@@ -144,57 +165,42 @@ fn main{
        exec $init
 }
 
-if(test -e '#b' && test -x /bin/aux/kbdfs){
-       bind -a '#b' /dev
+# keyboard and serial console
+if(test -x /bin/aux/kbdfs){
        a=$console(1)
        if(! ~ $#a 0)
                a=/dev/eia^$a
-       aux/kbdfs -s cons $a
-}
+       aux/kbdfs -q -s cons $a
 
-if(test -e '#u' && test -x /bin/usb/usbd){
-       bind -a '#u' /dev
-       usb/usbd
-}
-
-# bind in an ip interface
-for(i in I l^(0 1 2 3))
-       bind -qa '#'$i /net
-
-configlocal    # add partitions and binds
-
-# boot(8) command line arguments
-ff=()
-aa=()
-while(! ~ $#* 0){
-       if(~ $1 -*){
-               if(! ~ $1 -u*){
-                       if(~ $1 -*f*)
-                               ff=($ff -f)
-                       if(~ $1 -*k*)
-                               ff=($ff -k)
-                       if(~ $1 -*m*)
-                               ff=($ff -m)
-               }
-               shift
-       }
-       if not {
-               while(! ~ $#* 0){
-                       aa=($aa $1)
-                       shift
+       if(! ~$#kbmap 0){
+               if(test -f /sys/lib/kbmap/$kbmap){
+                       echo 'setting kbmap to' $kbmap
+                       cat /sys/lib/kbmap/$kbmap >/dev/kbmap
                }
        }
 }
-if(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){
-       bootargs=$aa
-       nobootprompt=$aa
+
+# usb devices
+if(test -x /bin/nusbrc && ! test -e /env/nousbrc)
+       nusbrc
+
+# load boot methods
+fn showlocaldevs {}
+fn configlocal {}
+for(i in /rc/lib/*.rc){
+       . $i
 }
 
+# add partitions and binds
+configlocal
+
 while(){
        @{main}
 
+       # subshell doesnt wait on interrupts
+       while(~ $status interrupted){wait}
+
        # cleanup so it can be restarted
        nobootprompt=()
-       user=()
-       rm -f /srv/cfs /srv/boot /srv/slashn /srv/cs /srv/dns
-} </dev/cons >/dev/cons >[2]/dev/cons 
+       rm -f /srv/^(cfs boot cs dns)
+} </dev/cons