#!/bin/rc if(~ $#rootdir 0) rootdir=/root objtype=`{cat /env/cputype} # 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 '#d' /fd bind -q '#p' /proc 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 # 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 $* >[1=2] 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 $* } fn hostcheck{ hosttest=`{cat /dev/hostowner} if(~ $hosttest ''){ if(~ $user ''){ user=glenda } echo 'no hostowner found: setting to '$user echo -n $user >'/dev/hostowner' } if(~ $user ''){ user=`{cat /dev/hostowner} } } fn dochecksys{ systest=`{cat /dev/sysname} switch($sysname){ case ?* if(~ $systest ''){ echo setting /dev/sysname to $sysname echo -n $sysname >/dev/sysname systest=`{cat /dev/sysname} } if(! ~ $systest $sysname){ echo warning sysname mismatch between dev and env } case '' if(~ $systest ''){ if(~ $service cpu){ sysname=helix } if(~ $service terminal){ sysname=front } if(~ $sysname ''){ sysname=mutant } echo no sysname found in dev or env setting to $sysname echo -n $sysname >/dev/sysname } if not{ echo setting sysname var to $systest from /dev/sysname sysname = $systest } } } fn ants{ paqfs -s -S frontpaq -c 128 /boot/bootfs.paq bind -a /boot /bin hostcheck dochecksys ipparams=`{echo $ipparams} ## set up ramfs as a rootlike fs hostdir=`{cat '#c/hostowner'} cd / echo -n 'ramfs -S ramboot...' ramfs -S ramboot mount -c /srv/ramboot /root bind -ac /root / echo -n 'tar xf /lib/skel.tar...' tar xf /lib/skel.tar if (test -d /root/mnt) bind -ac /root/mnt /mnt mount -b /srv/factotum /mnt bind -ac /root/bin /bin ## get tgzfs if chosen and load into the ramdisk if(~ $tgzfs '') tgzfs=tools.tgz if(~ $tgzfs no) tgzfs='' if(~ $tgzfs *.tgz){ dossrv if(~ $fatpath '') fatpath=`{ls /dev/sd*/9fat} if(! test -d /x) mkdir /root/x mount /srv/dos /x $fatpath if(test -e /x/$tgzfs){ echo -n tar xzf $tgzfs^... tar xzf /x/$tgzfs } if not echo 'tgz not found continuing with only /boot' } timezone=`{cat /adm/timezone/local} ## if we aren't bootes we need to have a $home if(! ~ $user bootes){ echo 'copying bootes skeleton to '$user mkdir /root/usr/$user mkdir /root/usr/$user/lib mkdir /root/usr/$user/tmp mkdir /root/usr/$user/bin mkdir /root/usr/$user/bin/rc mkdir /root/usr/$user/bin/$cputype cp /usr/bootes/lib/profile /root/usr/$user/lib/profile } bind -c /usr/$user/tmp /tmp echo 'partial root built starting services' auth/newns -n /lib/namespace initskel if(! ~ $privpassword ''){ echo adding key to factotum if(~ $passdom '') passdom=9front if(~ $keyowner '') keyowner=$user echo 'key proto=dp9ik dom='$passdom' user='$keyowner' !password='^$privpassword >/mnt/factotum/ctl rm '#ec/privpassword' rm /env/privpassword rm /env/passdom rm /env/keyowner } } mt=() fn main{ mp=() while(~ $#mp 0){ if(~ $#nobootprompt 0){ echo showlocaldevs ask bootargs ' is (tcp, tls, il, local!device)' $"bootargs } if not bootargs=$nobootprompt nobootprompt=() mn=`{echo $bootargs | sed 's,!, ,'} ma=$mn(2-) mn=$mn(1) switch(m$"mn){ case $mt mp=m$mn mp=$$mp } } # authentication agent if(! test -f /srv/factotum){ # 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 not x=($x -u) if(! ~ $#debugfactotum 0) x=($x -p) must $x bind -qa '#I' /net } # setup low level namespace ants # 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 } # 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){ {/bin/cfs -s -f $cfs /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 '#s/boot' /root $rootspec # compile init command if(~ $#init 0){ init=/$cputype/init if(~ $service cpu) init=($init -c) if not init=($init -t) } # remove enviroment variables rm -f '#e/'^$mt '#e/'? '#e/'?? '#e/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/bind -ac $rootdir / # remove the remaining temporary root /mnt/broot/$cputype/bin/unmount /mnt/broot exec $init } # 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 } # 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=() rm -f /srv/^(cfs boot cs dns) }