summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-01-02 12:02:19 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2018-01-02 12:02:19 -0500
commit96ce209e48e7f729552809540cc2e97e6fe1e6aa (patch)
tree53b1801ad90f9472d407b01a2ae10695219fd6e7 /src
parente8bed2be9f4a03b8573153f985653d3ccecdf8b3 (diff)
parent9c2ed3fab9cf19acd5a72d1240bc2a0c8003238d (diff)
Merge branch 'isacdaavid'
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--]src/lib/blacklist.sh46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh
index 249ee89..c092ed3 100644..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 <lukeshu@sbcglobal.net>
+# Copyright (C) 2017 Isaac David <isacdaavid@isacdaavid.info>
#
# License: GNU GPLv2+
#
@@ -24,7 +25,14 @@
# Usage: blacklist-normalize <$file
# Normalizes the syntax of the blacklist on stdin.
blacklist-normalize() {
- sed -e '/^#/d' -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/'
+ # 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
@@ -85,11 +93,43 @@ 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
+# 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() {
- blacklist-normalize | cut -d: -f3-
+ blacklist-normalize | cut -d: -f5-
}