mountdist 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. kfs=()
  63. fat=()
  64. ext2=()
  65. x9660=()
  66. fossil=()
  67. echo Please wait... Scanning storage devices...
  68. parts=`{ls /dev/sd??/* >[2]/dev/null | grep -v '/(plan9.*|ctl|log|raw)$'}
  69. for (i in $parts) {
  70. echo -n ' '^$i
  71. n=`{echo $i | sed 's;/;_;g'}
  72. if(! test -f /tmp/localpart.$n)
  73. dd -if $i -bs 2048 -count 32 -of /tmp/localpart.$n >[2]/dev/null
  74. if(iskfs /tmp/localpart.$n)
  75. kfs=($kfs $i)
  76. if(isfat /tmp/localpart.$n)
  77. fat=($fat $i)
  78. # if(isext2 /tmp/localpart.$n)
  79. # ext2=($ext2 $i)
  80. if(is9660 /tmp/localpart.$n)
  81. x9660=($x9660 $i)
  82. if(isfossil /tmp/localpart.$n)
  83. fossil=($fossil $i)
  84. echo
  85. }
  86. echo
  87. echo The following storage media were detected.
  88. echo Choose the one containing the distribution.
  89. echo
  90. for(i in $parts){
  91. switch($i){
  92. case $kfs
  93. echo ' '^$i^' (plan9 kfs)'
  94. case $fat
  95. echo ' '^$i^' (microsoft fat)'
  96. case $ext2
  97. echo ' '^$i^' (linux ext2)'
  98. case $x9660
  99. echo ' '^$i^' (iso9660 cdrom)'
  100. case $fossil
  101. echo ' '^$i^' (plan9 fossil)'
  102. }
  103. }
  104. echo
  105. mountstatus=x
  106. while(! ~ $mountstatus ''){
  107. prompt -w '' 'Distribution disk' $fat $x9660 $fossil
  108. disk=$rd
  109. srvmedia=()
  110. mountmedia=()
  111. switch($disk){
  112. case $fs
  113. mountmedia=(bind /n/newfs /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 $fat
  119. srvmedia=(dossrv)
  120. mountmedia=(mount /srv/dos /n/distmedia $disk)
  121. case $ext2
  122. srvmedia=(ext2srv -r)
  123. mountmedia=(mount /srv/ext2 /n/distmedia $disk)
  124. case $x9660
  125. srvmedia=(9660srv)
  126. mountmedia=(mount /srv/9660 /n/distmedia $disk)
  127. case $fossil
  128. echo 'srv fossil.mountdist' > /tmp/fossi.conf
  129. echo 'fsys main config '^$disk >> /tmp/fossil.conf
  130. echo 'fsys main open -AWVP' >> /tmp/fossil.conf
  131. echo 'fsys main' >> /tmp/fossil.conf
  132. srvmedia=(fossil/fossil -c '. /tmp/fossil.conf')
  133. mountmedia=(mount /srv/fossil.mountdist /n/distmedia)
  134. case *
  135. echo Unknown disk type '(cannot happen)'
  136. exit oops
  137. }
  138. export srvmedia mountmedia
  139. domount
  140. mountstatus=$status
  141. }
  142. first=yes
  143. dir=/
  144. while(~ $first yes || ! havedist /n/distmedia/$dir){
  145. if(~ $first yes){
  146. echo
  147. echo Which directory contains the distribution?
  148. echo 'Any of the following will suffice (in order of preference):'
  149. echo ' - the root directory of the cd image'
  150. echo ' - the directory containing plan9.iso'
  151. echo ' - the directory containing plan9.iso.bz2'
  152. echo 'Typing `browse'' will put you in a shell that you can use to'
  153. echo 'look for the directory.'
  154. echo
  155. first=no
  156. }
  157. prompt -d browse 'Location of archives'
  158. dir=$rd
  159. if(~ $dir browse){
  160. echo This is a simple shell. Commands are:
  161. echo ' cd directory - change to directory'
  162. echo ' lc - list contents of current directory'
  163. echo ' exit - exit shell'
  164. echo
  165. echo 'Move to the directory containing the distribution'
  166. echo 'and then exit.'
  167. echo
  168. oifs=$ifs
  169. ifs=$nl
  170. dir=`{cdsh -r /n/distmedia}
  171. ifs=$oifs
  172. }
  173. if(~ $#dir 0)
  174. dir=safdsfdsfdsf
  175. if(! ~ $#dir 1)
  176. dir=$"dir
  177. if(! havedist /n/distmedia/$dir)
  178. echo 'No distribution found in '^`{cleanname /$dir}
  179. }
  180. distmediadir=$dir
  181. export distmediadir
  182. case checkdone
  183. if(! ~ $#distmediadir 1){
  184. mountdist=notdone
  185. export mountdist
  186. exit notdone
  187. }
  188. if(! havedist /n/distmedia/$distmediadir && ! havedist /n/newfs/dist){
  189. mountdist=notdone
  190. export mountdist
  191. exit notdone
  192. }
  193. exitifdone
  194. if(test -f /n/distmedia/$distmediadir/dist/replica/plan9.db){
  195. bind /n/distmedia/$distmediadir /n/dist
  196. bind -a /n/dist/386/bin /bin
  197. bind -a /n/dist/rc/bin /bin
  198. exitifdone
  199. mountdist=notdone
  200. export mountdist
  201. exit notdone
  202. }
  203. trycdimage /n/distmedia/$distmediadir/plan9.iso
  204. trycdimage /n/newfs/dist/plan9.iso
  205. trycdimagebz2 /n/distmedia/$distmediadir/plan9.iso.bz2
  206. trycdimagebz2 /n/newfs/dist/plan9.iso.bz2
  207. mountdist=notdone
  208. export mountdist
  209. exit notdone
  210. }