3 # Copyright © 1995-1998 Ian Jackson <ijackson@chiark.greenend.org.uk>
4 # Copyright © 1998 Heiko Schlittermann <hs@schlittermann.de>
6 # This is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
25 cd "$vardir/methods/$method"
30 #debug() { echo "DEBUG: $@"; }
32 iarch=`dpkg --print-architecture`
33 ismulti() { test -e "$1/.disk/info" || test -e "$1$2/.disk/info"; }
39 if [ -f $1/.disk/info ]
41 echo -n `head -1 "$1/.disk/info"`
43 if [ -f $1$2/.disk/info ]
45 echo -n `head -1 "$1$2/.disk/info"`
47 echo -n 'Non-Debian disc'
55 if [ "$method" = "multi_mount" ]
60 if [ -n "$umount" ]; then
68 if [ "$method" = "multi_mount" ]
74 if [ ! -b "$p_blockdev" ]
79 if [ -n "$p_blockdev" ]
81 umount="$p_mountpoint"
82 echo mount -rt iso9660 -o nosuid,nodev${loop} "$p_blockdev" "$p_mountpoint"\; umount="$p_mountpoint"
87 umount="$p_mountpoint"
88 echo mount -rt nfs "$p_nfs" -o nosuid,nodev "$p_mountpoint"\; umount="$p_mountpoint"
91 #if [ -n "$p_multi" -a -n "$p_multi_contentsfile" ]; then
93 #echo " "`getdisklabel "${p_mountpoint}" "${p_hierbase}"`
97 trap 'eval `do_umount`; exit $xit' 0
101 predep="$vardir/predep-package"
104 thisdisk="`getdisklabel ${p_mountpoint} ${p_hierbase}`"
106 dpkg --predep-package >"$predep"
109 if test $rc = 1; then break; fi
113 ($binaryprefix,$predep,$thisdisk) = @ARGV;
114 open(P, "< $predep") or die "cannot open $predep: $!\n";
117 $package= $_ if s/^Package: //i;
118 /^X-Medium:\s+(.*)\s*/ and $medium = $1;
119 @filename= split(/ /,$_) if s/^Filename: //i;
120 @msdosfilename= split(/ /,$_) if s/^MSDOS-Filename: //i;
122 die "internal error - no package" if length($package) == 0;
123 die "internal error - no filename" if not @filename;
124 die "internal error - mismatch >@filename< >@msdosfilename<"
125 if @filename && @msdosfilename &&
126 @filename != @msdosfilename;
127 if ($medium && ($medium ne $thisdisk)) {
132 However, $package is expected on disc:
134 Please change the discs and press <RETURN>.
140 for ($i=0; $i<=$#filename; $i++) {
142 print "Looking for part $ppart of $package ... ";
143 if (-f "$binaryprefix$filename[$i]") {
144 $print= $filename[$i];
145 $invoke= "$binaryprefix$filename[$i]";
146 } elsif (-f "$binaryprefix$msdosfilename[$i]") {
147 $print= $msdosfilename[$i];
148 $invoke= "$binaryprefix$msdosfilename[$i]";
150 $base= $filename[$i]; $base =~ s,.*/,,;
151 $msdosbase= $msdosfilename[$i]; $msdosbase =~ s,.*/,,;
153 if (not defined $c) {
154 die "failed to fork for find: $!\n";
158 length($binaryprefix) ? $binaryprefix : ".",
159 "-name",$base,"-o","-name",$msdosbase);
160 die "failed to exec find: $!\n";
162 while (chop($invoke= <X>)) { last if -f $invoke; }
164 if (substr($print,0,length($binaryprefix)+1) eq
166 $print= substr($print,length($binaryprefix));
169 if (!length($invoke)) {
172 Oh dear, I need to install or upgrade $package, but I don'\''t see
173 the appropriate file(s) anywhere. I'\''m expecting version $version or
174 later, as that is listed in the Packages.cd file.
176 Perhaps you downloaded it with an unexpected name, or something.
177 In any case, you must find the file(s) and then either place it with
178 the correct filename(s) (as listed in the Packages.cd file or in
179 /var/lib/dpkg/available) and rerun the installation, or upgrade the
180 package by using '\''dpkg --install --auto-deconfigure'\'' by hand.
186 push(@invoke,$invoke);
188 print "Running dpkg -iB for $package ...\n";
189 exec("dpkg","-iB","--",@invoke);
190 die "failed to exec dpkg: $!\n";
191 ' -- "$p_mountpoint$p_hierbase" "$predep" "$thisdisk"
195 $SIG{INT} = sub { cd $vardir; unlink <tmp/*>; exit 1; };
197 my ($vardir, $mountpoint, $hierbase, $mount, $umount) = @ARGV;
199 my $AVAIL = "$vardir/methods/multicd/available";
200 my $STATUS = "$vardir/status";
201 my %Installed, %Filename, %Medium;
202 print "Get currently installed package versions...";
203 open(IN, "$STATUS") or die "cannot open $STATUS: $!\n";
209 $line++ % 20 or print ".";
211 %status = ("", split /^(\S*?):\s*/m, $_);
212 map { chomp $status{$_}; $status{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %status;
213 @pstat = split(/ /, $status{Status});
214 next unless ($pstat[0] eq "install");
215 if ($pstat[2] eq "config-files" || $pstat[2] eq "not-installed") {
216 $Installed{$status{Package}} = "0.0";
218 $Installed{$status{Package}} = $status{Version} || "" ;
221 print "\nGot ", scalar keys %Installed, " installed/pending packages\n";
222 print "Scanning available packages...";
224 open(IN, "$AVAIL") or die("Cannot open $AVAIL: $!\n");
228 $line++ % 20 or print ".";
231 %avail = ("", split /^(\S*?):\s*/m, $_);
232 map { chomp $avail{$_}; $avail{$_} =~ s/^\s*(.*?)\s*$/$1/;} keys %avail;
234 next unless defined $Installed{$avail{Package}};
236 system "dpkg", "--compare-versions", $avail{Version}, "gt", $Installed{$avail{Package}};
237 $updated = ($? == 0);
238 #print "$avail{Package}(" . ($updated ? "+" : "=") . ") ";
241 $Filename{$avail{Package}} = $avail{Filename};
243 next unless defined $avail{"X-Medium"};
244 ${Medium{$avail{"X-Medium"}}} or ${Medium{$avail{"X-Medium"}}} = [];
245 push @{${Medium{$avail{"X-Medium"}}}}, $avail{Package};
249 if (@_ = keys(%Medium)) {
250 print "You will need the following distribution disc(s):\n",
251 join (", ", @_), "\n";
254 foreach $need (sort @_) {
255 if (-r "$mountpoint/.disk/info") {
256 open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
258 open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
260 $disk = <IN>; chomp $disk; close(IN);
262 print "Processing disc\n $need\n";
264 while ($disk ne $need) {
265 print "Wrong disc. This is disc\n $disk\n";
266 print "However, I need disc\n $need\n";
267 print "Please change the discs and press <RETURN>\n";
271 $? and warn("cannot mount $mount\n");
273 if (-r "$mountpoint/.disk/info") {
274 open(IN, "$mountpoint/.disk/info") or die("$mountpoint/.disk/info: $!\n");
276 open(IN, "$mountpoint/$hierbase/.disk/info") or die("$mountpoint/$hierbase/.disk/info: $!\n");
278 $disk = <IN>; chomp $disk; close(IN);
281 -d "tmp" || mkdir "tmp", 0755 or die("Cannot mkdir tmp: $!\n");
284 print "creating symlinks...\n";
285 foreach (@{$Medium{$need}}) {
286 ($basename = $Filename{$_}) =~ s/.*\///;
287 symlink "$mountpoint/$hierbase/$Filename{$_}",
290 chdir "tmp" or die "cannot chdir to tmp: $!\n";
291 system "dpkg", "-iGROEB", ".";
296 print "\nThe dpkg run produced errors. Please tell me, if I should\n",
297 "continue with the next CD. [Y/n]: ";
299 exit 1 if $ans =~ /^n/i;
306 ' "$vardir" "$p_mountpoint" "$p_hierbase" "`do_mount`" "`do_umount`"
309 echo -n 'Installation OK. Hit RETURN. '