1#!/bin/rc 2 3. defs 4 5while() 6{ 7div=-------------------------------------- 8echo 9echo $div 10echo 11echo -n 'Preparing menu...' 12 13# must be topologically sorted (by prereq) 14tasks=(\ 15 configfs\ 16 partdisk prepdisk\ 17 fmtfossil\ 18 mountfs\ 19 configdist\ 20 confignet\ 21 mountdist\ 22 fmtventi\ 23 download\ 24 copydist\ 25 bootsetup finish stop\ 26 stopether stopppp\ 27) 28# startether startppp stopether stopppp download\ 29 30# these don't show up in the menu but still matter 31pseudotasks=(configip havefiles etherup etherdown pppup pppdown) 32 33for(i in $tasks $pseudotasks) 34 $i=notdone 35 36coherence 37 38for(i in $tasks $pseudotasks) 39 if(~ $#$i 0) 40 $i=notdone 41 42# 43# we believe the environment about what is done 44# only if we've confirmed it. since the tasks list is sorted so that 45# prereqs of xxx come before xxx, it's okay to assume xxx 46# is done until proven otherwise -- either a prereq or checkdone 47# will say so. 48# 49 50done=() 51ready=() 52rm /env/done 53rm /env/ready 54for(i in $tasks) { 55 $i=done 56 for(j in `{prereq $i}) 57 if(! ~ $$j done) 58 $i=notdone 59 if(~ $$i done) { 60 export $i 61 $i checkdone 62 $i=`{grep '^'$i^'=' /tmp/vars | sed -n '$p' | sed 's/.*=//'} 63 } 64 65 if(~ $$i notdone ready) { 66 okay=yes 67 for(j in `{prereq $i}) 68 if(! ~ $$j done) 69 okay=no 70 switch($okay){ 71 case yes 72 $i=ready 73 export $i 74 $i checkready 75 $i=`{grep '^'$i^'=' /tmp/vars | sed -n '$p' | sed 's/.*=//'} 76 case no 77 $i=notdone 78 } 79 } 80 81 if(~ $$i done ready) 82 $$i=($$$i $i) # rc can be just as complicated as perl! 83} 84 85export $tasks $pseudotasks done ready 86coherence 87echo 88 89if(! ~ $#done 0) { 90 echo 'The following tasks are done: ' 91 for(i in $done) 92 desc $i 93 echo 94} 95 96echo 'The following unfinished tasks are ready to be done:' 97for(i in $ready) 98 desc $i 99echo 100 101if(~ $#ready 0) { 102 echo hey you finished everything! not supposed to happen. 103 sleep 100 104 exit 105} 106 107prompt -d $ready(1) -w '' 'Task to do' $done $ready 108 109echo 110echo $div 111 112$rd go 113$rd=done # if it's not, the check will figure that out 114export $rd 115} 116