disk.setup 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. #!/bin/sh
  2. set -e
  3. vardir="$1"
  4. method=$2
  5. option=$3
  6. cd "$vardir/methods/disk"
  7. tp=/tmp/ddm$$
  8. xit=1
  9. trap '
  10. rm -f $tp.?
  11. if [ -n "$umount" ]
  12. then
  13. umount "$umount" >/dev/null 2>&1
  14. fi
  15. exit $xit
  16. ' 0
  17. if ls -d "$tp.?" >/dev/null 2>&1
  18. then
  19. rm $tp.?
  20. fi
  21. yesno () {
  22. while true
  23. do
  24. echo -n "$2 [$1] "
  25. read response
  26. if [ -z "$response" ]
  27. then
  28. response="$1"
  29. fi
  30. case "$response" in
  31. [Nn]*) yesno=no ; return ;;
  32. [Yy]*) yesno=yes ; return ;;
  33. esac
  34. done
  35. }
  36. getblockdev () {
  37. mountpoint="$vardir/methods/mnt"
  38. if [ -z "$defaultdevice" ]
  39. then
  40. defaultdevice="$newdefaultdevice"
  41. elif [ "$defaultdevice" != "$newdefaultdevice" ]
  42. then
  43. echo \
  44. "Last time you specified installation from $defaultdevice."
  45. fi
  46. promptstring="$1"
  47. while [ -z "$blockdevice" ]
  48. do
  49. echo -n "$promptstring [$defaultdevice]: "
  50. read response
  51. if [ -z "$response" ]
  52. then
  53. response="$defaultdevice"
  54. fi
  55. if ! [ -b "$response" ]
  56. then
  57. echo "$response is not a block device."; continue
  58. fi
  59. tryblockdevice="$response"
  60. if [ $option = cdrom ]
  61. then
  62. fstype=iso9660
  63. elif [ $option = harddisk ]
  64. then
  65. blockbase="`echo \"$tryblockdevice\" | sed -e 's/[0-9]\{1,\}$//'`"
  66. set +e
  67. echo -e "p\nq\n" | fdisk "$blockbase" 2>/dev/null >$tp.f
  68. set -e
  69. proposeddevice="$tryblockdevice" perl -ne '
  70. next unless /^ *Device +Boot +Begin +Start +End +Blocks +Id +System *$/i .. !/\S/;
  71. next unless s:^/\S+:: && $& eq $ENV{"proposeddevice"};
  72. next unless s/^ +(\* +)?\d+ +\d+ +\d+ +\d+\+? +//;
  73. next unless m/^([0-9a-f]{1,2}) /i;
  74. %types= ( "1","msdos", "4","msdos", "6","msdos", "7","hpfs", "80","minix",
  75. "81","minix", "83","ext2" );
  76. print $types{$1}; exit(0); ' <$tp.f >$tp.m
  77. defaultfstype="`cat $tp.m`"
  78. if [ -n "$defaultfstype" ]
  79. then
  80. cat <<END
  81. The partition table for $blockbase claims that $tryblockdevice
  82. contains filesystem type $defaultfstype.
  83. END
  84. if ! grep " $defaultfstype$" /proc/filesystems >/dev/null
  85. then
  86. echo \
  87. "Your kernel does not appear to support that filesystem type."
  88. defaultfstype=""
  89. fi
  90. fi
  91. echo -n "Supported filesystems: "
  92. sed -e 's/^.* / /' /proc/filesystems | tr '\n' ' '
  93. echo -n "
  94. Enter filesystem type (for $tryblockdevice) [$defaultfstype]: "
  95. read fstype
  96. if [ -z "$fstype" ]
  97. then
  98. fstype="$defaultfstype"
  99. fi
  100. fi
  101. umount="$mountpoint"
  102. if mount -rt "$fstype" -o nosuid,nodev "$tryblockdevice" "$mountpoint"
  103. then
  104. echo
  105. blockdevice="$tryblockdevice"
  106. else
  107. umount=""
  108. echo \
  109. "Unable to mount $tryblockdevice on $mountpoint, type $fstype."
  110. fi
  111. done
  112. }
  113. outputparam () {
  114. echo "$2" | sed -e "s/'/'\\\\''/; s/^/$1='/; s/$/'/" >&3
  115. }
  116. intrkey="`stty -a | sed -n 's/.*intr = \([^;]*\);.*/\1/p'`"
  117. echo "
  118. If you make a mistake, use the interrupt key ($intrkey) to abort.
  119. "
  120. # State variables, `best first'
  121. # {main,ctb,nf,lcl}_{packages,binary}
  122. # Empty before we've found them or if they're not available,
  123. # set to the relevant bit under mountpoint otherwise.
  124. # hierbase
  125. # A directory containing a Debian FTP site mirror tree.
  126. # mountpoint
  127. # The mountpoint for the filesystem containing the stuff
  128. # empty or unset if we don't know yet, or if we haven't mounted anything;
  129. # may also be empty if `directory' was set.
  130. # blockdevice
  131. # The actual block device to mount.
  132. # fstype
  133. # The filesystem type to use.
  134. # defaultdevice
  135. # The default block device to mount.
  136. p_usedevel=no
  137. if [ -f shvar.$option ]
  138. then
  139. . ./shvar.$option
  140. defaultdevice="$p_blockdev"
  141. defaultnfsserver="$p_nfsserver"
  142. defaultnfsrempath="$p_nfsrempath"
  143. usedevel="$p_usedevel"
  144. fi
  145. if [ $option = cdrom ]
  146. then
  147. mount >$tp.m
  148. sed -n 's/ ([^)]*)$//; s/^[^ ]* on //; s/ type iso9660$//p' <$tp.m >$tp.l
  149. ncdroms=`wc -l <$tp.l`
  150. if [ $ncdroms -gt 1 ]
  151. then
  152. response=""
  153. while [ -z "$response" ]
  154. do
  155. echo \
  156. 'Several CD-ROMs (or other ISO9660 filesystems) are mounted:'
  157. egrep 'type iso9660 \([^)]*\)$' <$tp.m | nl
  158. echo -n \
  159. 'Is it any of these ? Type a number, or `n'\'' for none. '
  160. read response
  161. response="`echo \"$response\" | sed -e 's/[ ]*$//'`"
  162. if expr "$response" : '[0-9][0-9]*$' >/dev/null && \
  163. [ $response -ge 1 -a $response -le $ncdroms ]
  164. then
  165. mountpoint="`sed -n $response'p' <$tp.l`"
  166. echo
  167. elif expr "$response" : '[Nn]' >/dev/null
  168. then
  169. mountpoint=""
  170. else
  171. response=""
  172. fi
  173. done
  174. elif [ $ncdroms = 1 ]
  175. then
  176. mountpoint="`cat $tp.l`"
  177. perl -ne 'print if s/ type iso9660 \([^)]*\)$// && s/ on .*$//;' \
  178. <$tp.m >$tp.d
  179. blockdevice="`cat $tp.d`"
  180. yesno yes \
  181. "I see a CD-ROM: $blockdevice, mounted on $mountpoint. Is it the right one ?"
  182. if [ $yesno = no ]
  183. then
  184. echo 'Unmounting it ...'
  185. umount="$mountpoint"
  186. while true
  187. do
  188. echo -n \
  189. 'Please insert the right disc, and hit return: '
  190. read response
  191. if mount -rt iso9660 -o nosuid,nodev \
  192. "$blockdevice" "$mountpoint"
  193. then
  194. echo
  195. break
  196. fi
  197. done
  198. fi
  199. fi
  200. if [ -z "$mountpoint" ]
  201. then
  202. if [ -b /dev/cdrom ]
  203. then
  204. echo \
  205. 'I see that /dev/cdrom exists and is a block device.'
  206. newdefaultdevice=/dev/cdrom
  207. fi
  208. getblockdev 'Insert the CD-ROM and enter the block device name'
  209. fi
  210. fi
  211. if [ $option = nfs ]
  212. then
  213. mountpoint="$vardir/methods/mnt"
  214. while [ -z "$nfsserver" ]
  215. do
  216. echo -n \
  217. "What is the name of the NFS server ? [$defaultnfsserver] "
  218. read response
  219. if [ -z "$response" -a -n "$defaultnfsserver" ]
  220. then
  221. response="$defaultnfsserver"
  222. fi
  223. if [ -z "$response" ]; then continue; fi
  224. if [ -x /usr/bin/rpcinfo ]
  225. then
  226. if rpcinfo -u "$response" mountd >/dev/null
  227. then
  228. nfsserver="$response"
  229. else
  230. echo "$response appears not to be an NFS server."
  231. fi
  232. elif [ -x /bin/ping ]
  233. then
  234. if ping -q -c 1 "$response" | grep -q ', 1 packets received'
  235. then
  236. nfsserver="$response"
  237. else
  238. echo "$response appears to be down or nonexistent."
  239. fi
  240. else
  241. echo \
  242. "(I can't check that now because there is no /usr/bin/rpcinfo or /bin/ping.)"
  243. nfsserver="$response"
  244. fi
  245. done
  246. while [ -z "$nfsrempath" ]
  247. do
  248. echo -n "
  249. What is the pathname on the NFS server of the filesystem with
  250. the Debian files ? [$defaultnfsrempath] "
  251. read response
  252. if [ -z "$response" -a -n "$defaultnfsrempath" ]
  253. then
  254. response="$defaultnfsrempath"
  255. else
  256. response="`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
  257. fi
  258. umount="$mountpoint"
  259. if mount -rt nfs -o nosuid,nodev "$nfsserver:$response" "$mountpoint"
  260. then
  261. echo
  262. nfsrempath="$response"
  263. else
  264. umount=""
  265. echo \
  266. "Unable to mount NFS filesystem $nfsserver:$response."
  267. fi
  268. done
  269. nfs="$nfsserver:$nfsrempath"
  270. fi
  271. if [ $option = harddisk ]
  272. then
  273. set +e
  274. echo -e 'p\nq\n' | fdisk /dev/hda 2>/dev/null >$tp.f
  275. if [ $? != 0 ]
  276. then
  277. echo -e 'p\nq\n' | fdisk /dev/sda 2>/dev/null >$tp.f
  278. fi
  279. set -e
  280. perl -ne '
  281. next unless /^ *Device +Boot +Begin +Start +End +Blocks +Id +System *$/i .. !/\S/;
  282. next unless / [146] +DOS \d+-bit \S+$/;
  283. next unless m:^/\S+:;
  284. print $&; ' <$tp.f >$tp.d
  285. newdefaultdevice="`cat $tp.d`"
  286. echo "
  287. I need to know which disk partition contains the distribution files;
  288. disk partitions are specified by the block device name in Linux."
  289. if [ -n "$newdefaultdevice" ]
  290. then
  291. echo \
  292. "By the way, $newdefaultdevice looks like a DOS partition."
  293. fi
  294. getblockdev "Enter the partition's block device name"
  295. fi
  296. if [ -n "$mountpoint" ]
  297. then
  298. # We must have $mountpoint
  299. if [ $option = cdrom ]
  300. then
  301. echo \
  302. 'All directory names should be entered relative to the root of the CD-ROM.
  303. '
  304. elif [ $option = nfs ]
  305. then
  306. echo \
  307. "All directory names should be entered relative to the root of the NFS
  308. filesystem, ie relative to $nfsrempath on the server.
  309. "
  310. else
  311. echo \
  312. "All directory names should be entered relative to the root of the
  313. $fstype filesystem on $blockdevice.
  314. "
  315. fi
  316. fi
  317. while true
  318. do
  319. if [ $option = cdrom ]
  320. then
  321. echo \
  322. "I would like to know where on the CD-ROM the top level of the Debian
  323. distribution is - this will usually contain the Packages-Master file.
  324. If the CD-ROM is badly organised and doesn't have a straightforward copy of
  325. the distribution you may answer \`none' and we'll go through the parts
  326. I need individually."
  327. else
  328. echo \
  329. "In order to make it easy for me to find the relevant files I'd ideally
  330. like to install from a straightforward copy of the Debian distribution.
  331. To use this I'll need to know where the top level of that copy of the
  332. distribution is - this directory usually contains the Packages-Master file.
  333. If you do not have a straightforward copy of the distribution available
  334. just answer \`none' and we'll go through the parts I need individually."
  335. fi
  336. defhierbase=none
  337. if [ -n "$p_hierbase" ]
  338. then
  339. if [ -d "$mountpoint/$p_hierbase/stable/binary" ]
  340. then
  341. echo "
  342. Last time you said \`$p_hierbase', and that looks plausible."
  343. defhierbase="$p_hierbase"
  344. else
  345. echo "
  346. Last time you said \`$p_hierbase', but that doesn't look plausible,
  347. since \`$p_hierbase/stable/binary' doesn't seem to exist."
  348. fi
  349. fi
  350. if [ none = "$defhierbase" -a -d "$mountpoint/debian/stable/binary" ]
  351. then
  352. echo "
  353. \`/debian' exists and looks plausible, so that's the default."
  354. defhierbase=/debian
  355. fi
  356. echo -n \
  357. "Distribution top level ? [$defhierbase] "
  358. read response
  359. if [ -z "$response" ]
  360. then
  361. response="$defhierbase"
  362. fi
  363. if [ none = "$response" ]
  364. then
  365. hierbase=""
  366. break
  367. elif [ -d "$mountpoint/$response/stable/binary" ]
  368. then
  369. hierbase="`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
  370. break
  371. fi
  372. echo \
  373. "$response/stable/binary does not exist.
  374. "
  375. done
  376. whichmain=stable
  377. if [ -n "$hierbase" ]
  378. then
  379. if [ -d "$mountpoint/$hierbase/development/binary" ]
  380. then
  381. echo \
  382. '
  383. Both a stable released distribution and a work-in-progress
  384. development tree are available for installation. Would you like to
  385. use the unreleased development tree (this is only recommended for
  386. experts who like to live dangerously and want to help with testing) ?'
  387. yesno "$p_usedevel" 'Use unreleased development distribution ?'
  388. usedevel="$response"
  389. if [ "$usedevel" = yes ]
  390. then
  391. whichmain=development
  392. fi
  393. else
  394. usedevel=no
  395. fi
  396. echo
  397. fi
  398. check_binary () {
  399. # args: area-in-messages directory
  400. if ! [ -d "$mountpoint/$2" ]
  401. then
  402. echo "\`$2' does not exist."
  403. return
  404. fi
  405. if ! find "$mountpoint/$2" -follow -name '*.deb' -print \
  406. 2>/dev/null | head -1 | grep . >/dev/null
  407. then
  408. echo "\`$2' does not contain any *.deb packages. Hmmpf."
  409. return
  410. fi
  411. echo "Using \`$2' as $1 binary dir."
  412. this_binary="$2"
  413. }
  414. find_area () {
  415. # args: area-in-messages area-in-vars subdirectory-in-hier
  416. # last-time-binary last-time-packages
  417. this_binary=''
  418. this_packages=''
  419. if [ -n "$hierbase" ]
  420. then
  421. check_binary $1 "$hierbase/$3/binary"
  422. fi
  423. if [ $option = cdrom -a $2 = nf -a -z "$this_binary" ]
  424. then
  425. echo '
  426. Note: most CD-ROM distributions of Debian do not include programs
  427. available in the `non-free'\'' directory of the distribution site.
  428. This is because these programs have copyrights that prevent
  429. distribution for profit on a CD-ROM - ie they are not free software.
  430. If you wish to install these programs you'\''ll have to get them from an
  431. alternative source.'
  432. fi
  433. while [ -z "$this_binary" ]
  434. do
  435. defaultbinary="$4"
  436. echo "
  437. Which directory contains the *.deb packages from the $1 distribution
  438. area (this directory is named \`$3/binary' on the distribution site) ?"
  439. if [ $2 != main ]
  440. then
  441. if [ -z "$defaultbinary" ]
  442. then
  443. defaultbinary=none
  444. fi
  445. echo \
  446. "Say \`none' if this area is not available."
  447. fi
  448. echo -n \
  449. "Enter _$1_ binary dir. [$4]
  450. ? "
  451. read response
  452. if [ -z "$response" -a -n "$defaultbinary" ]
  453. then
  454. response="$defaultbinary"
  455. fi
  456. if [ none = "$response" -a $2 != main ]
  457. then
  458. break
  459. fi
  460. case "$response" in
  461. '' | none) continue ;;
  462. esac
  463. check_binary $1 "`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
  464. done
  465. if [ -n "$this_binary" ]
  466. then
  467. for f in Packages.gz packages.gz Packages packages
  468. do
  469. if [ -f "$mountpoint/$this_binary/$f" ]
  470. then
  471. echo "Using \`$this_binary/$f' for $1."
  472. this_packages="$this_binary/$f"
  473. break
  474. fi
  475. done
  476. while [ -z "$this_packages" ]
  477. do
  478. echo -n "
  479. I can't find the $1 \`Packages' file. The information in the
  480. \`Packages' file is important for package selection during new
  481. installations, and is very useful for upgrades.
  482. If you overlooked it when downloading you should do get it now and
  483. return to this installation procedure when you have done so: you will
  484. find one Packages file and one Packages.gz file -- either will do --
  485. in the \`binary' subdirectory of each area on the FTP sites and
  486. CD-ROMs.
  487. You need a separate Packages file from each of the distribution areas
  488. you wish to install.
  489. Where is the _$1_ \`Packages' file (if none is available, say\`none')
  490. [$5]
  491. ? "
  492. read response
  493. if [ -z "$response" -a -n "$5" ]
  494. then
  495. response="$5"
  496. fi
  497. case "$response" in
  498. '') continue ;;
  499. none) break ;;
  500. /*) this_packages="$response" ;;
  501. *) this_packages="/$response" ;;
  502. esac
  503. done
  504. fi
  505. eval $2'_binary="$this_binary"'
  506. eval $2'_packages="$this_packages"'
  507. }
  508. find_area main main "$whichmain" "$p_main_binary" "$p_main_packages"
  509. find_area contrib ctb contrib "$p_ctb_binary" "$p_ctb_packages"
  510. find_area non-free nf non-free "$p_nf_binary" "$p_nf_packages"
  511. find_area local lcl local "$p_lcl_binary" "$p_lcl_packages"
  512. echo -n '
  513. Hit RETURN to continue. '
  514. read response
  515. exec 3>shvar.$option.new
  516. outputparam p_blockdev "$blockdevice"
  517. outputparam p_fstype "$fstype"
  518. outputparam p_mountpoint "$mountpoint"
  519. outputparam p_nfsserver "$nfsserver"
  520. outputparam p_nfsrempath "$nfsrempath"
  521. outputparam p_nfs "$nfs"
  522. outputparam p_hierbase "$hierbase"
  523. outputparam p_usedevel "$usedevel"
  524. outputparam p_main_packages "$main_packages"
  525. outputparam p_main_binary "$main_binary"
  526. outputparam p_ctb_packages "$ctb_packages"
  527. outputparam p_ctb_binary "$ctb_binary"
  528. outputparam p_nf_packages "$nf_packages"
  529. outputparam p_nf_binary "$nf_binary"
  530. outputparam p_lcl_packages "$lcl_packages"
  531. outputparam p_lcl_binary "$lcl_binary"
  532. mv shvar.$option.new shvar.$option
  533. xit=0