2011-04-30 20:17:33 +00:00
|
|
|
#!/bin/rc
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-06-04 05:19:29 +00:00
|
|
|
mntgen -s slash /mnt
|
|
|
|
bind /root /mnt/broot
|
|
|
|
unmount /root
|
|
|
|
|
2014-12-09 23:30:07 +00:00
|
|
|
bind -q '#d' /fd
|
2011-04-30 20:17:33 +00:00
|
|
|
bind -q '#p' /proc
|
2011-08-16 08:15:36 +00:00
|
|
|
for(i in S f k æ t b m)
|
|
|
|
bind -qa '#'^$i /dev
|
2011-05-09 08:32:14 +00:00
|
|
|
|
2011-08-16 08:15:36 +00:00
|
|
|
# bind in an ip interface
|
|
|
|
for(i in I l^(0 1 2 3))
|
|
|
|
bind -qa '#'$i /net
|
|
|
|
|
2011-08-22 09:20:32 +00:00
|
|
|
# usualy better than 1970
|
|
|
|
cat '#r/rtc' >/dev/time >[2]/dev/null
|
|
|
|
|
2011-08-28 18:37:20 +00:00
|
|
|
# reparse variables
|
2012-12-06 01:03:59 +00:00
|
|
|
for(i in `{ls -Qp /env}){
|
2011-08-27 15:58:20 +00:00
|
|
|
switch($i){
|
2012-12-06 02:46:22 +00:00
|
|
|
case '*'* 'fn#'* e820 apm0 apid ifs path pid prompt status ?
|
2011-08-27 15:58:20 +00:00
|
|
|
# ignore these
|
|
|
|
case *
|
|
|
|
$i=`{echo $$i}
|
|
|
|
}
|
2011-04-30 20:17:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 17:57:02 +00:00
|
|
|
fn sigint {
|
|
|
|
status=interrupted
|
|
|
|
}
|
|
|
|
|
2011-04-16 20:42:16 +00:00
|
|
|
fn fatal {
|
|
|
|
echo $*
|
|
|
|
exit $"*
|
|
|
|
}
|
|
|
|
|
|
|
|
fn must {
|
|
|
|
$* || fatal $"*^': '^$status
|
|
|
|
}
|
|
|
|
|
2011-04-19 05:24:46 +00:00
|
|
|
fn ask {
|
|
|
|
echo -n $1
|
|
|
|
echo -n $2
|
2011-04-23 18:22:24 +00:00
|
|
|
if(! ~ $#3 0){
|
2013-04-28 22:34:47 +00:00
|
|
|
echo -n '['
|
2011-04-19 05:24:46 +00:00
|
|
|
echo -n $3
|
|
|
|
echo -n '] '
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-06-04 08:07:21 +00:00
|
|
|
$1=`{dd -bs 64 -count 1 >[2]/dev/null}
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $#$1 0)
|
|
|
|
$1=$3
|
|
|
|
if(~ $"$1 '!rc'){
|
|
|
|
rc -i
|
|
|
|
$1=()
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $#$1 0)
|
|
|
|
ask $*
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
mt=()
|
|
|
|
|
|
|
|
fn main{
|
2011-04-21 22:22:25 +00:00
|
|
|
mp=()
|
|
|
|
while(~ $#mp 0){
|
2011-04-19 05:24:46 +00:00
|
|
|
if(~ $#nobootprompt 0){
|
|
|
|
echo
|
|
|
|
showlocaldevs
|
2015-08-25 09:07:46 +00:00
|
|
|
ask bootargs ' is (tcp, tcptls, il, local!device)' $"bootargs
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
2011-04-30 20:17:33 +00:00
|
|
|
if not bootargs=$nobootprompt
|
2011-06-14 19:03:03 +00:00
|
|
|
nobootprompt=()
|
2015-04-09 13:36:20 +00:00
|
|
|
mn=`{echo $bootargs | sed 's,!, ,'}
|
|
|
|
ma=$mn(2-)
|
|
|
|
mn=$mn(1)
|
2011-06-04 07:18:11 +00:00
|
|
|
switch(m$"mn){
|
|
|
|
case $mt
|
|
|
|
mp=m$mn
|
|
|
|
mp=$$mp
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:55:41 +00:00
|
|
|
# authentication agent
|
|
|
|
if(! test -f /srv/factotum){
|
|
|
|
x=(/boot/factotum -n -sfactotum)
|
|
|
|
if(~ $service cpu){
|
|
|
|
x=($x -S)
|
|
|
|
if(~ -k $ff)
|
|
|
|
x=($x -k)
|
|
|
|
}
|
|
|
|
if not
|
|
|
|
x=($x -u)
|
|
|
|
if(! ~ $#debugfactotum 0)
|
|
|
|
x=($x -p)
|
|
|
|
must $x
|
|
|
|
}
|
|
|
|
|
2011-04-21 22:22:25 +00:00
|
|
|
# config method
|
|
|
|
$mp(1) $ma
|
|
|
|
|
2014-12-09 21:26:30 +00:00
|
|
|
# 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)
|
2014-04-18 18:55:41 +00:00
|
|
|
if(~ $service cpu)
|
|
|
|
$x -n >/mnt/factotum/ctl
|
|
|
|
if(~ $status *readnvram* || ! ~ $service cpu)
|
|
|
|
$x >/mnt/factotum/ctl
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-21 22:22:25 +00:00
|
|
|
# connect method
|
|
|
|
$mp(2) $ma
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-06-15 12:50:29 +00:00
|
|
|
# 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){
|
2015-05-13 04:15:18 +00:00
|
|
|
x=(/bin/cfs -s -f $cfs)
|
2011-06-15 12:50:29 +00:00
|
|
|
if(~ -f $ff)
|
|
|
|
x=($x -r)
|
|
|
|
{$x </srv/boot &} | echo 0 >/srv/cfs
|
|
|
|
rm /srv/boot
|
|
|
|
mv /srv/cfs /srv/boot
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
# mount and change root in new enviroment and namespace
|
|
|
|
rfork ne
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
# mount root filesystem
|
|
|
|
if(~ $#rootdir 0)
|
|
|
|
rootdir=/root
|
|
|
|
must mount -c /srv/boot $rootdir
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-06-14 19:03:03 +00:00
|
|
|
# compile init command
|
|
|
|
if(~ $#init 0){
|
|
|
|
init=/$cputype/init
|
2011-06-16 15:35:07 +00:00
|
|
|
if(~ $service cpu)
|
2011-06-14 19:03:03 +00:00
|
|
|
init=($init -c)
|
|
|
|
if not
|
|
|
|
init=($init -t)
|
|
|
|
if(~ -m $ff)
|
|
|
|
init=($init -m)
|
|
|
|
}
|
|
|
|
|
2011-04-21 22:22:25 +00:00
|
|
|
# remove enviroment variables
|
2014-12-10 02:16:36 +00:00
|
|
|
rm -f '#e/'^$mt '#e/'? '#e/'?? '#e/fn#'*
|
2011-04-21 22:22:25 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# remove part of our temporary root
|
2011-04-19 05:24:46 +00:00
|
|
|
/mnt/broot/$cputype/bin/unmount /$cputype/bin /bin
|
2011-04-18 05:58:04 +00:00
|
|
|
/mnt/broot/$cputype/bin/unmount /rc/bin /bin
|
|
|
|
/mnt/broot/$cputype/bin/unmount /
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# create the name space, mount the root fs
|
|
|
|
/mnt/broot/$cputype/bin/bind / /
|
|
|
|
/mnt/broot/$cputype/bin/mount -ac '#s/boot' /
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# remove the remaining temporary root
|
|
|
|
/mnt/broot/$cputype/bin/unmount /mnt/broot
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
exec $init
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 08:15:36 +00:00
|
|
|
# keyboard and serial console
|
|
|
|
if(test -x /bin/aux/kbdfs){
|
2011-05-13 08:53:43 +00:00
|
|
|
a=$console(1)
|
|
|
|
if(! ~ $#a 0)
|
|
|
|
a=/dev/eia^$a
|
2011-09-02 13:16:10 +00:00
|
|
|
aux/kbdfs -q -s cons $a
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 08:15:36 +00:00
|
|
|
# usb devices
|
2012-03-01 17:55:42 +00:00
|
|
|
if(test -x /bin/nusbrc && ! test -e /env/nousbrc)
|
|
|
|
nusbrc
|
|
|
|
|
|
|
|
# wait for devices to settle down
|
2014-02-14 05:11:11 +00:00
|
|
|
if(~ $#usbwait 1)
|
|
|
|
sleep $usbwait
|
|
|
|
if(~ $#usbwait 0)
|
|
|
|
sleep 2
|
|
|
|
|
2015-03-24 23:11:54 +00:00
|
|
|
# load boot methods
|
|
|
|
fn showlocaldevs {}
|
|
|
|
fn configlocal {}
|
|
|
|
for(i in /rc/lib/*.rc){
|
|
|
|
. $i
|
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-06-16 15:35:07 +00:00
|
|
|
# add partitions and binds
|
|
|
|
configlocal
|
2011-04-18 06:33:38 +00:00
|
|
|
|
2011-06-14 19:03:03 +00:00
|
|
|
# boot(8) command line arguments
|
|
|
|
ff=()
|
|
|
|
aa=()
|
|
|
|
while(! ~ $#* 0){
|
|
|
|
if(~ $1 -*){
|
2011-06-16 15:35:07 +00:00
|
|
|
if(~ $1 -u*){
|
|
|
|
if(~ $1 -u){
|
|
|
|
user=$2
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
if not {
|
|
|
|
user=`{echo $1 | sed 's,^-u,,g'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if not {
|
2011-06-14 19:03:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
while(){
|
|
|
|
@{main}
|
|
|
|
|
2012-11-06 16:19:41 +00:00
|
|
|
# subshell doesnt wait on interrupts
|
|
|
|
while(~ $status interrupted){wait}
|
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
# cleanup so it can be restarted
|
|
|
|
nobootprompt=()
|
2011-08-16 08:15:36 +00:00
|
|
|
rm -f /srv/^(cfs boot slashn cs dns)
|
2012-03-01 17:55:42 +00:00
|
|
|
} </dev/cons
|