mountdist 4.8 KB

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