summaryrefslogtreecommitdiff
path: root/rc/bin/inst/main
blob: 4a3eb8bf869233c6e04c6d47dc3271295a27b220 (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
#!/bin/rc

. ./defs

while()
{
div=--------------------------------------
echo
echo $div
echo
echo -n 'Preparing menu...'

# must be topologically sorted (by prereq)
tasks=(\
	configfs\
	partdisk prepdisk\
	mountfs\
	configdist\
	confignet\
	mountdist\
	download\
	copydist\
	ndbsetup\
	tzsetup\
	bootsetup\
	finish\
)

# these don't show up in the menu but still matter
pseudotasks=(havefiles etherup etherdown pppup pppdown)

for(i in $tasks $pseudotasks)
	$i=notdone

coherence

for(i in $tasks $pseudotasks)
	if(~ $#$i 0)
		$i=notdone

#
# we believe the environment about what is done
# only if we've confirmed it.  since the tasks list is sorted so that
# prereqs of xxx come before xxx, it's okay to assume xxx
# is done until proven otherwise -- either a prereq or checkdone
# will say so.
#

done=()
ready=()
rm /env/done
rm /env/ready
for(i in $tasks) {
	$i=done
	for(j in `{prereq $i})
		if(! ~ $$j done)
			$i=notdone
	if(~ $$i done) {
		export $i
		./$i checkdone
		$i=`{grep '^'$i^'=' /tmp/vars | sed -n '$p' | sed 's/.*=//'}
	}

	if(~ $$i notdone ready) {
		okay=yes
		for(j in `{prereq $i}) 
			if(! ~ $$j done)
				okay=no
		switch($okay){
		case yes
			$i=ready
			export $i
			./$i checkready
			$i=`{grep '^'$i^'=' /tmp/vars | sed -n '$p' | sed 's/.*=//'}
		case no
			$i=notdone
		}
	}

	if(~ $$i done ready)
		$$i=($$$i $i)		# rc can be just as complicated as perl!
}

export $tasks $pseudotasks done ready
coherence
echo

if(! ~ $#done 0) {
	echo 'The following tasks are done: '
	for(i in $done)
		desc $i
	echo
}

echo 'The following unfinished tasks are ready to be done:'
for(i in $ready)
	desc $i
echo

if(~ $#ready 0) {
	echo hey you finished everything!  not supposed to happen.
	sleep 100
	exit
}

prompt -d $ready(1) -w '' 'Task to do' $done $ready

echo
echo $div

./$rd go
$rd=done		# if it's not, the check will figure that out
export $rd
}