From b7e257871dbf43d87d1fafd7d866c67b67023c9f Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Sat, 28 Nov 2020 00:46:48 +0100 Subject: [PATCH] use Debian::DistroInfo if available --- mmdebstrap | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index 8445545..d29ea84 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -3925,8 +3925,17 @@ sub get_sourceslist_by_suite { $sourceslist .= "deb$signedby $mirror $suite-updates $compstr\n"; # the security mirror changes, starting with bullseye # https://lists.debian.org/87r26wqr2a.fsf@43-1.org - my $distro_info = '/usr/share/distro-info/debian.csv'; - if (-f $distro_info) { + my $bullseye_or_later = 0; + my $distro_info = '/usr/share/distro-info/debian.csv'; + eval { require Debian::DistroInfo; }; + if (!$@) { + # libdistro-info-perl is installed + my $debinfo = DebianDistroInfo->new(); + if ($debinfo->version($suite, 0) >= 11) { + $bullseye_or_later = 1; + } + } elsif (-f $distro_info) { + # distro-info-data is installed open my $fh, '<', $distro_info or error "cannot open $distro_info: $!"; my $i = 0; @@ -3960,23 +3969,22 @@ sub get_sourceslist_by_suite { } close $fh; if ($matching_version >= 11) { - # starting from bullseye use - $sourceslist - .= "deb$signedby $secmirror $suite-security" . " $compstr\n"; - } else { - $sourceslist - .= "deb$signedby $secmirror $suite/updates" . " $compstr\n"; + $bullseye_or_later = 1; } } else { + # neither libdistro-info-perl nor distro-info-data is installed if (any { $_ eq $suite } ('bullseye', 'bookworm')) { - # starting from bullseye use - $sourceslist - .= "deb$signedby $secmirror $suite-security" . " $compstr\n"; - } else { - $sourceslist - .= "deb$signedby $secmirror $suite/updates" . " $compstr\n"; + $bullseye_or_later = 1; } } + if ($bullseye_or_later) { + # starting from bullseye use + $sourceslist + .= "deb$signedby $secmirror $suite-security" . " $compstr\n"; + } else { + $sourceslist + .= "deb$signedby $secmirror $suite/updates" . " $compstr\n"; + } } return $sourceslist; }