chiark / gitweb /
lib/dpkg/tarfn.c: Kludge `tar_header_decode' to handle spurious `errno'.
[dpkg] / dselect / methods / disk / install
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
16 set -e
17 vardir="$1"
18 method=$2
19 option=$3
20
21 cd "$vardir/methods/disk"
22
23 . ./shvar.$option
24
25 xit=1
26 trap '
27         if [ -n "$umount" ]
28         then
29                 umount "$umount" >/dev/null 2>&1
30         fi
31         exit $xit
32 ' 0
33
34 if [ -n "$p_blockdev" ]
35 then
36         umount="$p_mountpoint"
37         mount -rt "$p_fstype" -o nosuid,nodev "$p_blockdev" "$p_mountpoint"
38 fi
39
40 if [ -n "$p_nfs" ]
41 then
42         umount="$p_mountpoint"
43         mount -rt nfs "$p_nfs" -o nosuid,nodev "$p_mountpoint"
44 fi
45
46 predep="$vardir/predep-package"
47 while true
48 do
49         set +e
50         dpkg --admindir "$vardir" --predep-package >"$predep"
51         rc=$?
52         set -e
53         if test $rc = 1; then break; fi
54         test $rc = 0
55
56         perl -e '
57                 ($binaryprefix,$predep) = @ARGV;
58                 $binaryprefix =~ s,/*$,/, if length($binaryprefix);
59                 open(P, "< $predep") or die "cannot open $predep: $!\n";
60                 while (<P>) {
61                         s/\s*\n$//;
62                         $package= $_ if s/^Package: //i;
63                         @filename= split(/ /,$_) if s/^Filename: //i;
64                         @msdosfilename= split(/ /,$_) if s/^MSDOS-Filename: //i;
65                 }
66                 die "internal error - no package" if length($package) == 0;
67                 die "internal error - no filename" if not @filename;
68                 die "internal error - mismatch >@filename< >@msdosfilename<"
69                         if @filename && @msdosfilename &&
70                            @filename != @msdosfilename;
71                 @invoke=(); $|=1;
72                 for ($i=0; $i<=$#filename; $i++) {
73                         $ppart= $i+1;
74                         print "Looking for part $ppart of $package ... ";
75                         if (-f "$binaryprefix$filename[$i]") {
76                                 $print= $filename[$i];
77                                 $invoke= "$binaryprefix$filename[$i]";
78                         } elsif (-f "$binaryprefix$msdosfilename[$i]") {
79                                 $print= $msdosfilename[$i];
80                                 $invoke= "$binaryprefix$msdosfilename[$i]";
81                         } else {
82                                 $base= $filename[$i]; $base =~ s,.*/,,;
83                                 $msdosbase= $msdosfilename[$i]; $msdosbase =~ s,.*/,,;
84                                 $c = open(X, "-|"));
85                                 if (not defined $c) {
86                                         die "failed to fork for find: $!\n";
87                                 }
88                                 if (!$c) {
89                                         exec("find", "-L",
90                                              length($binaryprefix) ?
91                                              $binaryprefix : ".",
92                                              "-name",$base,"-o","-name",$msdosbase);
93                                         die "failed to exec find: $!\n";
94                                 }
95                                 while (chop($invoke= <X>)) { last if -f $invoke; }
96                                 $print= $invoke;
97                                 if (substr($print,0,length($binaryprefix)+1) eq
98                                     "$binaryprefix/") {
99                                         $print= substr($print,length($binaryprefix));
100                                 }
101                         }
102                         if (!length($invoke)) {
103                                 warn "
104
105 Oh dear, I need to install or upgrade $package, but I don'\''t see
106 the appropriate file(s) anywhere.  I'\''m expecting version $version or
107 later, as that is listed in the Packages file.
108
109 Perhaps you downloaded it with an unexpected name, or something.
110 In any case, you must find the file(s) and then either place it with
111 the correct filename(s) (as listed in the Packages file or in
112 $vardir/available) and rerun the installation, or upgrade the
113 package by using '\''dpkg --install --auto-deconfigure'\'' by hand.
114
115 ";
116                                 exit(1);
117                         }
118                         print "$print\n";
119                         push(@invoke,$invoke);
120                 }
121                 print "Running dpkg -iB for $package ...\n";
122                 exec("dpkg","--admindir",$vardir,"-iB","--",@invoke);
123                 die "failed to exec dpkg: $!\n";
124         ' -- "$p_mountpoint$p_main_binary" "$predep"
125 done
126
127 for f in main ctb nf nus lcl
128 do
129         eval 'this_binary=$p_'$f'_binary'
130         if [ -z "$this_binary" ]; then continue; fi
131         echo Running dpkg --admindir $vardir -iGROEB "$p_mountpoint$this_binary"
132         dpkg --admindir $vardir -iGROEB "$p_mountpoint$this_binary"
133 done
134
135 echo -n 'Installation OK.  Hit RETURN.  '
136 read response
137
138 xit=0