disk.setup 14 KB

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