~pixelherodev/ANTS

d63998cf976b74e09f0690d4f639923ee60d0dae — Noam Preil 11 months ago 4f3566e
boot: add ants files
3 files changed, 170 insertions(+), 0 deletions(-)

M sys/lib/sysconfig/proto/distproto
M sys/src/9/boot/bootfs.proto
M sys/src/9/boot/bootrc
M sys/lib/sysconfig/proto/distproto => sys/lib/sysconfig/proto/distproto +2 -0
@@ 69,6 69,7 @@ mail	d775 upas upas
		bitsy	d775
		dial	d775
		disk	d775
		fossil	d775
		fs	d775
		games	d775
		ip	d775


@@ 138,6 139,7 @@ amd64	d775
		bitsy	d775
		dial	d775
		disk	d775
		fossil	d775
		fs	d775
		games	d775
		ip	d775

M sys/src/9/boot/bootfs.proto => sys/src/9/boot/bootfs.proto +38 -0
@@ 1,16 1,22 @@
$objtype
	bin
		9660srv
		aan
		awk
		auth
			newns
			secstore
		aux
			kbdfs
			listen1
			wpa
		basename
		bind
		cat
		cfs
		chmod
		cp
		cpu
		dd
		disk
			cryptsetup


@@ 19,10 25,19 @@ $objtype
			prep
		dossrv
		echo
		ed
		exportfs
		fossil
			fossil
		cwfs64x
		grep
		grio
		gunzip
		hubfs
		hubshell
		ip
			ipconfig
			rexexec
		ls
		mkdir
		mntgen


@@ 31,19 46,30 @@ $objtype
		ndb
			dnsgetip
		hjfs
		ramfs
		rc
		read
		rm
		rx
		sed
		sleep
		srv
		srvfs
		tar
		test
		tlsclient
		tlssrv
		touch
		tr
		unmount
		nusb
			usbd
			ether
			disk
			kb
		venti
			venti
		wc
		xd
rc
	lib


@@ 54,6 80,14 @@ rc
	bin
		fstype
		diskparts
		hub - - - /sys/src/ants/bootdir.extras/hub
		initskel - - - /sys/src/ants/bootdir.extras/initskel
		ramskel - - - /sys/src/ants/bootdir.extras/ramskel
		rconnect
		rcpu
		rexport
		rimport
		save9cfg - - - /sys/src/ants/bootdir.extras/save9cfg
		srvtls
		nusbrc 555 sys sys ../boot/nusbrc
		bootrc 555 sys sys ../boot/bootrc


@@ 65,3 99,7 @@ sys
lib
	firmware
		+
	namespace
	namespace.saveterm
	namespace.save9front
	skel.tar - - - /sys/src/ants/bootdir.extras/skel.tar

M sys/src/9/boot/bootrc => sys/src/9/boot/bootrc +130 -0
@@ 1,5 1,9 @@
#!/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


@@ 63,6 67,129 @@ fn ask {
		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{


@@ 102,6 229,9 @@ fn main{
		bind -qa '#I' /net
	}

	# setup low level namespace
	ants

	# config method
	$mp(1) $ma