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
|
|
|
|
|
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
|
2011-08-27 15:58:20 +00:00
|
|
|
for(i in `{ls -Qp '#ec'}){
|
|
|
|
switch($i){
|
2011-08-28 18:37:20 +00:00
|
|
|
case '*'*
|
2011-08-27 15:58:20 +00:00
|
|
|
# ignore these
|
|
|
|
case *
|
|
|
|
$i=`{echo $$i}
|
|
|
|
}
|
2011-04-30 20:17:33 +00:00
|
|
|
}
|
|
|
|
|
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){
|
2011-04-19 05:24:46 +00:00
|
|
|
echo -n ' ['
|
|
|
|
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=()
|
2012-05-03 08:47:40 +00:00
|
|
|
. /rc/lib/net.rc
|
2011-04-30 20:17:33 +00:00
|
|
|
. /rc/lib/local.rc
|
|
|
|
|
|
|
|
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
|
2012-05-03 08:47:40 +00:00
|
|
|
ask bootargs ' is (tcp, 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=()
|
2011-04-21 22:22:25 +00:00
|
|
|
mn=`{echo $bootargs | awk -F! '{print $1}'}
|
2011-05-21 03:42:13 +00:00
|
|
|
ma=`{echo $bootargs | sed 's/[^!]*!?//'}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-21 22:22:25 +00:00
|
|
|
# config method
|
|
|
|
$mp(1) $ma
|
|
|
|
|
2011-04-18 05:58:04 +00:00
|
|
|
# authentication agent
|
2011-08-28 18:37:20 +00:00
|
|
|
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)
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
2011-08-28 18:37:20 +00:00
|
|
|
if not
|
|
|
|
x=($x -u)
|
2012-05-03 08:47:40 +00:00
|
|
|
if(! ~ $#auth 0)
|
|
|
|
x=($x -a $auth)
|
2011-08-28 18:37:20 +00:00
|
|
|
if(! ~ $#debugfactotum 0)
|
|
|
|
x=($x -p)
|
|
|
|
must $x
|
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){
|
|
|
|
x=(/bin/cfs -s -f $cfs)
|
|
|
|
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
|
|
|
|
rm -f /env/^$mt /env/? /env/?? '/env/fn#'*
|
|
|
|
|
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
|
|
|
|
sleep 2
|
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}
|
|
|
|
|
|
|
|
# cleanup so it can be restarted
|
|
|
|
nobootprompt=()
|
|
|
|
user=()
|
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
|