X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2F9%2Fboot%2Fbootrc;h=61da33c0df0cdf5499b7a833c087e2845862d763;hb=c3105131feb2344f64ae5169df3b024ecdbe814c;hp=e21dfc62924f7ded2a3d59add1d424db3bf0c8b8;hpb=012dec1119fe41b59bf4f498c835aa7ec2e269f2;p=plan9front.git diff --git a/sys/src/9/boot/bootrc b/sys/src/9/boot/bootrc index e21dfc629..61da33c0d 100644 --- a/sys/src/9/boot/bootrc +++ b/sys/src/9/boot/bootrc @@ -1,9 +1,33 @@ -rfork e +#!/bin/rc -mt=() -. /rc/lib/tcp.rc -. /rc/lib/local.rc -. /rc/lib/usb.rc +mntgen -s slash /mnt +bind /root /mnt/broot +unmount /root + +bind -q '#p' /proc +for(i in S f k æ 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 + +# usualy 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 $* @@ -22,7 +46,7 @@ fn ask { echo -n $3 echo -n '] ' } - $1=`{read} + $1=`{dd -bs 64 -count 1 >[2]/dev/null} if(~ $#$1 0) $1=$3 if(~ $"$1 '!rc'){ @@ -33,66 +57,86 @@ fn ask { ask $* } -fn getmethod{ +mt=() +. /rc/lib/net.rc +. /rc/lib/local.rc + +fn main{ mp=() while(~ $#mp 0){ if(~ $#nobootprompt 0){ echo showlocaldevs - ask bootargs ' are? (tcp, local!device)' $bootargs - } - if not { - bootargs=$nobootprompt - nobootprompt=() + ask bootargs ' is (tcp, il, local!device)' $"bootargs } + if not bootargs=$nobootprompt + nobootprompt=() mn=`{echo $bootargs | awk -F! '{print $1}'} - ma=`{echo $bootargs | awk -F! '{print $2}'} - for(i in `{seq 1 $#mt}){ - if(~ $mt($i) m^$mn) - mp=$$mt($i) + ma=`{echo $bootargs | sed 's/[^!]*!?//'} + switch(m$"mn){ + case $mt + mp=m$mn + mp=$$mp } } -} - -fn main{ - rm -f /srv/boot - rm -f /srv/usb - - getmethod - - switch($mn){ - case local - islocal=1 - case hybrid - ishybrid=1 - } # config method $mp(1) $ma # authentication agent - if(! test -f /srv/factotum){ - x=(/boot/factotum -sfactotum) - if(~ $cpuflag 1) - x=($x -kS) - if not - x=($x -u) - if(! ~ $#authaddr 0) - x=($x -a $authaddr) - if(! ~ $#debugfactotum 0) - x=($x -p) - must $x + if(test -f /srv/factotum){ + rm -f /srv/factotum + user=`{cat /dev/hostowner} } + x=(/boot/factotum -sfactotum) + if(~ $service cpu){ + x=($x -S) + if(~ -k $ff) + x=($x -k) + } + if not + x=($x -u) + if(! ~ $#auth 0) + x=($x -a $auth) + if(! ~ $#debugfactotum 0) + x=($x -p) + must $x # connect method $mp(2) $ma + # insert cfs in the pipeline + if(test -x /bin/cfs){ + 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/cfs + rm /srv/boot + mv /srv/cfs /srv/boot + } + } + + # mount and change root in new enviroment and namespace + rfork ne + # mount root filesystem - must mount -c /srv/boot /root + if(~ $#rootdir 0) + rootdir=/root + must mount -c /srv/boot $rootdir - # start pager - if(test -x /dev/swap) - echo -n start >/dev/swap + # compile init command + if(~ $#init 0){ + init=/$cputype/init + 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#'* @@ -109,41 +153,70 @@ fn main{ # remove the remaining temporary root /mnt/broot/$cputype/bin/unmount /mnt/broot - rootdir=/root - - if(~ $#init 0){ - init=/$cputype/init - if(~ $cpuflag 1) - init=($init -c) - if not - init=($init -t) - # TODO handle mflag - } exec $init } -bind -q '#p' /proc - -bind -qa '#S' /dev -bind -qa '#f' /dev -bind -qa '#k' /dev -bind -qa '#æ' /dev - -if(test -e '#u'){ - bind -a '#u' /dev - usb/usbd +# keyboard and serial console +if(test -x /bin/aux/kbdfs){ + a=$console(1) + if(! ~ $#a 0) + a=/dev/eia^$a + aux/kbdfs -q -s cons $a } -if(! ~ $#kbmap 0){ - bind -a '#κ' /dev - if(test -r $"kbmap) - cat $"kbmap >/dev/kbmap +# usb devices +if(test -x /bin/nusbrc && ! test -e /env/nousbrc) + nusbrc + +# wait for devices to settle down +sleep 2 + +# add partitions and binds +configlocal + +# boot(8) command line arguments +ff=() +aa=() +while(! ~ $#* 0){ + if(~ $1 -*){ + if(~ $1 -u*){ + if(~ $1 -u){ + user=$2 + shift + } + if not { + user=`{echo $1 | sed 's,^-u,,g'} + } + } + if not { + 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(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){ + bootargs=$aa + nobootprompt=$aa } -configusb # run partfs on usb disks -configlocal # add partitions and binds +while(){ + @{main} -while()@{ - rfork ne - main -} + # subshell doesnt wait on interrupts + while(~ $status interrupted){wait} + + # cleanup so it can be restarted + nobootprompt=() + rm -f /srv/^(cfs boot slashn cs dns) +}