]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/inst/main
bd974658bcaa8c6659241398f7ca8888c5758b52
[plan9front.git] / rc / bin / inst / main
1 #!/bin/rc
2
3 . defs
4
5 while()
6 {
7 div=--------------------------------------
8 echo
9 echo $div
10 echo
11 echo -n 'Preparing menu...'
12
13 # must be topologically sorted (by prereq)
14 tasks=(\
15         systype\
16         configfs\
17         partdisk prepdisk\
18         mountfs\
19         configdist\
20         confignet\
21         mountdist\
22         download\
23         copydist\
24         authsetup\
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
31 pseudotasks=(configip havefiles etherup etherdown pppup pppdown)
32
33 for(i in $tasks $pseudotasks)
34         $i=notdone
35
36 coherence
37
38 for(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
50 done=()
51 ready=()
52 rm /env/done
53 rm /env/ready
54 for(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
85 export $tasks $pseudotasks done ready
86 coherence
87 echo
88
89 if(! ~ $#done 0) {
90         echo 'The following tasks are done: '
91         for(i in $done)
92                 desc $i
93         echo
94 }
95
96 echo 'The following unfinished tasks are ready to be done:'
97 for(i in $ready)
98         desc $i
99 echo
100
101 if(~ $#ready 0) {
102         echo hey you finished everything!  not supposed to happen.
103         sleep 100
104         exit
105 }
106
107 prompt -d $ready(1) -w '' 'Task to do' $done $ready
108
109 echo
110 echo $div
111
112 $rd go
113 $rd=done                # if it's not, the check will figure that out
114 export $rd
115 }