shithub: riscv

ref: 0ee5d61b71baa6d76aea3b1257a507ba496fae4a
dir: /rc/bin/inst/main/

View raw version
#!/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
}