shithub: riscv

ref: 326c8d9c4261d8e58e2469adb66f5c8438a8838c
dir: /rc/bin/inst/bootsetup/

View raw version
#!/bin/rc

# desc: create a boot floppy or configure hard disk to boot plan 9
# prereq: systype copydist

fats=()
for(i in /dev/sd*/9fat){
	if(test -f $i)
		fats=($fats $i)
}

switch($1) {
case checkdone checkready
	if(~ $#fats 0 || ~ $#9fat 1 && ~ `{fstype $9fat} dos && ~ $didbootsetup 1)
		bootsetup=done
	if not
		bootsetup=ready
	export bootsetup

case go
	echo
	echo 'Setup Plan 9 FAT boot partition (9fat)'
	echo

	if(~ $#fats 1)
		default=(-d $fats)
	if not
		default=()
	prompt $default 'Plan 9 FAT partition' $fats
	9fat=$rd
	export 9fat

	if(! test -f /tmp/plan9.ini) {
		if(~ $syst cpu)
			bootfile=9pccpuf
		if not
			bootfile=9pcf
		{
			echo 'bootfile='^$bootfile
			echo 'bootargs=local!'^$fs
			if(~ $#nvram 1)
				echo 'nvram='^$nvram
			echo 'mouseport='^$mouseport
			echo 'monitor='^$monitor
			echo 'vgasize='^$vgasize
			if(test -f '#ec/*nomp')
				echo '*nomp=1'
		} >/tmp/plan9.ini
	}

	need9fatformat=no
	if(! ~ `{fstype $9fat} dos)
		need9fatformat=yes
	if(! test -f /srv/dos)
		dossrv
	if(! mount -c /srv/dos /n/9fat $9fat >[2]/dev/null)
		need9fatformat=yes
	if not if(! test -f /n/9fat/plan9.ini)
		need9fatformat=yes

	if(~ $need9fatformat yes){
		log Initializing Plan 9 FAT partition.
		logprog disk/format -r 2 -d -b /386/pbs $9fat
		logprog mount -c /srv/dos /n/9fat $9fat
	}
	if not {
		log Updating bootsector.
		logprog dd -if $9fat -of /n/9fat/pbs.bak -bs 512 -count 1
		logprog disk/format -b /386/pbs $9fat
	}

	logprog rm -f /n/9fat/^(9bootfat plan9.ini 9pcf 9pccpuf)
	logprog cp /n/newfs/386/9bootfat /n/9fat/9bootfat
	# make file continous on disk
	logprog chmod +al /n/9fat/9bootfat
	logprog cp /tmp/plan9.ini /n/9fat/plan9.ini
	logprog cp /n/newfs/386/9pcf /n/9fat/9pcf
	logprog cp /n/newfs/386/9pccpuf /n/9fat/9pccpuf

	echo
	echo 'There are myriad ways to boot a Plan 9 system.'
	echo 'You can use any of the following.'
	echo
	echo '  plan9  - make the plan 9 disk partition the default for booting'
	echo '  winnt  - add a plan 9 option to windows nt/2000/xp boot manager'
	echo
	echo 'If you are upgrading an extant third edition installation and booting'
	echo 'from something other than a floppy, you needn''t run anything here.'
	echo 'Just type ctl-d.'

	oldbootsetup=$didbootsetup
	didbootsetup=1
	export didbootsetup

	prompt 'Enable boot method' plan9 winnt

	disk=`{basename `{basename -d $9fat}}

	if(! boot$rd){
		didbootsetup=$oldbootsetup
		export didbootsetup
	}
}