setup 15 KB

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