mountdist 4.8 KB

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