allow empty sources.list entries

main
parent 860a9048d5
commit c738e96752
Signed by untrusted user: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -362,3 +362,5 @@ Variants: essential apt minbase
Test: apt-patterns Test: apt-patterns
Test: apt-patterns-custom Test: apt-patterns-custom
Test: empty-sources.list

@ -2072,7 +2072,7 @@ sub run_setup() {
} }
# write /etc/apt/sources.list and files in /etc/apt/sources.list.d/ # write /etc/apt/sources.list and files in /etc/apt/sources.list.d/
{ if (scalar @{ $options->{sourceslists} } > 0) {
my $firstentry = $options->{sourceslists}->[0]; my $firstentry = $options->{sourceslists}->[0];
# if the first sources.list entry is of one-line type and without # if the first sources.list entry is of one-line type and without
# explicit filename, then write out an actual /etc/apt/sources.list # explicit filename, then write out an actual /etc/apt/sources.list
@ -2299,6 +2299,9 @@ sub run_update() {
close $fh; close $fh;
if ($indextargets eq '') { if ($indextargets eq '') {
warning("apt-get indextargets output is empty"); warning("apt-get indextargets output is empty");
if (scalar @{ $options->{sourceslists} } == 0) {
warning "no known apt sources.list entry";
}
for my $list (@{ $options->{sourceslists} }) { for my $list (@{ $options->{sourceslists} }) {
if (defined $list->{fname}) { if (defined $list->{fname}) {
info("Filename: $list->{fname}"); info("Filename: $list->{fname}");
@ -5082,6 +5085,9 @@ sub main() {
## no critic (InputOutput::ProhibitExplicitStdin) ## no critic (InputOutput::ProhibitExplicitStdin)
<STDIN>; <STDIN>;
}; };
if ($content eq "") {
warning "sources.list from standard input is empty";
} else {
my $type = guess_sources_format($content); my $type = guess_sources_format($content);
if (!defined $type if (!defined $type
|| ($type ne "deb822" and $type ne "one-line")) { || ($type ne "deb822" and $type ne "one-line")) {
@ -5093,6 +5099,7 @@ sub main() {
fname => undef, fname => undef,
content => $content, content => $content,
}; };
}
} else { } else {
my @components = (); my @components = ();
foreach my $comp (@{ $options->{components} }) { foreach my $comp (@{ $options->{components} }) {
@ -5112,9 +5119,11 @@ sub main() {
} }
} }
my $compstr = join " ", @components; my $compstr = join " ", @components;
# if the currently selected apt keyrings do not contain the # From the suite name we can maybe infer which key we need. If we
# necessary key material for the chosen suite, then attempt adding # can infer this information, then we need to check whether the
# a signed-by option # currently running apt actually trusts this key or not. If it
# doesn't, then we need to add a signed-by line to the sources.list
# entry.
my $signedby = ''; my $signedby = '';
my %suite_by_vendor = get_suite_by_vendor(); my %suite_by_vendor = get_suite_by_vendor();
my $gpgproc = sub { my $gpgproc = sub {
@ -5251,9 +5260,14 @@ sub main() {
## no critic (InputOutput::ProhibitExplicitStdin) ## no critic (InputOutput::ProhibitExplicitStdin)
<STDIN>; <STDIN>;
}; };
if ($content eq "") {
warning
"sources.list from standard input is empty";
} else {
my $type = guess_sources_format($content); my $type = guess_sources_format($content);
if (!defined $type if (!defined $type
|| ($type ne 'deb822' and $type ne 'one-line')) { || ($type ne 'deb822' and $type ne 'one-line'))
{
error "cannot determine sources.list format"; error "cannot determine sources.list format";
} }
# if last entry is of same type and without filename, # if last entry is of same type and without filename,
@ -5272,6 +5286,7 @@ sub main() {
content => $content, content => $content,
}; };
} }
}
} elsif ($arg =~ /^deb(-src)? /) { } elsif ($arg =~ /^deb(-src)? /) {
my $content = "$arg\n"; my $content = "$arg\n";
# if last entry is of same type and without filename, # if last entry is of same type and without filename,
@ -5315,6 +5330,9 @@ sub main() {
$content .= $line; $content .= $line;
} }
close $fh; close $fh;
if ($content eq "") {
warning "$arg is empty";
} else {
my $type = undef; my $type = undef;
if ($arg =~ /\.list$/) { if ($arg =~ /\.list$/) {
$type = 'one-line'; $type = 'one-line';
@ -5324,7 +5342,8 @@ sub main() {
$type = guess_sources_format($content); $type = guess_sources_format($content);
} }
if (!defined $type if (!defined $type
|| ($type ne 'deb822' and $type ne 'one-line')) { || ($type ne 'deb822' and $type ne 'one-line'))
{
error "cannot determine sources.list format"; error "cannot determine sources.list format";
} }
push @{$sourceslists}, push @{$sourceslists},
@ -5333,6 +5352,9 @@ sub main() {
fname => basename($arg), fname => basename($arg),
content => $content, content => $content,
}; };
}
} elsif ($arg eq '') {
# empty
} else { } else {
error "invalid mirror: $arg"; error "invalid mirror: $arg";
} }
@ -5351,7 +5373,7 @@ sub main() {
} }
} }
if (scalar @{$sourceslists} == 0) { if (scalar @{$sourceslists} == 0) {
error "empty apt sources.list"; warning "empty apt sources.list";
} }
debug("sources list entries:"); debug("sources list entries:");
for my $list (@{$sourceslists}) { for my $list (@{$sourceslists}) {

@ -0,0 +1,8 @@
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM
printf '' | {{ CMD }} --mode={{ MODE }} --variant=apt \
--setup-hook='echo "deb {{ MIRROR }} {{ DIST }} main" > "$1"/etc/apt/sources.list' \
{{ DIST }} /tmp/debian-chroot.tar -
tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt -
Loading…
Cancel
Save