summaryrefslogtreecommitdiff
path: root/rc/bin/inst/bootsetup
blob: c1de3dce24c9e9091fe0e8e73b6379e3b48ce6c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/rc

# desc: configure hard disk to boot plan 9
# prereq: 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(~ $#bootfile 1){
		bootfile=`{basename $bootfile}
	}
	if(! ~ $#bootfile 1 || ! test -f /$cputype/$bootfile) {
		bootfile=()
	}

	if(! test -f /tmp/plan9.ini) {
		@{
			if(~ $#bootfile 1)
				echo 'bootfile='^$bootfile
			if(~ $#fs 1)
				echo 'bootargs=local!'^$fs' '$"fsflags
			if(~ $#nvram 1)
				echo 'nvram='^$nvram
			if(~ $#mouseport 1)
				echo 'mouseport='^$mouseport
			if(~ $#monitor 1)
				echo 'monitor='^$monitor
			if(~ $#vgasize 1)
				echo 'vgasize='^$vgasize
			cd '#ec'
			for(i in *){
				echo -n $"i'='
				cat $i
				echo
			} | grep -v '(apm0|e820|bootfile|bootargs|bootscreen|nvram|mouseport|monitor|vgasize|cdboot)'
		} >/tmp/plan9.ini
	}

	# clean state
	rm -f /tmp/oldplan9.ini /tmp/pbs.bak
	unmount /n/9fat >[2]/dev/null

	if(! test -f /srv/dos)
		dossrv

	need9fatformat=yes
	if(~ `{fstype $9fat} dos){
		if(mount /srv/dos /n/9fat $9fat >[2]/dev/null){
			if(cp /n/9fat/plan9.ini /tmp/oldplan9.ini >[2]/dev/null)
				need9fatformat=no
			unmount /n/9fat >[2]/dev/null

			# make sure dossrv is gone
			sleep 1
		}
	}

	# always make backup of old bootsector
	logprog dd -bs 512 -count 1 -if $9fat -of /tmp/pbs.bak

	if (! test -f /386/pbs) {
		if(~ $need9fatformat yes){
			log Initializing Plan 9 FAT partition.
			logprog disk/format -r 2 -d -l PLAN9 $9fat
		}
	}
	if not {
		if(~ $need9fatformat yes){
			log Initializing Plan 9 FAT partition.
			logprog disk/format -r 2 -d -b /386/pbs -l PLAN9 $9fat
		}
		if not {
			log Updating bootsector.
			logprog disk/format -b /386/pbs $9fat
		}
	}

	logprog mount -c /srv/dos /n/9fat $9fat

	if(test -f /386/9bootfat) {
		logprog rm -f /n/9fat/9bootfat
		logprog cp /386/9bootfat /n/9fat/9bootfat

		# make file continous on disk
		logprog chmod +al /n/9fat/9bootfat
	}

	# copy config
	logprog rm -f /n/9fat/plan9.ini
	logprog cp /tmp/plan9.ini /n/9fat/plan9.ini

	# copy kernel
	if(~ $#bootfile 1){
		logprog rm -f /n/9fat/$bootfile
		logprog cp /$cputype/$bootfile /n/9fat/$bootfile
	}

	# copy efi bootloader
	for(i in /386/*.efi){
		if(test -f $i) {
			logprog mkdir -p /n/9fat/efi/boot
			logprog cp $i /n/9fat/efi/boot/
		}
	}

	# copy in backups
	if(test -f /tmp/oldplan9.ini)
		logprog cp /tmp/oldplan9.ini /n/9fat
	if(test -f /tmp/pbs.bak)
		logprog cp /tmp/pbs.bak /n/9fat

	logprog unmount /n/9fat

	disk=`{basename `{basename -d $9fat}}
	if(./bootplan9){
		didbootsetup=1
		export didbootsetup
	}
}