Plan 9 from Bell Labs’s /usr/web/sources/contrib/maht/rc/make_cpuauth

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

echo this script will ask some questions, see QUESTIONS HERE, answer the questions truthfully and it will become a cpu/auth server, you will probably have to make notes so you know what to do when it does a reboot see the end of the script

echo these instructions were culled from the wiki and made to work on a fresh install on September 7th 2007 

echo 20th July - Added testing for and if so starting venti on '/dev/$disk/arenas'

echo added aux/listen for doing cpu -h

echo failed on 15th may because /386/bin/fossil has the wrong date and mk kernel tries to mk it

if(! ~ $user glenda) exec echo log in as glenda

fn set_sysname {
	echo 'sysname=' ^$sysname >> /n/9fat/plan9.ini
}

fn add_cfg {
	cd /cfg
	mkdir $sysname
	dircp example $sysname
}

fn drivers {
	echo m i S t
	#cat /dev/drivers | awk ' { print "''" $1 "''" } ' | tr -d '#'
}

fn bind_devices {
	{
		echo 'for (i in (m i S t))'
		echo '	bind -a ''#''^$i /dev >/dev/null >[2=1]'
	} >> /rc/bin/cpurc.local
}

fn config_ip {
	{
		if(! ~ $#ip 0 && ! ~ $#gateway 0 && ! ~ $#netmask 0 )
			echo 'ip/ipconfig -g ' ^$gateway ^' ether /net/ether0 ' ^$ip ^' ' ^$netmask
		if not
			echo ip/config
	
	} >> /cfg/$sysname/cpurc
}

fn uncomment_cpurc {
	echo '/# auth\/keyfs
s/# /
/# auth\/cron
s/# /
/dicey
-1
s/^/aux\/listen -q -t \/rc\/bin\/service.auth -d \/rc\/bin\/service tcp
w
q
' | ed /rc/bin/cpurc
}

fn uncomment_cfg_cpurc {
	echo '/# ip\/dhcpd
s/# /
/# ip\/tftpd
s/# /
/# ndb\/dns
s/# /
s/$/ -r/
w
q
' | ed /cfg/$sysname/cpurc
}

fn enable_services {
	mv /rc/bin/service.auth/authsrv.tcp567 /rc/bin/service.auth/tcp567
	echo auth/secstored >>  /cfg/$sysname/cpurc
}

fn rioize {
	{
		echo 'aux/mouse ' ^$mouseport
		echo 'aux/vga -l ' ^$vgasize
		echo 'exec rio'	
	} >> /cfg/$sysname/cpustart
}


fn create_bootes {
	{
		echo uname bootes bootes
		echo uname adm +bootes
		echo uname sys +bootes
		echo fsys main
		echo create /active/cron/bootes bootes bootes d775
		echo create /active/sys/log/cron bootes bootes a664
	} >> /srv/fscons
}

fn q40 {
	oifs = $ifs
	ifs = '.'
	bits = `{echo -n $ip}
	echo -n $bits(1) ^. ^$bits(2) ^. ^$bits(3) ^.0
	ifs = $oifs
}

fn fill_ndb {
	
	{
		echo 'ipnet=' ^$ipnet 'ip=' ^`{q40} 'ipmask=' ^$netmask 'ether=' ^`{cat /net/ether0/addr}
		echo '	auth=' ^$sysname
		echo '	cpu=' ^$sysname
		echo '	fs=' ^$sysname
		echo '	bootf=' ^$bootf 
		echo '	dns=' ^$dns

		echo 'authdom=' ^$authdom ^' auth=' ^$sysname

		echo 'ip=' ^$ip ^' sys=' ^$sysname ^' dom=' ^$sysname ^'.' ^$authdom
	} >> /lib/ndb/local
}

fn empower_bootes {
	{
		echo 'hostid=bootes'
		echo '	uid=!sys uid=!adm uid=*'
	} >> /lib/ndb/auth
}

fn install_kernel {
	if(! test -e /n/9fat/9pccpuf) {
		touch /386/bin/fossil # srcs has bugged dates and mk fails because of this
		cd /sys/src/9/pc
		mk 'CONF=pccpuf' install
		mk clean
		cp /386/9pccpuf /n/9fat
	}
}

fn write_bootmenu {

	{
		echo '
[menu]
menuitem=pcf, Boot terminal - 9pcf
menuitem=pccpuf, Boot cpu/auth - 9pccpuf
menuitem=chooser, Choose kernel
menudefault=pccpuf, 10

[pcf]
bootfile=' ^$disk ^'!9fat!9pcf

[pccpuf]
bootfile=' ^$disk ^'!9fat!9pccpuf

[chooser]
bootfile=' ^$disk ^'!9fat!9pcf
bootfile=' ^$disk ^'!9fat!9pccpuf
 
[common]
'
		grep -v '^bootfile=' /n/9fat/plan9.ini
	if(test -e /dev/$disk/arenas)
		echo venti'='/dev/$disk/arenas
	} > /tmp/plan9.ini 
	mv /tmp/plan9.ini  /n/9fat/plan9.ini
}

fn backup_files {
	bkdir = /usr/glenda/backups/`{date -n}
	mkdir -p $bkdir && echo backups going in $bkdir
	cp /n/9fat/plan9.ini /rc/bin/cpurc.local /rc/bin/cpurc /lib/ndb/local /lib/ndb/auth $bkdir
}

fn create_newfossil_sys_user {
	echo '#!/bin/rc

auth/changeuser $1
{
	echo uname $1 $1
	echo ''uname sys +'' ^$1
	echo newuser $1
	echo ''newuser sys +'' ^$1
} >> /srv/fscons
' > /sys/lib/newfsysuser
	chmod 755 /sys/lib/newfsysuser
} 

# QUESTIONS HERE
# variables required 

if(! test -e /env/mouseport)
	mouseport = ps2intellimouse
if(! test -e /env/vgasize)
	vgasize = 640x480x8

echo What sysname will this cpu/auth have
sysname =`{read}
echo enter ip netmask gateway as dotted quads i.e. 192.168.1.9 255.255.255.0 192.168.1.1
nets =`{read}
ip = $nets(1)
netmask = $nets(2)
gateway = $nets(3)

echo enter ip of dns for /lib/ndb/local
dns = `{read}
echo enter ipnet and authdom i.e, zero zero.dom
bits = `{read}
ipnet = $bits(1)
authdom = $bits(2)
echo disk to use i.e. sdC0
disk = `{read}
bootf = /386/9pc

echo sysname - $sysname
echo ipnet - $ipnet
echo authdom - $authdom
echo ip - $ip
echo netmask - $netmask
echo gateway - $gateway
echo dns - $dns
echo disk - $disk
if(test -e /dev/$disk/arenas)
	echo venti on /dev/$disk/arenas
echo bootf - $bootf
echo mouseport - $mouseport
echo vgasize - $vgasize

echo enter to continue or kill it now 
read

# ACTION STARTS HERE
9fat:
ramfs
backup_files
set_sysname

add_cfg
bind_devices
config_ip 
uncomment_cfg_cpurc
uncomment_cpurc
enable_services
rioize
create_bootes

echo auth/keyfs password for this machine 

auth/keyfs

fill_ndb
empower_bootes
install_kernel
write_bootmenu
create_newfossil_sys_user

echo blahblahblah >/dev/$disk/nvram

echo 'that''s the end of stage 1, now reboot
after reboot you''re asked these (with the answers here) :
authid : bootes
authdom : ' ^$authdom ^'
secstore key : YOUR CHOICE
password : BOOTES PASSWORD

then 
' ^$sysname ^'# auth/changeuser bootes
password: BOOTES PASSWORD

then run
/sys/lib/newfsysuser YOURUSERNAME
to give yourself a login in sys group on that machine
then you can drawterm into it
'

echo to reboot type:  fshalt -r


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].