File: install.pl

package info (click to toggle)
dpkg 1.23.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 59,120 kB
  • sloc: ansic: 40,205; perl: 30,746; sh: 18,907; cpp: 6,054; makefile: 5,226; sed: 127
file content (146 lines) | stat: -rwxr-xr-x 4,260 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
#
# Copyright © 1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
# Copyright © 2000 Adam Heath <doogie@debian.org>
# Copyright © 2009-2025 Guillem Jover <guillem@debian.org>
#
# 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/>.

use v5.36;

use Dselect::Method::Config;

my $vardir = $ARGV[0];
my $method = $ARGV[1];
my $option = $ARGV[2];

chdir "$vardir/methods/file";

my $conf = Dselect::Method::Config->new();

$conf->load("./shvar.$option");

my $exit = 1;

my $predep = "$vardir/predep-package";
my $binaryprefix = $conf->get('p_mountpoint') . $conf->get('p_main_binary');
$binaryprefix =~ s{/*$}{/} if length($binaryprefix);

while (1) {
    my $package;
    my $version;
    my @filename;

    system "dpkg --admindir '$vardir' --predep-package >'$predep'";
    my $rc = $? >> 8;
    last if $rc == 1;
    die if $rc != 0;

    open my $predep_fh, '<', $predep
        or die "cannot open $predep: $!\n";
    while (<$predep_fh>) {
        s/\s*\n$//;
        $package = $_ if s/^Package: //i;
        $version = $_ if s{^Version: }{}i;
        @filename = split / / if s/^Filename: //i;
    }
    close $predep_fh;
    die 'internal error - no package' if length($package) == 0;
    die 'internal error - no filename' if not @filename;

    my @invoke = ();
    $| = 1;
    foreach my $i (0 .. $#filename) {
        my $ppart = $i + 1;
        my $print;
        my $invoke;
        my $base;

        print "Looking for part $ppart of $package ... ";
        if (-f "$binaryprefix$filename[$i]") {
            $print = $filename[$i];
            $invoke = "$binaryprefix$filename[$i]";
        } else {
            $base = $filename[$i];
            $base =~ s{.*/}{};
            my $c = open my $find_fh, '-|';
            if (not defined $c) {
                die "failed to fork for find: $!\n";
            }
            if (! $c) {
                exec('find', '-L',
                     length($binaryprefix) ?
                     $binaryprefix : q{.},
                     '-name', $base);
                die "failed to exec find: $!\n";
            }
            while (chop($invoke = <$find_fh>)) {
                last if -f $invoke;
            }
            close $find_fh;
            $print = $invoke;
            my $printprefix = substr $print, 0, length $binaryprefix + 1;
            if ($printprefix eq "$binaryprefix/") {
                $print = substr $print, length $binaryprefix;
            }
        }
        if (! length($invoke)) {
            warn <<"WARN";

Cannot find the appropriate file(s) anywhere needed to install or upgrade
package $package. Expecting version $version or later, as listed in the
Packages file.

Perhaps the package was downloaded with an unexpected name? In any case,
you must find the file(s) and then either place it with the correct
filename(s) (as listed in the Packages file or in $vardir/available)
and rerun the installation, or upgrade the package by using
"dpkg --install --auto-deconfigure" by hand.

WARN
            exit(1);
        }
        print "$print\n";
        push(@invoke, $invoke);
    }

    print "Running dpkg -iB for $package ...\n";
    exec('dpkg', '--admindir', $vardir, '-iB', '--', @invoke);
    die "failed to exec dpkg: $!\n";
}

foreach my $f (qw(main ctb nf lcl)) {
    my $this_binary = $conf->get("p_${f}_binary");
    next if length $this_binary == 0;

    my @cmd = (
        'dpkg',
        '--admindir', $vardir,
        '-iGROEB',
        $conf->get('p_mountpoint') . $this_binary,
    );

    print "Running @cmd\n";
    system(@cmd) == 0
        or die;
}

print 'Installation OK. Hit RETURN.';
<STDIN>;

$exit = 0;

END {
    exit $exit;
}