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.
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.
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/>.
21 cd "$vardir/methods/disk"
24 iarch=`dpkg --admindir $vardir --print-architecture`
31 umount "$umount" >/dev/null 2>&1
36 if ls -d "$tp.?" >/dev/null 2>&1
51 [Nn]*) yesno=no ; return ;;
52 [Yy]*) yesno=yes ; return ;;
57 print_partition_table()
61 printf "p\nq\n" | fdisk "$device" 2>/dev/null
65 mountpoint="$vardir/methods/mnt"
66 if [ -z "$defaultdevice" ]
68 defaultdevice="$newdefaultdevice"
69 elif [ "$defaultdevice" != "$newdefaultdevice" ]
72 "Last time you specified installation from $defaultdevice."
75 while [ -z "$blockdevice" ]
77 echo -n "$promptstring [$defaultdevice]: "
81 response="$defaultdevice"
83 if ! [ -b "$response" ]
85 echo "$response is not a block device."; continue
87 tryblockdevice="$response"
88 if [ $option = cdrom ]
91 elif [ $option = harddisk ]
93 blockbase="`echo \"$tryblockdevice\" | sed -e 's/[0-9]\{1,\}$//'`"
95 print_partition_table "$blockbase" >$tp.f
97 proposeddevice="$tryblockdevice" perl -ne '
98 next unless /^ *Device +Boot +Start +End +Blocks +Id +System *$/i .. !/\S/;
99 next unless s:^/\S+::p && ${^MATCH} eq $ENV{proposeddevice};
100 next unless s/^ +(\* +)?\d+ +\d+ +\d+\+? +//;
101 next unless m/^([0-9a-f]{1,2}) /i;
102 %types= ( "1","msdos", "4","msdos", "6","msdos", "7","hpfs", "80","minix",
103 "81","minix", "83","ext2" );
104 print $types{$1}; exit(0); ' <$tp.f >$tp.m
105 defaultfstype="`cat $tp.m`"
106 if [ -n "$defaultfstype" ]
109 The partition table for $blockbase claims that $tryblockdevice
110 contains filesystem type $defaultfstype.
112 if ! grep " $defaultfstype$" /proc/filesystems >/dev/null
115 "Your kernel does not appear to support that filesystem type."
119 echo -n "Supported filesystems: "
120 sed -e 's/^.* / /' /proc/filesystems | tr '\n' ' '
122 Enter filesystem type (for $tryblockdevice) [$defaultfstype]: "
126 fstype="$defaultfstype"
130 if mount -rt "$fstype" -o nosuid,nodev "$tryblockdevice" "$mountpoint"
133 blockdevice="$tryblockdevice"
137 "Unable to mount $tryblockdevice on $mountpoint, type $fstype."
143 echo "$2" | sed -e "s/'/'\\\\''/; s/^/$1='/; s/$/'/" >&3
146 intrkey="`stty -a | sed -n 's/.*intr = \([^;]*\);.*/\1/p'`"
148 If you make a mistake, use the interrupt key ($intrkey) to abort.
151 # State variables, “best first”
152 # {main,ctb,nf,nus,lcl}_{packages,binary}
153 # Empty before we've found them or if they're not available,
154 # set to the relevant bit under mountpoint otherwise.
156 # A directory containing a Debian FTP site mirror tree for ONE distribution.
157 # eg /pub/debian/dists/stable
159 # The mountpoint for the filesystem containing the stuff
160 # empty or unset if we don't know yet, or if we haven't mounted anything;
161 # may also be empty if ‘directory’ was set.
163 # The actual block device to mount.
165 # The filesystem type to use.
167 # The default block device to mount.
169 if [ -f shvar.$option ]
172 defaultdevice="$p_blockdev"
173 defaultnfsserver="$p_nfsserver"
174 defaultnfsrempath="$p_nfsrempath"
177 if [ $option = cdrom ]
180 sed -n 's/ ([^)]*)$//; s/^[^ ]* on //; s/ type iso9660$//p' <$tp.m >$tp.l
181 ncdroms=`wc -l <$tp.l`
182 if [ $ncdroms -gt 1 ]
185 while [ -z "$response" ]
188 'Several CD-ROMs (or other ISO9660 filesystems) are mounted:'
189 grep 'type iso9660 ([^)]*)$' <$tp.m | nl
191 "Is it any of these ? Type a number, or 'n' for none. "
193 response="`echo \"$response\" | sed -e 's/[ ]*$//'`"
194 if expr "$response" : '[0-9][0-9]*$' >/dev/null && \
195 [ $response -ge 1 ] && [ $response -le $ncdroms ]
197 mountpoint="`sed -n $response'p' <$tp.l`"
199 elif expr "$response" : '[Nn]' >/dev/null
206 elif [ $ncdroms = 1 ]
208 mountpoint="`cat $tp.l`"
209 perl -ne 'print if s/ type iso9660 \([^)]*\)$// && s/ on .*$//;' \
211 blockdevice="`cat $tp.d`"
213 "I see a CD-ROM: $blockdevice, mounted on $mountpoint. Is it the right one ?"
216 echo 'Unmounting it ...'
221 'Please insert the right disc, and hit return: '
223 if mount -rt iso9660 -o nosuid,nodev \
224 "$blockdevice" "$mountpoint"
232 if [ -z "$mountpoint" ]
237 'I see that /dev/cdrom exists and is a block device.'
238 newdefaultdevice=/dev/cdrom
240 getblockdev 'Insert the CD-ROM and enter the block device name'
246 mountpoint="$vardir/methods/mnt"
247 while [ -z "$nfsserver" ]
250 "What is the name of the NFS server ? [$defaultnfsserver] "
252 if [ -z "$response" ] && [ -n "$defaultnfsserver" ]
254 response="$defaultnfsserver"
256 if [ -z "$response" ]; then continue; fi
257 if [ -x "`which rpcinfo`" ]
259 if rpcinfo -u "$response" mountd | grep -q 'ready'
261 nfsserver="$response"
263 echo "$response appears not to be an NFS server."
265 elif [ -x "`which ping`" ]
267 if ping -q -c 1 "$response" | grep -q ', 1 packets received'
269 nfsserver="$response"
271 echo "$response appears to be down or nonexistent."
275 "(I can't check that now because there is no rpcinfo or ping.)"
276 nfsserver="$response"
279 while [ -z "$nfsrempath" ]
282 What is the pathname on the NFS server of the filesystem with
283 the Debian files? [$defaultnfsrempath] "
285 if [ -z "$response" ] && [ -n "$defaultnfsrempath" ]
287 response="$defaultnfsrempath"
289 response="`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
292 if mount -rt nfs -o nosuid,nodev "$nfsserver:$response" "$mountpoint"
295 nfsrempath="$response"
299 "Unable to mount NFS filesystem $nfsserver:$response."
302 nfs="$nfsserver:$nfsrempath"
305 if [ $option = harddisk ]
308 print_partition_table /dev/hda >$tp.f
311 print_partition_table /dev/sda >$tp.f
315 next unless /^ *Device +Boot +Start +End +Blocks +Id +System *$/i .. !/\S/;
316 next unless / [146] +DOS \d+-bit \S+$/;
317 next unless m:^/\S+:p;
318 print ${^MATCH}; ' <$tp.f >$tp.d
319 newdefaultdevice="`cat $tp.d`"
321 I need to know which disk partition contains the distribution files;
322 disk partitions are specified by the block device name in Linux."
323 if [ -n "$newdefaultdevice" ]
326 "By the way, $newdefaultdevice looks like a DOS partition."
328 getblockdev "Enter the partition's block device name"
331 if [ -n "$mountpoint" ]
333 # We must have $mountpoint
334 if [ $option = cdrom ]
337 'All directory names should be entered relative to the root of the CD-ROM.
339 elif [ $option = nfs ]
342 "All directory names should be entered relative to the root of the NFS
343 filesystem, ie relative to $nfsrempath on the server.
347 "All directory names should be entered relative to the root of the
348 $fstype filesystem on $blockdevice.
355 if [ $option = cdrom ]
358 "I would like to know where on the CD-ROM the top level of the Debian
359 distribution is (eg. 'dists/stable') - this directory usually contains the
360 Packages-Master file.
362 If the CD-ROM is badly organised and doesn't have a straightforward copy of
363 the distribution you may answer 'none' and we'll go through the parts
364 I need individually."
367 "In order to make it easy for me to find the relevant files I'd ideally
368 like to install from a straightforward copy of the Debian distribution.
369 To use this I'll need to know where the top level of that copy of the
370 distribution is (eg. 'debian/dists/stable') - this directory usually
371 contains the Packages-Master file.
373 If you do not have a straightforward copy of the distribution available
374 just answer 'none' and we'll go through the parts I need individually."
377 # maybe ask for debian/dists and then show and ask for available dists
378 # eg. {stable,frozen,unstable,bo,hamm,slink}
379 if [ -n "$p_hierbase" ]
381 if [ -d "$mountpoint/$p_hierbase/main/binary-$iarch" ]
384 Last time you said '$p_hierbase', and that looks plausible."
385 defhierbase="$p_hierbase"
388 Last time you said '$p_hierbase', but that doesn't look plausible,
389 since '$p_hierbase/main/binary-$iarch' doesn't seem to exist."
392 if [ none = "$defhierbase" ]
394 if [ -d "$mountpoint/debian/dists/stable/main/binary-$iarch" ]
397 '/debian/dists/stable' exists and looks plausible, so that's the default."
398 defhierbase=/debian/dists/stable
399 elif [ -d "$mountpoint/dists/stable/main/binary-$iarch" ]
402 '/dists/stable' exists and looks plausible, so that's the default."
403 defhierbase=/dists/stable
407 "Distribution top level ? [$defhierbase] "
409 if [ -z "$response" ]
411 response="$defhierbase"
413 if [ none = "$response" ]
417 elif [ -d "$mountpoint/$response/main/binary-$iarch" ]
419 hierbase="`echo \"$response\" | sed -e 's:/*$::; s:^/*:/:'`"
423 "$response/main/binary-$iarch does not exist.
431 * ) hierbase="/$hierbase" ;;
435 # args: area-in-messages directory
436 # eg: main "$hierbase/main/binary-$iarch"
437 # checks whether $2 contains *.deb
438 if ! [ -d "$mountpoint$2/" ]
440 echo "'$2' does not exist."
444 if ! ( find -L "$mountpoint$2/" -name '*.deb' -print \
445 | head -n 1 ) 2>/dev/null | grep . >/dev/null
447 echo "'$2' does not contain any *.deb packages. Hmmpf."
450 echo "Using '$2' as $1 binary dir."
455 # args: area-in-messages area-in-vars subdirectory-in-hier
456 # last-time-binary last-time-packages
458 # "$p_main_binary" "$p_main_packages"
462 if [ -n "$hierbase" ]
464 check_binary $1 "$hierbase/$3/binary-$iarch"
467 if [ $option = cdrom ] && [ $2 = nf ] && [ -z "$this_binary" ]
470 Note: most CD-ROM distributions of Debian do not include programs
471 available in the 'non-free' directory of the distribution site.
472 This is because these programs have copyrights that prevent
473 distribution for profit on a CD-ROM - ie they are not free software.
474 If you wish to install these programs you'll have to get them from an
476 elif [ $2 = lcl ] && [ -z "$this_binary" ]
479 Note: By default there is no 'local' directory. It is intended for
480 packages you made yourself."
482 while [ -z "$this_binary" ]
486 Which directory contains the *.deb packages from the $1 distribution
487 area (this directory is named '$3/binary-$iarch' on the distribution site) ?
488 Say 'none' if this area is not available."
489 if [ $2 != main ] && [ -z "$defaultbinary" ]
494 "Enter _$1_ binary dir. [$4]
497 if [ -z "$response" ] && [ -n "$defaultbinary" ]
499 response="$defaultbinary"
501 if [ none = "$response" ]
506 '' | none) continue ;;
508 check_binary $1 "`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
510 if [ -n "$this_binary" ]
512 for f in Packages.gz packages.gz Packages packages
514 if [ -f "$mountpoint/$this_binary/$f" ]
516 echo "Using '$this_binary/$f' for $1."
517 this_packages="$this_binary/$f"
521 while [ -z "$this_packages" ]
524 I can't find the $1 'Packages' file. The information in the
525 'Packages' file is important for package selection during new
526 installations, and is very useful for upgrades.
528 If you overlooked it when downloading you should do get it now and
529 return to this installation procedure when you have done so: you will
530 find one Packages file and one Packages.gz file -- either will do --
531 in the 'binary-$iarch' subdirectory of each area on the FTP sites and
532 CD-ROMs. Alternatively (and this will be rather slow) I can scan the
533 packages in the distribution area - say 'scan' if you want me to do so.
535 You need a separate Packages file from each of the distribution areas
538 Where is the _$1_ 'Packages' file (if none is available, say 'none')
542 if [ -z "$response" ] && [ -n "$5" ]
549 scan) this_packages=scan ;;
550 /*) this_packages="$response" ;;
551 *) this_packages="/$response" ;;
555 eval $2'_binary="$this_binary"'
556 eval $2'_packages="$this_packages"'
559 find_area main main main "$p_main_binary" "$p_main_packages"
560 find_area contrib ctb contrib "$p_ctb_binary" "$p_ctb_packages"
561 find_area non-free nf non-free "$p_nf_binary" "$p_nf_packages"
562 find_area non-US nus non-US "$p_nus_binary" "$p_nus_packages"
563 find_area local lcl local "$p_lcl_binary" "$p_lcl_packages"
566 Hit RETURN to continue. '
569 exec 3>shvar.$option.new
571 outputparam p_blockdev "$blockdevice"
572 outputparam p_fstype "$fstype"
573 outputparam p_mountpoint "$mountpoint"
574 outputparam p_nfsserver "$nfsserver"
575 outputparam p_nfsrempath "$nfsrempath"
576 outputparam p_nfs "$nfs"
577 outputparam p_hierbase "$hierbase"
579 outputparam p_main_packages "$main_packages"
580 outputparam p_main_binary "$main_binary"
581 outputparam p_ctb_packages "$ctb_packages"
582 outputparam p_ctb_binary "$ctb_binary"
583 outputparam p_nf_packages "$nf_packages"
584 outputparam p_nf_binary "$nf_binary"
585 outputparam p_nus_packages "$nus_packages"
586 outputparam p_nus_binary "$nus_binary"
587 outputparam p_lcl_packages "$lcl_packages"
588 outputparam p_lcl_binary "$lcl_binary"
590 mv shvar.$option.new shvar.$option