test: Generate the pkg-old.deb from controlled parts
[dpkg.git] / dselect / methods / media / setup.sh
blob5bf36422cd20d976256c84bf392c54a35a0d5e3d
1 #!/bin/sh
3 # Copyright © 1995-1998 Ian Jackson <ijackson@chiark.greenend.org.uk>
4 # Copyright © 1998 Heiko Schlittermann <hs@schlittermann.de>
5 # Copyright © 1998-1999 Martin Schulze <joey@infodrom.north.de>
7 # This is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 set -e
21 vardir="$1"
22 method=$2
23 option=$3
25 test -d "$vardir/methods/$method" || mkdir "$vardir/methods/$method"
26 cd "$vardir/methods/$method"
27 tp="$(mktemp --tmpdir $method.XXXXXXXXXX)"
29 iarch=$(dpkg --print-architecture)
30 dist=stable
32 xit=1
33 trap '
34 rm -f $tp.?
35 if [ -n "$umount" ]; then
36 umount "$umount" >/dev/null 2>&1
38 exit $xit
39 ' 0
41 if ls -d "$tp.?" >/dev/null 2>&1; then
42 rm $tp.?
45 #debug() { echo "DEBUG: $@"; }
46 debug() {
47 true
49 ismulti() {
50 debug $1 $2; test -e "$1/.disk/info" || test -e "$1$2/.disk/info"
53 # 1/ mountpoint
54 # 2/ hierarchy
55 getdisklabel () {
56 debug "$1" "$2"
57 if [ -f $1/.disk/info ]; then
58 echo -n $(head -1 "$1/.disk/info")
59 elif [ -f $1$2/.disk/info ]; then
60 echo -n $(head -1 "$1$2/.disk/info")
61 else
62 echo -n 'Non-Debian disc'
66 yesno () {
67 while true; do
68 echo -n "$2 [$1] "
69 read response
70 if [ -z "$response" ]; then
71 response="$1"
73 case "$response" in
74 [Nn]*)
75 yesno=no
76 return
78 [Yy]*)
79 yesno=yes
80 return
82 esac
83 done
86 getblockdev () {
87 mountpoint="$vardir/methods/mnt"
88 if [ -z "$defaultdevice" ]; then
89 defaultdevice="$newdefaultdevice"
90 elif [ "$defaultdevice" != "$newdefaultdevice" ]; then
91 echo "Last time you specified installation from $defaultdevice."
93 promptstring="$1"
94 while [ -z "$blockdevice" ]; do
95 echo -n "$promptstring [$defaultdevice]: "
96 read response
97 if [ -z "$response" ]; then
98 response="$defaultdevice"
100 if [ ! -b "$response" ]; then
101 echo "$response is not a block device - will try as loopback."
102 loop=",loop"
104 tryblockdevice="$response"
105 fstype=iso9660
106 umount="$mountpoint"
107 if mount -rt "$fstype" -o nosuid,nodev$loop "$tryblockdevice" "$mountpoint"
108 then
109 echo
110 blockdevice="$tryblockdevice"
111 else
112 umount=""
113 echo "Unable to mount $tryblockdevice on $mountpoint, type $fstype."
115 done
118 outputparam () {
119 echo "$2" | sed -e "s/'/'\\\\''/; s/^/$1='/; s/$/'/" >&3
122 ## MAIN
123 intrkey="$(stty -a | sed -n 's/.*intr = \([^;]*\);.*/\1/p')"
124 echo "
125 If you make a mistake, use the interrupt key ($intrkey) to abort.
128 # State variables, “best first”
129 # {main,ctb,nf,lcl}_{packages,binary}
130 # Empty before we've found them or if they're not available,
131 # set to the relevant bit under mountpoint otherwise.
132 # hierbase
133 # A directory containing a Debian FTP site mirror tree.
134 # mountpoint
135 # The mountpoint for the filesystem containing the stuff
136 # empty or unset if we don't know yet, or if we haven't mounted anything;
137 # may also be empty if ‘directory’ was set.
138 # blockdevice
139 # The actual block device to mount.
140 # fstype
141 # The filesystem type to use.
142 # defaultdevice
143 # The default block device to mount.
145 p_usedevel=no
146 if [ -f shvar.$option ]; then
147 . ./shvar.$option
148 defaultdevice="$p_blockdev"
149 usedevel="$p_usedevel"
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 ]; then
156 response=""
157 while [ -z "$response" ]; do
158 echo 'Several media discs (ISO9660 filesystems) are mounted:'
159 grep -E 'type iso9660 \([^)]*\)$' <$tp.m | nl
160 echo -n "Is it any of these ? Type a number, or 'n' for none. "
161 read response
162 response="$(echo "$response" | sed -e 's/[ ]*$//')"
163 if expr "$response" : '[0-9][0-9]*$' >/dev/null && \
164 [ $response -ge 1 -a $response -le $ncdroms ]; then
165 mountpoint="$(sed -n $response'p' <$tp.l)"
166 echo
167 elif expr "$response" : '[Nn]' >/dev/null; then
168 mountpoint=""
169 else
170 response=""
172 done
173 elif [ $ncdroms = 1 ]; then
174 mountpoint="$(cat $tp.l)"
175 perl -ne 'print if s/ type iso9660 \([^)]*\)$// && s/ on .*$//;' \
176 <$tp.m >$tp.d
177 blockdevice="$(cat $tp.d)"
178 yesno yes \
179 "Found a media disc: $blockdevice, mounted on $mountpoint. Is it the right one?"
180 if [ $yesno = no ]; then
181 echo 'Unmounting it ...'
182 umount="$mountpoint"
183 while true; do
184 echo -n 'Please insert the right disc, and hit return: '
185 read response
186 if mount -rt iso9660 -o nosuid,nodev \
187 "$blockdevice" "$mountpoint"; then
188 echo
189 break
191 done
194 if [ -z "$mountpoint" ]; then
195 if [ -b /dev/cdrom ]; then
196 echo 'Found that /dev/cdrom exists and is a block device.'
197 newdefaultdevice=/dev/cdrom
199 getblockdev 'Insert the media and enter the block device name'
202 if [ -n "$mountpoint" ]; then
203 # We must have $mountpoint
204 echo \
205 'All directory names should be entered relative to the root of the media disc.
209 # now try to get the users idea where the debian
210 # hierarchy start below the mointpoint
212 debug "mountpoint: $mountpoint"
213 while true; do
214 if ismulti "${mountpoint}" "${hierbase}"; then
215 multi=yes
218 echo \
219 "Need to know where on the media disc the top level of the Debian
220 distribution is - this will usually contain the 'dists' directory.
222 If the media disc is badly organized and doesn't have a straightforward copy of
223 the distribution you may answer 'none' and the needed parts will be prompted
224 individually."
226 defhierbase=none
227 if [ -n "$p_hierbase" ]; then
228 if [ -d "$mountpoint/$p_hierbase/dists/$dist/main/binary-$iarch" \
229 -o -n "$multi" ]; then
230 echo "Last time you said '$p_hierbase', and that looks plausible."
231 defhierbase="$p_hierbase"
232 else
233 echo "
234 Last time you said '$p_hierbase', but that doesn't look plausible,
235 since '$p_hierbase/dists/$dist/main/binary-$iarch' doesn't seem to exist.
236 And it does not appear that you are using a multiple media set."
240 # at this point defhierbase is set if it looks plausible
241 # if ‘none’ was entered, we assume a media with a debian/ directory
243 if [ none = "$defhierbase" -a -d "$mountpoint/debian/dists/$dist/main/binary-$iarch" ]
244 then
245 echo "'/debian' exists and looks plausible, so that's the default."
246 defhierbase=/debian
249 echo -n "Distribution top level ? [$defhierbase] "
250 read response
251 if [ -z "$response" ]; then
252 response="$defhierbase"
254 if [ none = "$response" ]; then
255 hierbase=""
256 break
257 elif ismulti "$mountpoint" "$response" && [ -z "$multi" ]; then
258 multi=yes
261 if ! [ -d "$mountpoint/$response/dists/$dist/main/binary-$iarch" \
262 -o -n "$multi" ]; then
263 echo \
264 "Neither $response/dists/$dist/main/binary-$iarch does not exist,
265 nor are you using a multiple media set"
266 break
269 hierbase="$(echo "$response" | sed -e 's:/$::; s:^/*:/:; s:/\+:/:g;')"
270 debug "hierbase: [$hierbase]"
272 if [ -n "$multi" ]; then
273 disklabel=$(getdisklabel "$mountpoint" "/$response")
274 echo "Ok, this is disc"
275 echo " $disklabel"
276 #echo "Updating multiple media contents file cache ..."
277 #multi_contentsfile="${mountpoint}/${response}/.disk/contents.gz"
278 #zcat "$multi_contentsfile" > disk-contents.$option
281 break;
282 done
284 distribution=$dist
285 if [ -n "$hierbase" ]; then
286 if [ -d "$mountpoint/$hierbase/dists/unstable/binary-$iarch" ]; then
287 echo \
289 Both a stable released distribution and a work-in-progress
290 development tree are available for installation. Would you like to
291 use the unreleased development tree (this is only recommended for
292 experts who like to live dangerously and want to help with testing) ?'
293 yesno "$p_usedevel" 'Use unreleased development distribution ?'
294 usedevel="$yesno"
295 if [ "$usedevel" = yes ]; then
296 distribution=development
298 else
299 usedevel=no
301 echo
304 case "$hierbase" in
305 /* )
307 '' )
310 hierbase="/$hierbase"
312 esac
314 check_binary () {
315 # args: area-in-messages directory
316 debug "check_binary($@)"
318 if [ ! -d "${mountpoint}$2" -a -z "$multi" ]; then
319 echo "'$2' does not exist."
320 return
323 # In this special case it is ok for a sub-distribution to not contain any
324 # .deb files. Each media should contain all Packages.cd files but does not
325 # need to contain the .deb files.
327 # if ! { find -L "$mountpoint$2" -name '*.deb' -print \
328 # | head -1 | grep . ; } >/dev/null 2>&1 && [ -z "$multi" ];
329 # then
330 # echo "'$2' does not contain any *.deb packages."
331 # return
332 # fi
334 this_binary="$2"
335 echo -n "Using '$this_binary' as $1 binary directory"
337 if [ -n "$multi" ]; then
338 this_disk=$(getdisklabel ${mountpoint} "/$hierbase")
339 echo " from disc"
340 echo " '$this_disk'"
341 else
342 echo ""
346 find_area () {
347 # args: area-in-messages area-in-vars subdirectory-in-hier
348 # last-time-binary last-time-packages
349 debug "find_area($@)"
350 this_binary=''
351 this_packages=''
352 this_disk=''
353 if [ -n "$hierbase" ]; then
354 check_binary $1 $(echo "$hierbase/dists/$3/$1/binary-$iarch" | sed 's:/\+:/:g')
355 debug "THIS_BINARY $this_binary"
357 if [ $2 = nf -a -z "$this_binary" ]; then
358 echo "
359 Note: most media distributions of Debian do not include programs available
360 in the 'non-free' directory of the distribution site.
361 This is because these programs are under licenses that do not allow source
362 modification or prevent distribution for profit on a media, or other
363 restrictions that make them not free software.
364 If you wish to install these programs you will have to get them from an
365 alternative source."
367 while [ -z "$this_binary" ]; do
368 defaultbinary="$4"
369 echo "
370 Which directory contains the *.deb packages from the $1 distribution
371 area (this directory is named '$3/binary' on the distribution site) ?
372 Say 'none' if this area is not available."
373 if [ $2 != main -a -z "$defaultbinary" ]; then
374 defaultbinary=none
376 echo -n \
377 "Enter _$1_ binary directory. [$4]
379 read response
380 if [ -z "$response" -a -n "$defaultbinary" ]; then
381 response="$defaultbinary"
383 if [ none = "$response" ]; then
384 break
386 case "$response" in
387 '' | none)
388 continue
390 esac
391 check_binary $1 "$(echo "$response" | sed -e 's:/$::; s:^/*:/:')"
392 done
393 if [ -n "$this_binary" ]; then
394 if [ "$multi" = "yes" ]; then
395 for f in Packages.cd.gz packages.cd.gz Packages.cd packages.cd; do
396 if [ -f "$mountpoint/$this_binary/$f" ]; then
397 this_packages="$this_binary/$f"
398 echo "Using '$this_packages' for $1."
399 break
401 done
402 elif [ -f "${mountpoint}${hierbase}/.disk/packages/$1/Packages.gz" ]; then
403 this_packages=$(echo "${hierbase}/.disk/packages/$1/Packages.gz"|sed 's:/\+:/:g')
404 echo "Using '${this_packages}' for $1."
406 while [ -z "$this_packages" ]; do
407 echo -n "
408 Cannot find the $1 'Packages.cd' file. The information in the
409 'Packages.cd' file is important for package selection during new
410 installations, and is very useful for upgrades.
412 If you overlooked it when downloading you should do get it now and
413 return to this installation procedure when you have done so: you will
414 find one Packages.cd file and one Packages.cd.gz file -- either will do --
415 in the 'binary' subdirectory of each area on the FTP sites and
416 media discs. Alternatively (and this will be rather slow) the packages in
417 the distribution area can be scanned - say 'scan' if you want to do so.
419 You need a separate Packages.cd file from each of the distribution areas
420 you wish to install.
422 Where is the _$1_ 'Packages.cd' file (if none is available, say 'none')
423 [$5]
425 read response
426 if [ -z "$response" -a -n "$5" ]; then
427 response="$5"
429 case "$response" in
431 break
433 none)
434 break
436 scan)
437 this_packages=scan
440 this_packages="$response"
443 this_packages="/$response"
445 esac
446 done
448 eval $2'_binary="$this_binary"'
449 eval $2'_packages="$this_packages"'
450 eval $2'_disk="$this_disk"'
453 find_area main main "$distribution" "$p_main_binary" "$p_main_packages"
454 find_area contrib ctb "$distribution" "$p_ctb_binary" "$p_ctb_packages"
455 find_area non-free-firmware nff "$distribution" "$p_nff_binary" "$p_nff_packages"
456 find_area non-free nf "$distribution" "$p_nf_binary" "$p_nf_packages"
457 find_area local lcl local "$p_lcl_binary" "$p_lcl_packages"
459 echo -n '
460 Hit RETURN to continue. '
461 read response
463 exec 3>shvar.$option.new
465 outputparam p_blockdev "$blockdevice"
466 outputparam p_fstype "$fstype"
467 outputparam p_mountpoint "$mountpoint"
468 outputparam p_hierbase "$hierbase"
469 outputparam p_usedevel "$usedevel"
470 outputparam p_main_packages "$main_packages"
471 outputparam p_main_binary "$main_binary"
472 outputparam p_main_disk "$main_disk"
473 outputparam p_ctb_packages "$ctb_packages"
474 outputparam p_ctb_binary "$ctb_binary"
475 outputparam p_ctb_disk "$ctb_disk"
476 outputparam p_nff_packages "$nff_packages"
477 outputparam p_nff_binary "$nff_binary"
478 outputparam p_nff_disk "$nff_disk"
479 outputparam p_nf_packages "$nf_packages"
480 outputparam p_nf_binary "$nf_binary"
481 outputparam p_nf_disk "$nf_disk"
482 outputparam p_lcl_packages "$lcl_packages"
483 outputparam p_lcl_binary "$lcl_binary"
484 outputparam p_multi "$multi"
485 outputparam p_multi_contentsfile "$multi_contentsfile"
487 mv shvar.$option.new shvar.$option
489 xit=0