From 89300de664d73c52b78e46d158b02e41bb7b30c5 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Mon, 16 Sep 2024 20:55:43 +0300 Subject: [PATCH] Add support for listing `deb822-style` repos https://forum.virtualmin.com/t/package-repositories-empty-ubuntu-24-04/129152/12?u=ilia --- package-updates/index.cgi | 2 +- software/apt-lib.pl | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/package-updates/index.cgi b/package-updates/index.cgi index a482cafd5..54d54a359 100755 --- a/package-updates/index.cgi +++ b/package-updates/index.cgi @@ -244,7 +244,7 @@ if ($has_repos) { "$text{'yes'}" : "$text{'no'}", $r->{'url'}, - ], "", "d", $r->{'id'}); + ], "", "d", $r->{'id'}, undef, $r->{'cannot'}); } print &ui_columns_end(); print &ui_form_end([ diff --git a/software/apt-lib.pl b/software/apt-lib.pl index 74e62ec6e..736909345 100755 --- a/software/apt-lib.pl +++ b/software/apt-lib.pl @@ -457,7 +457,34 @@ my @rv; foreach my $f ($sources_list_file, glob("$sources_list_dir/*")) { my $lref = &read_file_lines($f, 1); my $lnum = 0; + my (%repo, @types); + my $repo = sub { + foreach my $type (@types) { + my @suites = @{$repo{'suites'}}; + foreach my $suite (@suites) { + my @comps = @{$repo{'comps'}}; + foreach my $comp (@comps) { + my $repo = + { + 'cannot' => 1, + 'file' => $f, + # 'line' => $lnum, + 'url' => $repo{'url'}, + 'enabled' => !$repo{'disabled'}, + 'words' => [$comp, $suite], + 'name' => join("/", $comp, $suite). + ($type =~ /src/ ? " ($type)" : ""), + 'signed_by' => $repo{'signed_by'}, + }; + $repo->{'id'} = + $repo->{'url'}.$repo->{'name'}; + push(@rv, $repo); + } + } + } + }; foreach my $l (@$lref) { + # Debian classic format (using .list files) if ($l =~ /^(#*)\s*deb.*?((http|https)\S+)\s+(\S.*)/) { my $repo = { 'file' => $f, 'line' => $lnum, @@ -471,6 +498,40 @@ foreach my $f ($sources_list_file, glob("$sources_list_dir/*")) { $repo->{'id'} = $repo->{'url'}.$repo->{'name'}; push(@rv, $repo); } + # New Ubuntu-style repos (using .sources files) + elsif ($f =~ /\.sources$/) { + if ($l =~ /^([\w\-]+):\s*(.+)$/) { + my ($key, $value) = ($1, $2); + if ($key eq 'Types') { + @types = split(/\s+/, $value); + } + elsif ($key eq 'URIs') { + $repo{'url'} = $value; + } + elsif ($key eq 'Suites') { + $repo{'suites'} = [split(/\s+/, $value)]; + } + elsif ($key eq 'Components') { + $repo{'comps'} = [split(/\s+/, $value)]; + } + elsif ($key eq 'Signed-By') { + $repo{'signed_by'} = $value; + } + elsif ($key eq 'Enabled') { + $repo{'disabled'} = + (lc($value) eq 'no') ? 1 : 0; + } + } + elsif ($l =~ /^\s*$/ || $lnum == $#{$lref}) { + # Process and push the current repo if we + # got an empty line or it's the last line + if (%repo) { + $repo->(); + %repo = (); + @types = (); + } + } + } $lnum++; } }