]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/inst/mountdist
bla
[plan9front.git] / rc / bin / inst / mountdist
1 #!/bin/rc
2
3 # prereq: mountfs configdist
4 # desc: locate and mount the distribution
5
6 fn domount{
7         if(! test -e $mountmedia(2))
8                 logprog $srvmedia
9         unmount /n/distmedia >[2]/dev/null
10         logprog $mountmedia
11 }
12
13 fn exitifdone{
14         if(test -f /n/dist/dist/replica/plan9.db)
15                 exit
16 }
17
18 fn trycdimage{
19         if(test -f $1){
20                 rm -f /srv/9660.dist
21                 unmount /n/dist
22                 9660srv 9660.dist >[2]/dev/null
23                 logprog mount /srv/9660.dist /n/dist $1
24                 exitifdone
25                 mountdist=notdone
26                 export mountdist
27                 exit notdone
28         }
29 }
30
31 fn trycdimagebz2 {
32         if(test -f $1){
33                 echo -n 'bunzip2 < '^$1^' >/n/newfs/dist/plan9.iso'
34                 bunzip2 < $1 >/n/newfs/dist/_plan9.iso &&
35                 mv /n/newfs/dist/_plan9.iso /n/newfs/dist/plan9.iso
36                 echo
37                 trycdimage /n/newfs/dist/plan9.iso
38                 mountdist=notdone
39                 export mountdist
40                 exit notdone
41         }
42 }
43
44 fn havedist {
45         test -f $1/dist/replica/plan9.db ||
46         test -f $1/plan9.iso ||
47         test -f $1/plan9.iso.bz2
48 }
49
50 switch($1){
51 case checkready
52         if(! ~ $distisfrom local && ! ~ $download done){
53                 mountdist=notdone
54                 export mountdist
55         }
56         if(! ~ $#mountmedia 0 1){
57                 if(domount){
58                         mountdist=done
59                         export mountdist
60                         if(mountdist checkdone)
61                                 exit
62                 }
63                 srvmedia=()
64                 mountmedia=()
65                 mountdist=ready
66                 export srvmedia mountmedia mountdist
67         }
68                 
69 case go
70         fat=()
71         ext2=()
72         x9660=()
73         fossil=()
74
75         echo Please wait... Scanning storage devices...
76
77         parts=`{ls /dev/sd??/* >[2]/dev/null | grep -v '/(plan9.*|ctl|log|raw)$'}
78         for (i in $parts) {
79                 echo -n '       '^$i
80                 n=`{echo $i | sed 's;/;_;g'}
81                 if(! test -f /tmp/localpart.$n)
82                         dd -if $i -bs 2048 -count 32 -of /tmp/localpart.$n >[2]/dev/null
83                 if(isfat /tmp/localpart.$n)
84                         fat=($fat $i)
85                 if(isext2 /tmp/localpart.$n)
86                         ext2=($ext2 $i)
87                 if(is9660 /tmp/localpart.$n)
88                         x9660=($x9660 $i)
89                 if(isfossil $i)
90                         fossil=($fossil $i)
91                 echo
92         }
93         echo
94         echo The following storage media were detected.
95         echo Choose the one containing the distribution.
96         echo
97         for(i in $parts){
98                 switch($i){
99                 case $fat
100                         echo    '       '^$i^' (microsoft fat)'
101                 case $ext2
102                         echo    '       '^$i^' (linux ext2)'
103                 case $x9660
104                         echo    '       '^$i^' (iso9660 cdrom)'
105                 case $fossil
106                         echo    '       '^$i^' (plan9 fossil)'
107                 }
108         }
109         echo
110
111         mountstatus=x
112         while(! ~ $mountstatus ''){
113                 prompt -w '' 'Distribution disk' $fat $x9660 $fossil
114                 disk=$rd
115
116                 srvmedia=()
117                 mountmedia=()
118                 switch($disk){
119                 case $fs
120                         mountmedia=(bind /n/newfs /n/distmedia)
121                 case $fat
122                         srvmedia=(dossrv)
123                         mountmedia=(mount /srv/dos /n/distmedia $disk)
124                 case $ext2
125                         srvmedia=(ext2srv -r)
126                         mountmedia=(mount /srv/ext2 /n/distmedia $disk)
127                 case $x9660
128                         srvmedia=(9660srv)
129                         mountmedia=(mount /srv/9660 /n/distmedia $disk)
130                 case $fossil
131                         echo 'srv fossil.mountdist' > /tmp/fossi.conf
132                         echo 'fsys main config '^$disk >> /tmp/fossil.conf
133                         echo 'fsys main open -AWVP' >> /tmp/fossil.conf
134                         echo 'fsys main' >> /tmp/fossil.conf
135                         srvmedia=(fossil/fossil -c '. /tmp/fossil.conf')
136                         mountmedia=(mount /srv/fossil.mountdist /n/distmedia)
137                 case *
138                         echo Unknown disk type '(cannot happen)'
139                         exit oops
140                 }
141                 export srvmedia mountmedia
142                 domount
143                 mountstatus=$status
144         }
145
146         first=yes
147         dir=/
148         while(~ $first yes || ! havedist /n/distmedia/$dir){
149                 if(~ $first yes){
150                         echo
151                         echo Which directory contains the distribution?
152                         echo 'Any of the following will suffice (in order of preference):'
153                         echo '  - the root directory of the cd image'
154                         echo '  - the directory containing plan9.iso'
155                         echo '  - the directory containing plan9.iso.bz2'
156                         echo 'Typing `browse'' will put you in a shell that you can use to'
157                         echo 'look for the directory.'
158                         echo
159                         first=no
160                 }
161
162                 prompt -d browse 'Location of archives'
163                 dir=$rd
164                 if(~ $dir browse){
165                         echo This is a simple shell.  Commands are:
166                         echo '  cd directory    - change to directory'
167                         echo '  lc                              - list contents of current directory'
168                         echo '  exit                    - exit shell'
169                         echo 
170                         echo 'Move to the directory containing the distribution'
171                         echo 'and then exit.'
172                         echo
173                         oifs=$ifs
174                         ifs=$nl
175                         dir=`{cdsh -r /n/distmedia}
176                         ifs=$oifs
177                 }
178                 if(~ $#dir 0)
179                         dir=safdsfdsfdsf
180                 if(! ~ $#dir 1)
181                         dir=$"dir
182                 if(! havedist /n/distmedia/$dir)
183                         echo 'No distribution found in '^`{cleanname /$dir}
184         }
185
186         distmediadir=$dir
187         export distmediadir
188
189 case checkdone
190         if(! ~ $#distmediadir 1){
191                 mountdist=notdone
192                 export mountdist
193                 exit notdone
194         }
195         if(! havedist /n/distmedia/$distmediadir && ! havedist /n/newfs/dist){
196                 mountdist=notdone
197                 export mountdist
198                 exit notdone
199         }
200
201         exitifdone
202
203         if(test -f /n/distmedia/$distmediadir/dist/replica/plan9.db){
204                 bind /n/distmedia/$distmediadir /n/dist
205                 bind -a /n/dist/386/bin /bin
206                 bind -a /n/dist/rc/bin /bin
207                 exitifdone
208                 mountdist=notdone
209                 export mountdist
210                 exit notdone
211         }
212
213         trycdimage /n/distmedia/$distmediadir/plan9.iso
214         trycdimage /n/newfs/dist/plan9.iso
215
216         trycdimagebz2 /n/distmedia/$distmediadir/plan9.iso.bz2
217         trycdimagebz2 /n/newfs/dist/plan9.iso.bz2
218
219         mountdist=notdone
220         export mountdist
221         exit notdone
222 }