disk.setup 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #!/bin/sh
  2. set -e
  3. vardir="$1"
  4. method=$2
  5. option=$3
  6. cd "$vardir/methods/disk"
  7. tp=/var/run/ddm$$
  8. iarch=`dpkg --admindir $vardir --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,nus,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 for ONE distribution.
  127. # eg /pub/debian/dists/stable
  128. # mountpoint
  129. # The mountpoint for the filesystem containing the stuff
  130. # empty or unset if we don't know yet, or if we haven't mounted anything;
  131. # may also be empty if `directory' was set.
  132. # blockdevice
  133. # The actual block device to mount.
  134. # fstype
  135. # The filesystem type to use.
  136. # defaultdevice
  137. # The default block device to mount.
  138. if [ -f shvar.$option ]
  139. then
  140. . ./shvar.$option
  141. defaultdevice="$p_blockdev"
  142. defaultnfsserver="$p_nfsserver"
  143. defaultnfsrempath="$p_nfsrempath"
  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. grep '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 ] && [ $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" ] && [ -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 | grep -q 'ready'
  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" ] && [ -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 (eg. 'dists/stable') - this directory usually contains the
  324. 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 (eg. 'debian/dists/stable') - this directory usually
  334. contains the Packages-Master file.
  335. If you do not have a straightforward copy of the distribution available
  336. just answer \`none' and we'll go through the parts I need individually."
  337. fi
  338. defhierbase=none
  339. # maybe ask for debian/dists and then show and ask for available dists
  340. # eg. {stable,frozen,unstable,bo,hamm,slink}
  341. if [ -n "$p_hierbase" ]
  342. then
  343. if [ -d "$mountpoint/$p_hierbase/main/binary-$iarch" ]
  344. then
  345. echo "
  346. Last time you said \`$p_hierbase', and that looks plausible."
  347. defhierbase="$p_hierbase"
  348. else
  349. echo "
  350. Last time you said \`$p_hierbase', but that doesn't look plausible,
  351. since \`$p_hierbase/main/binary-$iarch' doesn't seem to exist."
  352. fi
  353. fi
  354. if [ none = "$defhierbase" ]
  355. then
  356. if [ -d "$mountpoint/debian/dists/stable/main/binary-$iarch" ]
  357. then
  358. echo "
  359. \`/debian/dists/stable' exists and looks plausible, so that's the default."
  360. defhierbase=/debian/dists/stable
  361. elif [ -d "$mountpoint/dists/stable/main/binary-$iarch" ]
  362. then
  363. echo "
  364. \`/dists/stable' exists and looks plausible, so that's the default."
  365. defhierbase=/dists/stable
  366. fi
  367. fi
  368. echo -n \
  369. "Distribution top level ? [$defhierbase] "
  370. read response
  371. if [ -z "$response" ]
  372. then
  373. response="$defhierbase"
  374. fi
  375. if [ none = "$response" ]
  376. then
  377. hierbase=""
  378. break
  379. elif [ -d "$mountpoint/$response/main/binary-$iarch" ]
  380. then
  381. hierbase="`echo \"$response\" | sed -e 's:/*$::; s:^/*:/:'`"
  382. break
  383. fi
  384. echo \
  385. "$response/main/binary-$iarch does not exist.
  386. "
  387. done
  388. case "$hierbase" in
  389. /* ) ;;
  390. '' ) ;;
  391. * ) hierbase="/$hierbase" ;;
  392. esac
  393. check_binary () {
  394. # args: area-in-messages directory
  395. # eg: main "$hierbase/main/binary-$iarch"
  396. # checks wether $2 contains *.deb
  397. if ! [ -d "$mountpoint$2/" ]
  398. then
  399. echo "\`$2' does not exist."
  400. return
  401. fi
  402. if ! ( find "$mountpoint$2/" -follow -name '*.deb' -print \
  403. | head -n 1 ) 2>/dev/null | grep . >/dev/null
  404. then
  405. echo "\`$2' does not contain any *.deb packages. Hmmpf."
  406. return
  407. fi
  408. echo "Using \`$2' as $1 binary dir."
  409. this_binary="$2"
  410. }
  411. find_area () {
  412. # args: area-in-messages area-in-vars subdirectory-in-hier
  413. # last-time-binary last-time-packages
  414. # eg: main main main
  415. # "$p_main_binary" "$p_main_packages"
  416. this_binary=''
  417. this_packages=''
  418. if [ -n "$hierbase" ]
  419. then
  420. check_binary $1 "$hierbase/$3/binary-$iarch"
  421. fi
  422. if [ $option = cdrom ] && [ $2 = nf ] && [ -z "$this_binary" ]
  423. then
  424. echo '
  425. Note: most CD-ROM distributions of Debian do not include programs
  426. available in the `non-free'\'' directory of the distribution site.
  427. This is because these programs have copyrights that prevent
  428. distribution for profit on a CD-ROM - ie they are not free software.
  429. If you wish to install these programs you'\''ll have to get them from an
  430. alternative source.'
  431. elif [ $2 = lcl ] && [ -z "$this_binary" ]
  432. then
  433. echo '
  434. Note: By default there is no `local'\'' directory. It is intended for
  435. packages you made yourself.'
  436. fi
  437. while [ -z "$this_binary" ]
  438. do
  439. defaultbinary="$4"
  440. echo "
  441. Which directory contains the *.deb packages from the $1 distribution
  442. area (this directory is named \`$3/binary-$iarch' on the distribution site) ?
  443. Say \`none' if this area is not available."
  444. if [ $2 != main ] && [ -z "$defaultbinary" ]
  445. then
  446. defaultbinary=none
  447. fi
  448. echo -n \
  449. "Enter _$1_ binary dir. [$4]
  450. ? "
  451. read response
  452. if [ -z "$response" ] && [ -n "$defaultbinary" ]
  453. then
  454. response="$defaultbinary"
  455. fi
  456. if [ none = "$response" ]
  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-$iarch' subdirectory of each area on the FTP sites and
  486. CD-ROMs. Alternatively (and this will be rather slow) I can scan the
  487. packages in the distribution area - say \`scan' if you want me to do so.
  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" ] && [ -n "$5" ]
  495. then
  496. response="$5"
  497. fi
  498. case "$response" in
  499. '') continue ;;
  500. none) break ;;
  501. scan) this_packages=scan ;;
  502. /*) this_packages="$response" ;;
  503. *) this_packages="/$response" ;;
  504. esac
  505. done
  506. fi
  507. eval $2'_binary="$this_binary"'
  508. eval $2'_packages="$this_packages"'
  509. }
  510. find_area main main main "$p_main_binary" "$p_main_packages"
  511. find_area contrib ctb contrib "$p_ctb_binary" "$p_ctb_packages"
  512. find_area non-free nf non-free "$p_nf_binary" "$p_nf_packages"
  513. find_area non-US nus non-US "$p_nus_binary" "$p_nus_packages"
  514. find_area local lcl local "$p_lcl_binary" "$p_lcl_packages"
  515. echo -n '
  516. Hit RETURN to continue. '
  517. read response
  518. exec 3>shvar.$option.new
  519. outputparam p_blockdev "$blockdevice"
  520. outputparam p_fstype "$fstype"
  521. outputparam p_mountpoint "$mountpoint"
  522. outputparam p_nfsserver "$nfsserver"
  523. outputparam p_nfsrempath "$nfsrempath"
  524. outputparam p_nfs "$nfs"
  525. outputparam p_hierbase "$hierbase"
  526. outputparam p_main_packages "$main_packages"
  527. outputparam p_main_binary "$main_binary"
  528. outputparam p_ctb_packages "$ctb_packages"
  529. outputparam p_ctb_binary "$ctb_binary"
  530. outputparam p_nf_packages "$nf_packages"
  531. outputparam p_nf_binary "$nf_binary"
  532. outputparam p_nus_packages "$nus_packages"
  533. outputparam p_nus_binary "$nus_binary"
  534. outputparam p_lcl_packages "$lcl_packages"
  535. outputparam p_lcl_binary "$lcl_binary"
  536. mv shvar.$option.new shvar.$option
  537. xit=0