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-06-04 07:18:11 +00:00
|
|
|
for(i in S f k æ t)
|
2011-05-10 09:14:30 +00:00
|
|
|
bind -a '#'^$i /dev >/dev/null >[2=1]
|
2011-05-09 08:32:14 +00:00
|
|
|
|
2011-05-10 09:14:30 +00:00
|
|
|
for(i in init user nvram rootdir bootargs nobootprompt sysname \
|
|
|
|
debugfactotum fs fsaddr auth authaddr){
|
|
|
|
a=$$i
|
|
|
|
$i=()
|
|
|
|
rm -f '#e'/$i '#ec'/$i /env/$i
|
2011-04-30 20:17:33 +00:00
|
|
|
if(! ~ $#a 0)
|
2011-05-10 09:14:30 +00:00
|
|
|
$i=$a
|
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-04-19 05:24:46 +00:00
|
|
|
$1=`{read}
|
|
|
|
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=()
|
|
|
|
. /rc/lib/tcp.rc
|
|
|
|
. /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
|
2011-04-30 20:17:33 +00:00
|
|
|
ask bootargs ' is (tcp, local!device)' $bootargs
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
2011-04-30 20:17:33 +00:00
|
|
|
if not bootargs=$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-04-19 05:24:46 +00:00
|
|
|
if(! test -f /srv/factotum){
|
|
|
|
x=(/boot/factotum -sfactotum)
|
|
|
|
if(~ $cpuflag 1)
|
2011-05-01 03:25:02 +00:00
|
|
|
x=($x -S)
|
2011-04-19 05:24:46 +00:00
|
|
|
if not
|
|
|
|
x=($x -u)
|
|
|
|
if(! ~ $#authaddr 0)
|
|
|
|
x=($x -a $authaddr)
|
|
|
|
if(! ~ $#debugfactotum 0)
|
|
|
|
x=($x -p)
|
|
|
|
must $x
|
|
|
|
}
|
2011-04-30 20:17:33 +00:00
|
|
|
if not user=`{cat /dev/hostowner}
|
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-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-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
|
|
|
if(~ $#init 0){
|
|
|
|
init=/$cputype/init
|
|
|
|
if(~ $cpuflag 1)
|
|
|
|
init=($init -c)
|
|
|
|
if not
|
|
|
|
init=($init -t)
|
|
|
|
}
|
|
|
|
exec $init
|
2011-04-16 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 09:14:30 +00:00
|
|
|
if(test -e '#b' && test -x /bin/aux/kbdfs){
|
|
|
|
bind -a '#b' /dev
|
2011-05-13 08:53:43 +00:00
|
|
|
a=$console(1)
|
|
|
|
if(! ~ $#a 0)
|
|
|
|
a=/dev/eia^$a
|
|
|
|
aux/kbdfs -s cons $a
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 09:14:30 +00:00
|
|
|
if(test -e '#u' && test -x /bin/usb/usbd){
|
|
|
|
bind -a '#u' /dev
|
|
|
|
usb/usbd
|
2011-04-19 05:24:46 +00:00
|
|
|
}
|
2011-04-16 20:42:16 +00:00
|
|
|
|
2011-05-01 07:07:32 +00:00
|
|
|
# bind in an ip interface
|
2011-06-04 07:18:11 +00:00
|
|
|
for(i in I l^(0 1 2 3))
|
2011-05-01 07:07:32 +00:00
|
|
|
bind -qa '#'$i /net
|
|
|
|
|
2011-04-18 06:33:38 +00:00
|
|
|
configlocal # add partitions and binds
|
|
|
|
|
2011-04-30 20:17:33 +00:00
|
|
|
while(){
|
|
|
|
@{main}
|
|
|
|
|
|
|
|
# cleanup so it can be restarted
|
|
|
|
nobootprompt=()
|
|
|
|
user=()
|
2011-05-02 01:21:55 +00:00
|
|
|
rm -f /srv/boot /srv/slashn /srv/cs /srv/dns
|
2011-05-10 09:14:30 +00:00
|
|
|
} </dev/cons >/dev/cons >[2]/dev/cons
|