From a5de5ff031412c0319dc292d40ee60898d90e064 Mon Sep 17 00:00:00 2001 From: Isaac David Date: Sat, 7 Oct 2017 19:34:01 -0500 Subject: blacklist.sh: update `normalize` and `get-reason` to reflect blacklist.txt the blacklist has had a couple extra fields (ref, id) for some time, but `libreblacklist` was never made aware of the change. this updates test/lib-blacklist-test.sh for the same reason, and adds a test for comment stripping under `it_normalizes_correctly()`. --- src/lib/blacklist.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/lib/blacklist.sh (limited to 'src') diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh old mode 100644 new mode 100755 index 249ee89..6c507f4 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -24,7 +24,11 @@ # Usage: blacklist-normalize <$file # Normalizes the syntax of the blacklist on stdin. blacklist-normalize() { - sed -e '/^#/d' -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/' + sed -r -e '/^#/d' \ + -e 's/^[^:]*$/&::::/' \ + -e 's/^[^:]*:[^:]*$/&:::/' \ + -e 's/^[^:]*(:[^:]*){2}$/&::/' \ + -e 's/^[^:]*(:[^:]*){3}$/&:/' } # Usage: blacklist-cat @@ -91,5 +95,5 @@ blacklist-get-rep() { # Usage: blacklist-cat | blacklist-get-reason # Prints only the reason field of the blacklist line(s) on stdin. blacklist-get-reason() { - blacklist-normalize | cut -d: -f3- + blacklist-normalize | cut -d: -f5- } -- cgit v1.2.2 From 37c8e4a16bf03509b032385482a1c13041adaf65 Mon Sep 17 00:00:00 2001 From: Isaac David Date: Sat, 7 Oct 2017 22:48:24 -0500 Subject: blacklist.sh: make `blacklist-normalize` more maintainable For about the same amount of code we can save us the hassle of messing with sed expressions every time the number of fields changes in blacklist.txt. by knowing the delimiter character(s) and the number of times it's supposed to appear, a corresponding normalizing expression is constructed on the fly. --- src/lib/blacklist.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh index 6c507f4..10eafef 100755 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -2,6 +2,7 @@ # This may be included with or without `set -euE` # Copyright (C) 2013-2014, 2016-2017 Luke Shumaker +# Copyright (C) 2017 Isaac David # # License: GNU GPLv2+ # @@ -24,11 +25,14 @@ # Usage: blacklist-normalize <$file # Normalizes the syntax of the blacklist on stdin. blacklist-normalize() { - sed -r -e '/^#/d' \ - -e 's/^[^:]*$/&::::/' \ - -e 's/^[^:]*:[^:]*$/&:::/' \ - -e 's/^[^:]*(:[^:]*){2}$/&::/' \ - -e 's/^[^:]*(:[^:]*){3}$/&:/' + # dynamically build sed expression based on number of fields + local -a expr + local fields=5 sep=: i + for (( i = $fields - 2; i >= 0; --i )); do + expr+=('-e' "s/^[^:]*(:[^:]*){${i}}$/&${sep}/") + sep+=${sep:0:1} + done + sed -r -e '/^#/d' "${expr[@]}" } # Usage: blacklist-cat -- cgit v1.2.2 From ce4bc72dbd590231186267c064ae1679c2ba1241 Mon Sep 17 00:00:00 2001 From: Isaac David Date: Mon, 9 Oct 2017 15:22:46 -0500 Subject: blacklist: implement `get-url` function from `reference` and `id` fields The blacklist allows referring to a number of trusted bug trackers to complement the information given in the reason field. However, maintainable shorthand identifiers are used instead of full URLs. Printing the latter based on the former is the job of this new functionality. This also introduces corresponding test cases and l10n strings (together with translations for the `es` locale). --- src/lib/blacklist.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh index 10eafef..e3d976b 100755 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -96,6 +96,21 @@ blacklist-get-rep() { blacklist-normalize | cut -d: -f2 } +# Usage: blacklist-cat | blacklist-get-url +# Prints URLs formed from the reference-id fields of the blacklist line(s) on stdin. +# Prints an empty line in the absence of reference. +blacklist-get-url() { + blacklist-normalize | awk -F: ' + BEGIN { + refs["debian"] = "http://bugs.debian.org/" + refs["fsf"] = "http://libreplanet.org/wiki/List_of_software_that_does_not_respect_the_Free_System_Distribution_Guidelines#" + refs["sv"] = "https://savannah.nongnu.org/bugs/?" + refs["fedora"] = "https://bugzilla.redhat.com/show_bug.cgi?id=" + refs["parabola"] = "https://labs.parabola.nu/issues/" + } + refs[$3] { print refs[$3] $4 } !refs[$3] { print "" }' +} + # Usage: blacklist-cat | blacklist-get-reason # Prints only the reason field of the blacklist line(s) on stdin. blacklist-get-reason() { -- cgit v1.2.2 From 313d1ee619363eca0b8b0742a2d58c9ce18877fd Mon Sep 17 00:00:00 2001 From: Isaac David Date: Sat, 14 Oct 2017 00:54:20 -0500 Subject: blacklist get-rep: re-implement to query repos instead of blacklist.txt Rationale: https://lists.parabola.nu/pipermail/dev/2017-October/005936.html This makes get-rep a general-purpose tool for finding replacements and providers of any package, not just blacklisted-ones. It works equally well reading from full blacklist.txt lines, just pkgname lines, and unwittingly; a single line with many pkgnames. Some caveats for further discussion: - This changes behavior from showing just one replacement/provider to _all_ replacements and providers (including pkgname itself) in the repos. - By "repos" I mean the repos the executing machine is configured to access. This could be changed in the future with `expac --config` if more package databases are desired (e.g. different architecture). - Results are shown using the "repo/pkgname ..." format rather than just "pkgname ...". I think this makes the program more useful. - Results aren't reordered to ensure that the first provider of pkgname is pkgname itself. Order will be as expected otherwise, by virtue of expac parsing repos in order. --- src/lib/blacklist.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh index e3d976b..c092ed3 100755 --- a/src/lib/blacklist.sh +++ b/src/lib/blacklist.sh @@ -93,7 +93,24 @@ blacklist-get-pkg() { # Usage: blacklist-cat | blacklist-get-rep # Prints only the replacement package field of the blacklist line(s) on stdin. blacklist-get-rep() { - blacklist-normalize | cut -d: -f2 + local -a targets=($(blacklist-get-pkg)) + expac -Ss '%r/%n %n %P %R' | awk -v arr="${targets[*]}" ' + { + gsub("[=<>]+[^[:blank:]]*", "", $0) # discard versioning + # build pkg -> providers table from pkg -> provides + for (provided = 2; provided <= NF; ++provided) { + if (! seen[$1 " " $provided]++) { + providers[$provided] = providers[$provided] $1 " " + } + } + } + END { + split(arr, targets, " ") + for (pkg in targets) { + sub("[ \t]+$", "", providers[targets[pkg]]) + print providers[targets[pkg]] + } + }' } # Usage: blacklist-cat | blacklist-get-url -- cgit v1.2.2