123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- #!/bin/sh
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- set -e
- vardir="$1"
- method=$2
- option=$3
- cd "$vardir/methods/disk"
- tp=/var/run/ddm$$
- iarch=`dpkg --admindir $vardir --print-architecture`
- xit=1
- trap '
- rm -f $tp.?
- if [ -n "$umount" ]
- then
- umount "$umount" >/dev/null 2>&1
- fi
- exit $xit
- ' 0
- if ls -d "$tp.?" >/dev/null 2>&1
- then
- rm $tp.?
- fi
- yesno () {
- while true
- do
- echo -n "$2 [$1] "
- read response
- if [ -z "$response" ]
- then
- response="$1"
- fi
- case "$response" in
- [Nn]*) yesno=no ; return ;;
- [Yy]*) yesno=yes ; return ;;
- esac
- done
- }
- print_partition_table()
- {
- device="$1"
- printf "p\nq\n" | fdisk "$device" 2>/dev/null
- }
- getblockdev () {
- mountpoint="$vardir/methods/mnt"
- if [ -z "$defaultdevice" ]
- then
- defaultdevice="$newdefaultdevice"
- elif [ "$defaultdevice" != "$newdefaultdevice" ]
- then
- echo \
- "Last time you specified installation from $defaultdevice."
- fi
- promptstring="$1"
- while [ -z "$blockdevice" ]
- do
- echo -n "$promptstring [$defaultdevice]: "
- read response
- if [ -z "$response" ]
- then
- response="$defaultdevice"
- fi
- if ! [ -b "$response" ]
- then
- echo "$response is not a block device."; continue
- fi
- tryblockdevice="$response"
- if [ $option = cdrom ]
- then
- fstype=iso9660
- elif [ $option = harddisk ]
- then
- blockbase="`echo \"$tryblockdevice\" | sed -e 's/[0-9]\{1,\}$//'`"
- set +e
- print_partition_table "$blockbase" >$tp.f
- set -e
- proposeddevice="$tryblockdevice" perl -ne '
- next unless /^ *Device +Boot +Start +End +Blocks +Id +System *$/i .. !/\S/;
- next unless s:^/\S+::p && ${^MATCH} eq $ENV{proposeddevice};
- next unless s/^ +(\* +)?\d+ +\d+ +\d+\+? +//;
- next unless m/^([0-9a-f]{1,2}) /i;
- %types= ( "1","msdos", "4","msdos", "6","msdos", "7","hpfs", "80","minix",
- "81","minix", "83","ext2" );
- print $types{$1}; exit(0); ' <$tp.f >$tp.m
- defaultfstype="`cat $tp.m`"
- if [ -n "$defaultfstype" ]
- then
- cat <<END
- The partition table for $blockbase claims that $tryblockdevice
- contains filesystem type $defaultfstype.
- END
- if ! grep " $defaultfstype$" /proc/filesystems >/dev/null
- then
- echo \
- "Your kernel does not appear to support that filesystem type."
- defaultfstype=""
- fi
- fi
- echo -n "Supported filesystems: "
- sed -e 's/^.* / /' /proc/filesystems | tr '\n' ' '
- echo -n "
- Enter filesystem type (for $tryblockdevice) [$defaultfstype]: "
- read fstype
- if [ -z "$fstype" ]
- then
- fstype="$defaultfstype"
- fi
- fi
- umount="$mountpoint"
- if mount -rt "$fstype" -o nosuid,nodev "$tryblockdevice" "$mountpoint"
- then
- echo
- blockdevice="$tryblockdevice"
- else
- umount=""
- echo \
- "Unable to mount $tryblockdevice on $mountpoint, type $fstype."
- fi
- done
- }
- outputparam () {
- echo "$2" | sed -e "s/'/'\\\\''/; s/^/$1='/; s/$/'/" >&3
- }
- intrkey="`stty -a | sed -n 's/.*intr = \([^;]*\);.*/\1/p'`"
- echo "
- If you make a mistake, use the interrupt key ($intrkey) to abort.
- "
- # State variables, “best first”
- # {main,ctb,nf,nus,lcl}_{packages,binary}
- # Empty before we've found them or if they're not available,
- # set to the relevant bit under mountpoint otherwise.
- # hierbase
- # A directory containing a Debian FTP site mirror tree for ONE distribution.
- # eg /pub/debian/dists/stable
- # mountpoint
- # The mountpoint for the filesystem containing the stuff
- # empty or unset if we don't know yet, or if we haven't mounted anything;
- # may also be empty if ‘directory’ was set.
- # blockdevice
- # The actual block device to mount.
- # fstype
- # The filesystem type to use.
- # defaultdevice
- # The default block device to mount.
- if [ -f shvar.$option ]
- then
- . ./shvar.$option
- defaultdevice="$p_blockdev"
- defaultnfsserver="$p_nfsserver"
- defaultnfsrempath="$p_nfsrempath"
- fi
- if [ $option = cdrom ]
- then
- mount >$tp.m
- sed -n 's/ ([^)]*)$//; s/^[^ ]* on //; s/ type iso9660$//p' <$tp.m >$tp.l
- ncdroms=`wc -l <$tp.l`
- if [ $ncdroms -gt 1 ]
- then
- response=""
- while [ -z "$response" ]
- do
- echo \
- 'Several CD-ROMs (or other ISO9660 filesystems) are mounted:'
- grep 'type iso9660 ([^)]*)$' <$tp.m | nl
- echo -n \
- "Is it any of these ? Type a number, or 'n' for none. "
- read response
- response="`echo \"$response\" | sed -e 's/[ ]*$//'`"
- if expr "$response" : '[0-9][0-9]*$' >/dev/null && \
- [ $response -ge 1 ] && [ $response -le $ncdroms ]
- then
- mountpoint="`sed -n $response'p' <$tp.l`"
- echo
- elif expr "$response" : '[Nn]' >/dev/null
- then
- mountpoint=""
- else
- response=""
- fi
- done
- elif [ $ncdroms = 1 ]
- then
- mountpoint="`cat $tp.l`"
- perl -ne 'print if s/ type iso9660 \([^)]*\)$// && s/ on .*$//;' \
- <$tp.m >$tp.d
- blockdevice="`cat $tp.d`"
- yesno yes \
- "I see a CD-ROM: $blockdevice, mounted on $mountpoint. Is it the right one ?"
- if [ $yesno = no ]
- then
- echo 'Unmounting it ...'
- umount="$mountpoint"
- while true
- do
- echo -n \
- 'Please insert the right disc, and hit return: '
- read response
- if mount -rt iso9660 -o nosuid,nodev \
- "$blockdevice" "$mountpoint"
- then
- echo
- break
- fi
- done
- fi
- fi
- if [ -z "$mountpoint" ]
- then
- if [ -b /dev/cdrom ]
- then
- echo \
- 'I see that /dev/cdrom exists and is a block device.'
- newdefaultdevice=/dev/cdrom
- fi
- getblockdev 'Insert the CD-ROM and enter the block device name'
- fi
- fi
- if [ $option = nfs ]
- then
- mountpoint="$vardir/methods/mnt"
- while [ -z "$nfsserver" ]
- do
- echo -n \
- "What is the name of the NFS server ? [$defaultnfsserver] "
- read response
- if [ -z "$response" ] && [ -n "$defaultnfsserver" ]
- then
- response="$defaultnfsserver"
- fi
- if [ -z "$response" ]; then continue; fi
- if [ -x "`which rpcinfo`" ]
- then
- if rpcinfo -u "$response" mountd | grep -q 'ready'
- then
- nfsserver="$response"
- else
- echo "$response appears not to be an NFS server."
- fi
- elif [ -x "`which ping`" ]
- then
- if ping -q -c 1 "$response" | grep -q ', 1 packets received'
- then
- nfsserver="$response"
- else
- echo "$response appears to be down or nonexistent."
- fi
- else
- echo \
- "(I can't check that now because there is no rpcinfo or ping.)"
- nfsserver="$response"
- fi
- done
- while [ -z "$nfsrempath" ]
- do
- echo -n "
- What is the pathname on the NFS server of the filesystem with
- the Debian files? [$defaultnfsrempath] "
- read response
- if [ -z "$response" ] && [ -n "$defaultnfsrempath" ]
- then
- response="$defaultnfsrempath"
- else
- response="`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
- fi
- umount="$mountpoint"
- if mount -rt nfs -o nosuid,nodev "$nfsserver:$response" "$mountpoint"
- then
- echo
- nfsrempath="$response"
- else
- umount=""
- echo \
- "Unable to mount NFS filesystem $nfsserver:$response."
- fi
- done
- nfs="$nfsserver:$nfsrempath"
- fi
- if [ $option = harddisk ]
- then
- set +e
- print_partition_table /dev/hda >$tp.f
- if [ $? != 0 ]
- then
- print_partition_table /dev/sda >$tp.f
- fi
- set -e
- perl -ne '
- next unless /^ *Device +Boot +Start +End +Blocks +Id +System *$/i .. !/\S/;
- next unless / [146] +DOS \d+-bit \S+$/;
- next unless m:^/\S+:p;
- print ${^MATCH}; ' <$tp.f >$tp.d
- newdefaultdevice="`cat $tp.d`"
- echo "
- I need to know which disk partition contains the distribution files;
- disk partitions are specified by the block device name in Linux."
- if [ -n "$newdefaultdevice" ]
- then
- echo \
- "By the way, $newdefaultdevice looks like a DOS partition."
- fi
- getblockdev "Enter the partition's block device name"
- fi
- if [ -n "$mountpoint" ]
- then
- # We must have $mountpoint
- if [ $option = cdrom ]
- then
- echo \
- 'All directory names should be entered relative to the root of the CD-ROM.
- '
- elif [ $option = nfs ]
- then
- echo \
- "All directory names should be entered relative to the root of the NFS
- filesystem, ie relative to $nfsrempath on the server.
- "
- else
- echo \
- "All directory names should be entered relative to the root of the
- $fstype filesystem on $blockdevice.
- "
- fi
- fi
- while true
- do
- if [ $option = cdrom ]
- then
- echo \
- "I would like to know where on the CD-ROM the top level of the Debian
- distribution is (eg. 'dists/stable') - this directory usually contains the
- Packages-Master file.
- If the CD-ROM is badly organised and doesn't have a straightforward copy of
- the distribution you may answer 'none' and we'll go through the parts
- I need individually."
- else
- echo \
- "In order to make it easy for me to find the relevant files I'd ideally
- like to install from a straightforward copy of the Debian distribution.
- To use this I'll need to know where the top level of that copy of the
- distribution is (eg. 'debian/dists/stable') - this directory usually
- contains the Packages-Master file.
- If you do not have a straightforward copy of the distribution available
- just answer 'none' and we'll go through the parts I need individually."
- fi
- defhierbase=none
- # maybe ask for debian/dists and then show and ask for available dists
- # eg. {stable,frozen,unstable,bo,hamm,slink}
- if [ -n "$p_hierbase" ]
- then
- if [ -d "$mountpoint/$p_hierbase/main/binary-$iarch" ]
- then
- echo "
- Last time you said '$p_hierbase', and that looks plausible."
- defhierbase="$p_hierbase"
- else
- echo "
- Last time you said '$p_hierbase', but that doesn't look plausible,
- since '$p_hierbase/main/binary-$iarch' doesn't seem to exist."
- fi
- fi
- if [ none = "$defhierbase" ]
- then
- if [ -d "$mountpoint/debian/dists/stable/main/binary-$iarch" ]
- then
- echo "
- '/debian/dists/stable' exists and looks plausible, so that's the default."
- defhierbase=/debian/dists/stable
- elif [ -d "$mountpoint/dists/stable/main/binary-$iarch" ]
- then
- echo "
- '/dists/stable' exists and looks plausible, so that's the default."
- defhierbase=/dists/stable
- fi
- fi
- echo -n \
- "Distribution top level ? [$defhierbase] "
- read response
- if [ -z "$response" ]
- then
- response="$defhierbase"
- fi
- if [ none = "$response" ]
- then
- hierbase=""
- break
- elif [ -d "$mountpoint/$response/main/binary-$iarch" ]
- then
- hierbase="`echo \"$response\" | sed -e 's:/*$::; s:^/*:/:'`"
- break
- fi
- echo \
- "$response/main/binary-$iarch does not exist.
- "
- done
- case "$hierbase" in
- /* ) ;;
- '' ) ;;
- * ) hierbase="/$hierbase" ;;
- esac
- check_binary () {
- # args: area-in-messages directory
- # eg: main "$hierbase/main/binary-$iarch"
- # checks whether $2 contains *.deb
- if ! [ -d "$mountpoint$2/" ]
- then
- echo "'$2' does not exist."
- return
- fi
- if ! ( find -L "$mountpoint$2/" -name '*.deb' -print \
- | head -n 1 ) 2>/dev/null | grep . >/dev/null
- then
- echo "'$2' does not contain any *.deb packages. Hmmpf."
- return
- fi
- echo "Using '$2' as $1 binary dir."
- this_binary="$2"
- }
- find_area () {
- # args: area-in-messages area-in-vars subdirectory-in-hier
- # last-time-binary last-time-packages
- # eg: main main main
- # "$p_main_binary" "$p_main_packages"
- this_binary=''
- this_packages=''
- if [ -n "$hierbase" ]
- then
- check_binary $1 "$hierbase/$3/binary-$iarch"
- fi
- if [ $option = cdrom ] && [ $2 = nf ] && [ -z "$this_binary" ]
- then
- echo "
- Note: most CD-ROM distributions of Debian do not include programs
- available in the 'non-free' directory of the distribution site.
- This is because these programs have copyrights that prevent
- distribution for profit on a CD-ROM - ie they are not free software.
- If you wish to install these programs you'll have to get them from an
- alternative source."
- elif [ $2 = lcl ] && [ -z "$this_binary" ]
- then
- echo "
- Note: By default there is no 'local' directory. It is intended for
- packages you made yourself."
- fi
- while [ -z "$this_binary" ]
- do
- defaultbinary="$4"
- echo "
- Which directory contains the *.deb packages from the $1 distribution
- area (this directory is named '$3/binary-$iarch' on the distribution site) ?
- Say 'none' if this area is not available."
- if [ $2 != main ] && [ -z "$defaultbinary" ]
- then
- defaultbinary=none
- fi
- echo -n \
- "Enter _$1_ binary dir. [$4]
- ? "
- read response
- if [ -z "$response" ] && [ -n "$defaultbinary" ]
- then
- response="$defaultbinary"
- fi
- if [ none = "$response" ]
- then
- break
- fi
- case "$response" in
- '' | none) continue ;;
- esac
- check_binary $1 "`echo \"$response\" | sed -e 's:/$::; s:^/*:/:'`"
- done
- if [ -n "$this_binary" ]
- then
- for f in Packages.gz packages.gz Packages packages
- do
- if [ -f "$mountpoint/$this_binary/$f" ]
- then
- echo "Using '$this_binary/$f' for $1."
- this_packages="$this_binary/$f"
- break
- fi
- done
- while [ -z "$this_packages" ]
- do
- echo -n "
- I can't find the $1 'Packages' file. The information in the
- 'Packages' file is important for package selection during new
- installations, and is very useful for upgrades.
- If you overlooked it when downloading you should do get it now and
- return to this installation procedure when you have done so: you will
- find one Packages file and one Packages.gz file -- either will do --
- in the 'binary-$iarch' subdirectory of each area on the FTP sites and
- CD-ROMs. Alternatively (and this will be rather slow) I can scan the
- packages in the distribution area - say 'scan' if you want me to do so.
- You need a separate Packages file from each of the distribution areas
- you wish to install.
- Where is the _$1_ 'Packages' file (if none is available, say 'none')
- [$5]
- ? "
- read response
- if [ -z "$response" ] && [ -n "$5" ]
- then
- response="$5"
- fi
- case "$response" in
- '') continue ;;
- none) break ;;
- scan) this_packages=scan ;;
- /*) this_packages="$response" ;;
- *) this_packages="/$response" ;;
- esac
- done
- fi
- eval $2'_binary="$this_binary"'
- eval $2'_packages="$this_packages"'
- }
- find_area main main main "$p_main_binary" "$p_main_packages"
- find_area contrib ctb contrib "$p_ctb_binary" "$p_ctb_packages"
- find_area non-free nf non-free "$p_nf_binary" "$p_nf_packages"
- find_area non-US nus non-US "$p_nus_binary" "$p_nus_packages"
- find_area local lcl local "$p_lcl_binary" "$p_lcl_packages"
- echo -n '
- Hit RETURN to continue. '
- read response
- exec 3>shvar.$option.new
- outputparam p_blockdev "$blockdevice"
- outputparam p_fstype "$fstype"
- outputparam p_mountpoint "$mountpoint"
- outputparam p_nfsserver "$nfsserver"
- outputparam p_nfsrempath "$nfsrempath"
- outputparam p_nfs "$nfs"
- outputparam p_hierbase "$hierbase"
- outputparam p_main_packages "$main_packages"
- outputparam p_main_binary "$main_binary"
- outputparam p_ctb_packages "$ctb_packages"
- outputparam p_ctb_binary "$ctb_binary"
- outputparam p_nf_packages "$nf_packages"
- outputparam p_nf_binary "$nf_binary"
- outputparam p_nus_packages "$nus_packages"
- outputparam p_nus_binary "$nus_binary"
- outputparam p_lcl_packages "$lcl_packages"
- outputparam p_lcl_binary "$lcl_binary"
- mv shvar.$option.new shvar.$option
- xit=0
|