setup 14 KB

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