upgrades: Overwrite apt sources lens with bug fixes

Fixes: #2251
Fixes: #2426

- Temporarily add a bug fix for the one-line style apt sources format. Upstream
submission: https://github.com/hercules-team/augeas/pull/865 .

- Currently, only two options with keys arch= or trusted= are allowed. However,
as documented in apt manual page[1], there are many different options possible.
Apt itself parses these options in a much more generic way[2][3].

- Fixes allow parsing all the different options allowed by apt. A practical
example (accepted by apt) is also provided as a test case.

Tests:

- Add the following line to one of the apt sources file in
/etc/apt/sources.list.d: "deb
[signed-by=/usr/share/keyrings/debian-archive-trixie-stable.gpg]
https://deb.debian.org/debian trixie main". In augtool, print
/augeas/files/etc/apt/sources.list.d//error.

- With the patch, run 'make build install' and errors in augtool disappear.

- In tor proxy app, enabling/disabling apt through tor works. The files in
/etc/apt/ are updated as expected.

Link: https://manpages.debian.org/trixie/apt/sources.list.5.en.html
Link: 3c9399e643/apt-pkg/sourcelist.cc (L215)
Link: 3c9399e643/apt-pkg/contrib/strutl.cc (L245)
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-09-09 20:05:19 -07:00 committed by James Valleroy
parent a98e6f7563
commit 5758bdba2a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 189 additions and 0 deletions

7
debian/copyright vendored
View File

@ -327,6 +327,13 @@ Copyright: 2005 Andrew Dolgov
Comment: https://git.tt-rss.org/fox/tt-rss/src/master/images/favicon-72px.png
License: GPL-3+
Files: plinth/modules/upgrades/data/usr/share/augeas/lenses/aptsources.aug
plinth/modules/upgrades/data/usr/share/augeas/lenses/tests/test_aptsources.aug
Copyright: 2007-2025 David Lutterkort
Comment: https://github.com/hercules-team/augeas/blob/master/lenses/aptsources.aug
https://github.com/hercules-team/augeas/blob/master/lenses/tests/test_aptsources.aug
License: LGPL-2.1+
Files: plinth/modules/wordpress/static/icons/wordpress.png
plinth/modules/wordpress/static/icons/wordpress.svg
Copyright: 2011-2021 WordPress Contributors

View File

