From 7e704d7ac997387341e920e1757c24cac0efe5e9 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 8 Feb 2016 16:36:45 -0500 Subject: Refactor the build system. Avoid recursive make. This looks like a lot, but more things should "just work". We have `make dist` now! --- src/lib/libreblacklist | 141 +++++++++++++------------------------------------ 1 file changed, 36 insertions(+), 105 deletions(-) (limited to 'src/lib/libreblacklist') diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist index 1e5a467..6c354fe 100755 --- a/src/lib/libreblacklist +++ b/src/lib/libreblacklist @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# This may be included with or without `set -euE` -# When run directly, it does `set -euE` - -# Copyright (C) 2013-2014 Luke Shumaker +# Copyright (C) 2013-2014, 2016 Luke Shumaker # # License: GNU GPLv2+ # @@ -19,88 +16,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# make sure XDG_CACHE_HOME is set -. "$(librelib conf)" - -# Usage: blacklist-normalize <$file -# Normalizes the syntax of the blacklist on stdin. -blacklist-normalize() { - sed -e '/^#/d' -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/' -} - -# Usage: blacklist-cat -# Prints the blacklist. -# Uses the cache, but downloads it if it doesn't exist. Also normalizes the blacklist for easier parsing. -blacklist-cat() { - local file="$XDG_CACHE_HOME/libretools/blacklist.txt" - if ! [[ -e $file ]]; then - # exit on failure, whether set -e or not - blacklist-update || return $? - fi - blacklist-normalize < "$file" -} - -# Usage: blacklist-update -# Updates (or creates) the cached copy of the blacklist. -blacklist-update() ( - . libremessages - load_files libretools || return 1 - check_vars libretools BLACKLIST || return 1 - - local remote_blacklist="$BLACKLIST" - local local_blacklist="$XDG_CACHE_HOME/libretools/blacklist.txt" - - _l stat_busy "Downloading blacklist of proprietary software packages" - - mkdir -p "${local_blacklist%/*}" - if wget -N -q -O "${local_blacklist}.part" "$remote_blacklist" 2>/dev/null; then - stat_done - mv -f "${local_blacklist}.part" "$local_blacklist" - else - stat_done - rm "${local_blacklist}.part" - if [[ -e "$local_blacklist" ]]; then - _l warning "Using local copy of blacklist" - else - _l error "Download failed, exiting" - return 1 - fi - - fi -) - -# Usage: blacklist-cat | blacklist-lookup $pkgname -# Filters to obtain the line for $pkgname from the blacklist on stdin. -# Exits successfully whether a line is found or not. -blacklist-lookup() { - local pkg=$1 - # we accept that $pkg contains no regex-nes - blacklist-normalize | grep "^$pkg:" || true -} - -# Usage: blacklist-cat | blacklist-get-pkg -# Prints only the package name field of the blacklist line(s) on stdin. -blacklist-get-pkg() { - blacklist-normalize | cut -d: -f1 -} - -# 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 -} +if [[ "${0##*/}" != libreblacklist ]]; then + . "$(librelib blacklist)" +else + set -euE -# 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- -} + lib_file="$(librelib blacklist)" + . "$lib_file" -if [[ "${0##*/}" == libreblacklist ]]; then - set -euE usage-outside() { - sed -n '/^# Usage:/,/()/p' "$0" | - tr '\n' '\r' | sed 's/\s*()\s*[{(]/\n/g' + sed -n '/^# Usage:/,/()/p' "$lib_file" | + tr '\n' '\r' | sed 's/\s*()\s*[{(]/\n/g' } # The output format of this is: # - The first line is "Usage:" @@ -110,6 +36,7 @@ if [[ "${0##*/}" == libreblacklist ]]; then usage-inside() { sed 's/\r/\n/g'<<<"$1"|sed -e '/^$/d' -e 's/^# //' } + usage() { export TEXTDOMAIN='librelib' export TEXTDOMAINDIR='/usr/share/locale' @@ -120,33 +47,37 @@ if [[ "${0##*/}" == libreblacklist ]]; then echo print "Commands:" usage-outside | while read -r sec; do sec="$(usage-inside "$sec")" - cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') - desc="$(_ "$(sed -n 2p <<<"$sec")")" - flag "$cmd" "${desc//blacklist-/${0##*/} }" + cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') + desc="$(_ "$(sed -n 2p <<<"$sec")")" + flag "$cmd" "${desc//blacklist-/${0##*/} }" done else usage-outside | while read -r sec; do sec="$(usage-inside "$sec")" - cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') - if [[ "$cmd" == "$1" ]]; then - <<<"$sec" sed '$d' | - while read -r line; do print "$line"; done | - sed "s/blacklist-/${0##*/} /g" | - fmt -us - return 0 - fi + cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p') + if [[ "$cmd" == "$1" ]]; then + <<<"$sec" sed '$d' | + while read -r line; do print "$line"; done | + sed "s/blacklist-/${0##*/} /g" | + fmt -us + return 0 + fi done fi } - if [[ $# -eq 0 ]]; then - usage >&2 - exit 1 - fi - _blacklist_cmd=$1 - shift - if [[ $_blacklist_cmd == -h ]]; then - usage "$@" - else - "blacklist-$_blacklist_cmd" "$@" - fi + main() { + if [[ $# -eq 0 ]]; then + usage >&2 + exit 1 + fi + _blacklist_cmd=$1 + shift + if [[ $_blacklist_cmd == -h ]]; then + usage "$@" + else + "blacklist-$_blacklist_cmd" "$@" + fi + } + + main "$@" fi -- cgit v1.2.2