improve --components parsing with comma and whitespace as separator

pull/1/head
parent cf9d80f059
commit 78358eaf9a
Signed by: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -52,7 +52,7 @@ if [ ! -e shared/mmdebstrap ] || [ mmdebstrap -nt shared/mmdebstrap ]; then
fi
starttime=
total=102
total=103
i=1
print_header() {
@ -510,6 +510,24 @@ else
./run_null.sh
fi
print_header "mode=$defaultmode,variant=apt: supply components manually"
cat << END > shared/test.sh
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
$CMD --mode=$defaultmode --variant=apt --components="main main" --comp="main,main" $DEFAULT_DIST /tmp/debian-chroot $mirror
echo "deb $mirror $DEFAULT_DIST main" | cmp /tmp/debian-chroot/etc/apt/sources.list
tar -C /tmp/debian-chroot --one-file-system -c . | tar -t | sort | diff -u tar1.txt -
rm -r /tmp/debian-chroot
END
if [ "$HAVE_QEMU" = "yes" ]; then
./run_qemu.sh
elif [ "$defaultmode" = "root" ]; then
./run_null.sh SUDO
else
./run_null.sh
fi
print_header "mode=root,variant=apt: stable default mirror"
cat << END > shared/test.sh
#!/bin/sh

@ -1776,7 +1776,7 @@ sub main() {
my @ARGVORIG = @ARGV;
my $options = {
components => "main",
components => ["main"],
variant => "important",
include => undef,
mode => 'auto',
@ -1793,7 +1793,7 @@ sub main() {
GetOptions(
'h|help' => sub { pod2usage(-exitval => 0, -verbose => 2) },
'version' => sub { print STDOUT "mmdebstrap $VERSION\n"; exit 0; },
'components=s' => \$options->{components},
'components=s@' => \$options->{components},
'variant=s' => \$options->{variant},
'include=s' => \$options->{include},
'architectures=s' => \$options->{architectures},
@ -2083,6 +2083,24 @@ sub main() {
info "Reading sources.list from standard input...";
$sourceslist = do { local $/; <STDIN> };
} else {
my @components = ();
foreach my $comp (@{$options->{components}}) {
my @comps = split /[,\s]+/, $comp;
foreach my $c (@comps) {
# strip leading and trailing whitespace
$c =~ s/^\s+|\s+$//g;
# skip if the remainder is an empty string
if ($c eq "") {
next;
}
# do not append component if it's already in the list
if (any {$_ eq $c} @components) {
next;
}
push @components, $c;
}
}
my $compstr = join " ", @components;
if (scalar @ARGV > 0) {
for my $arg (@ARGV) {
if ($arg eq '-') {
@ -2091,7 +2109,7 @@ sub main() {
} elsif ($arg =~ /^deb(-src)? /) {
$sourceslist .= "$arg\n";
} elsif ($arg =~ /:\/\//) {
$sourceslist .= "deb $arg $suite $options->{components}\n";
$sourceslist .= "deb $arg $suite $compstr\n";
} elsif (-f $arg) {
open my $fh, '<', $arg or error "cannot open $arg: $!";
while (my $line = <$fh>) {
@ -2123,20 +2141,20 @@ sub main() {
} elsif (any {$_ eq $suite} @kali) {
$mirror = 'https://http.kali.org/kali'
}
$sourceslist .= "deb $mirror $suite $options->{components}\n";
$sourceslist .= "deb $mirror $suite $compstr\n";
if (any {$_ eq $suite} @ubuntustable) {
$sourceslist .= "deb $mirror $suite-updates $options->{components}\n";
$sourceslist .= "deb $secmirror $suite-security $options->{components}\n";
$sourceslist .= "deb $mirror $suite-updates $compstr\n";
$sourceslist .= "deb $secmirror $suite-security $compstr\n";
} elsif (any {$_ eq $suite} @tanglustable) {
$sourceslist .= "deb $secmirror $suite-updates $options->{components}\n";
$sourceslist .= "deb $secmirror $suite-updates $compstr\n";
} elsif (any {$_ eq $suite} @debstable) {
$sourceslist .= "deb $mirror $suite-updates $options->{components}\n";
$sourceslist .= "deb $mirror $suite-updates $compstr\n";
if (any {$_ eq $suite} ('stable', 'oldstable', 'stretch', 'buster')) {
$sourceslist .= "deb $secmirror $suite/updates $options->{components}\n";
$sourceslist .= "deb $secmirror $suite/updates $compstr\n";
} else {
# starting from bullseye use
# https://lists.debian.org/87r26wqr2a.fsf@43-1.org
$sourceslist .= "deb $secmirror $suite-security $options->{components}\n";
$sourceslist .= "deb $secmirror $suite-security $compstr\n";
}
}
}
@ -2716,8 +2734,16 @@ C<pkg>. See apt(8) for the supported syntax.
=item B<--components>=I<comp1>[,I<comp2>,...]
Comma separated list of components like main, contrib and non-free which will
be used for all URI-only I<MIRROR> arguments.
Comma or whitespace separated list of components like main, contrib and
non-free which will be used for all URI-only I<MIRROR> arguments. The option
can be specified multiple times and the components are concatenated in the
order in which they are given on the command line. If later list items are
repeated, then they get dropped so that the resulting component list is free
of duplicates. So the following are equivalent:
--components="main contrib non-free"
--components=main,contrib,non-free
--comp=main --comp="contrib non-free" --comp="main,non-free"
=item B<--architectures>=I<native>[,I<foreign1>,...]

Loading…
Cancel
Save