#!/bin/rc mntgen -s slash /mnt bind /root /mnt/broot unmount /root 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 } fn fatal { echo $* exit $"* } fn must { $* || fatal $"*^': '^$status } fn ask { echo -n $1 echo -n $2 if(! ~ $#3 0){ echo -n ' [' echo -n $3 echo -n '] ' } $1=`{dd -bs 64 -count 1 >[2]/dev/null} if(~ $#$1 0) $1=$3 if(~ $"$1 '!rc'){ rc -i $1=() } if(~ $#$1 0) ask $* } mt=() . /rc/lib/tcp.rc . /rc/lib/local.rc fn main{ mp=() while(~ $#mp 0){ if(~ $#nobootprompt 0){ echo showlocaldevs ask bootargs ' is (tcp, local!device)' $bootargs } if not bootargs=$nobootprompt nobootprompt=() mn=`{echo $bootargs | awk -F! '{print $1}'} ma=`{echo $bootargs | sed 's/[^!]*!?//'} switch(m$"mn){ case $mt mp=m$mn mp=$$mp } } # config method $mp(1) $ma # authentication agent if(! test -f /srv/factotum){ x=(/boot/factotum -sfactotum) if(~ $cpuflag 1){ 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 } if not user=`{cat /dev/hostowner} # 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 if(~ $#rootdir 0) rootdir=/root must mount -c /srv/boot $rootdir # compile init command if(~ $#init 0){ init=/$cputype/init if(~ $cpuflag 1) 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#'* # remove part of our temporary root /mnt/broot/$cputype/bin/unmount /$cputype/bin /bin /mnt/broot/$cputype/bin/unmount /rc/bin /bin /mnt/broot/$cputype/bin/unmount / # create the name space, mount the root fs /mnt/broot/$cputype/bin/bind / / /mnt/broot/$cputype/bin/mount -ac '#s/boot' / # remove the remaining temporary root /mnt/broot/$cputype/bin/unmount /mnt/broot exec $init } if(test -e '#b' && test -x /bin/aux/kbdfs){ bind -a '#b' /dev a=$console(1) if(! ~ $#a 0) a=/dev/eia^$a aux/kbdfs -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(! ~ $#aa 0 && ~ $#bootargs 0 && ~ $#nobootprompt 0){ bootargs=$aa nobootprompt=$aa } while(){ @{main} # cleanup so it can be restarted nobootprompt=() user=() rm -f /srv/cfs /srv/boot /srv/slashn /srv/cs /srv/dns } /dev/cons >[2]/dev/cons