@ -0,0 +1,72 @@
(*
Module: Aptsources
Parsing /etc/apt/sources.list
*)
module Aptsources =
autoload xfm
(************************************************************************
* Group: Utility variables/functions
************************************************************************)
(* View: sep_ws *)
let sep_ws = Sep.space
(* View: eol *)
let eol = Util.del_str "\n"
(* View: comment *)
let comment = Util.comment
(* View: empty *)
let empty = Util.empty
(* View: word *)
let word = /[^][# \n\t]+/
(* View: uri *)
let uri =
let protocol = /[a-z+]+:/
in let path = /\/[^] \t]*/
in let path_brack = /\[[^]]+\]\/?/
in protocol? . path
| protocol . path_brack
(************************************************************************
* Group: Keywords
************************************************************************)
(* View: record *)
let record =
let option_key = /[^= \t\r\n]*[^-+= \t\r\n]/
in let option_sep = [ label "operation" . store /[+-]/]? . Sep.equal
in let option_value = (store /[^] \t\r\n]+/)
in let option = Build.key_value option_key option_sep option_value
in let options = [ label "options"
. Util.del_str "[" . Sep.opt_space
. Build.opt_list option Sep.space
. Sep.opt_space . Util.del_str "]"
. sep_ws ]
in [ Util.indent . seq "source"
. [ label "type" . store word ] . sep_ws
. options?
. [ label "uri" . store uri ] . sep_ws
. [ label "distribution" . store word ]
. [ label "component" . sep_ws . store word ]*
. del /[ \t]*(#.*)?/ ""
. eol ]
(************************************************************************
* Group: Lens
************************************************************************)
(* View: lns *)
let lns = ( comment | empty | record ) *
(* View: filter *)
let filter = (incl "/etc/apt/sources.list")
. (incl "/etc/apt/sources.list.d/*")
. Util.stdexcl
let xfm = transform lns filter
(* Local Variables: *)
(* mode: caml *)
(* End: *)

View File

@ -0,0 +1,110 @@
module Test_aptsources =
let simple_source = "deb ftp://mirror.bytemark.co.uk/debian/ etch main\n"
let multi_components = "deb http://security.debian.org/ etch/updates main contrib non-free\n"
test Aptsources.lns get simple_source =
{ "1"
{ "type" = "deb" }
{ "uri" = "ftp://mirror.bytemark.co.uk/debian/" }
{ "distribution" = "etch" }
{ "component" = "main" }
}
test Aptsources.lns get multi_components =
{ "1"
{ "type" = "deb" }
{ "uri" = "http://security.debian.org/" }
{ "distribution" = "etch/updates" }
{ "component" = "main" }
{ "component" = "contrib" }
{ "component" = "non-free" }
}
let multi_line = "#deb http://www.backports.org/debian/ sarge postfix
# deb http://people.debian.org/~adconrad sarge subversion
deb ftp://mirror.bytemark.co.uk/debian/ etch main non-free contrib
deb http://security.debian.org/ etch/updates main contrib non-free # security line
deb-src http://mirror.bytemark.co.uk/debian etch main contrib non-free\n"
test Aptsources.lns get multi_line =
{ "#comment" = "deb http://www.backports.org/debian/ sarge postfix" }
{ "#comment" = "deb http://people.debian.org/~adconrad sarge subversion" }
{}
{ "1"
{ "type" = "deb" }
{ "uri" = "ftp://mirror.bytemark.co.uk/debian/" }
{ "distribution" = "etch" }
{ "component" = "main" }
{ "component" = "non-free" }
{ "component" = "contrib" }
}
{ "2"
{ "type" = "deb" }
{ "uri" = "http://security.debian.org/" }
{ "distribution" = "etch/updates" }
{ "component" = "main" }
{ "component" = "contrib" }
{ "component" = "non-free" }
}
{ "3"
{ "type" = "deb-src" }
{ "uri" = "http://mirror.bytemark.co.uk/debian" }
{ "distribution" = "etch" }
{ "component" = "main" }
{ "component" = "contrib" }
{ "component" = "non-free" }
}
let trailing_comment = "deb ftp://server/debian/ etch main # comment\n"
(* Should be a noop; makes sure that we preserve the trailing comment *)
test Aptsources.lns put trailing_comment after
set "/1/type" "deb"
= trailing_comment
(* Support options, GH #295 *)
test Aptsources.lns get "deb [arch=amd64] tor+http://ftp.us.debian.org/debian sid main contrib
deb [ arch+=amd64 trusted-=true ] http://ftp.us.debian.org/debian sid main contrib
deb [signed-by=/usr/share/keyrings/debian-archive-trixie-stable.gpg] http://deb.debian.org/debian trixie main\n" =
{ "1"
{ "type" = "deb" }
{ "options"
{ "arch" = "amd64" }
}
{ "uri" = "tor+http://ftp.us.debian.org/debian" }
{ "distribution" = "sid" }
{ "component" = "main" }
{ "component" = "contrib" } }
{ "2"
{ "type" = "deb" }
{ "options"
{ "arch" = "amd64" { "operation" = "+" } }
{ "trusted" = "true" { "operation" = "-" } }
}
{ "uri" = "http://ftp.us.debian.org/debian" }
{ "distribution" = "sid" }
{ "component" = "main" }
{ "component" = "contrib" } }
{ "3"
{ "type" = "deb" }
{ "options"
{ "signed-by" = "/usr/share/keyrings/debian-archive-trixie-stable.gpg" } }
{ "uri" = "http://deb.debian.org/debian" }
{ "distribution" = "trixie" }
{ "component" = "main" } }
(* cdrom entries may have spaces, GH #296 *)
test Aptsources.lns get "deb cdrom:[Debian GNU/Linux 7.5.0 _Wheezy_ - Official amd64 CD Binary-1 20140426-13:37]/ wheezy main\n" =
{ "1"
{ "type" = "deb" }
{ "uri" = "cdrom:[Debian GNU/Linux 7.5.0 _Wheezy_ - Official amd64 CD Binary-1 20140426-13:37]/" }
{ "distribution" = "wheezy" }
{ "component" = "main" } }
(* Local Variables: *)
(* mode: caml *)
(* End: *)