summaryrefslogtreecommitdiff
path: root/src/pkgbuild-check-nonfree
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkgbuild-check-nonfree')
-rwxr-xr-xsrc/pkgbuild-check-nonfree121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree
new file mode 100755
index 0000000..1cc0d9b
--- /dev/null
+++ b/src/pkgbuild-check-nonfree
@@ -0,0 +1,121 @@
+#!/usr/bin/env bash
+# pkgbuild-check-nonfree
+
+# Copyright 2010 Haase Hernández
+# Copyright 2010 Joseph Graham
+# Copyright 2010 Joshua Ismael
+# Copyright 2012-2013 Luke Shumaker
+#
+# This file is part of Parabola.
+#
+# Parabola is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Parabola is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
+
+. libremessages
+. libreblacklist
+. $(librelib conf)
+
+# Usage: check_deps $pkgbuild
+# Check whether a PKGBUILD package depends on non-free packages
+check_deps() (
+ # Note that we use () instead of {} for this function; so that variables
+ # from the PKBUILD don't bubble up
+ local pkgbuild=$1
+ load_PKGBUILD "$pkgbuild"
+ if [[ -z "$pkgname" ]]; then
+ exit 1 # not a PKGBUILD
+ fi
+
+ msg2 'Looking for unfree dependencies of %s %s' "${pkgbase:-${pkgname[0]}}" "$(get_full_version)"
+
+ local pkgs=(
+ # packages being built
+ "${pkgname[@]}"
+ # depends
+ "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}" "${optdepends[@]%%:*}"
+ # mksource depends
+ "${mkdepends[@]}"
+ )
+ local ret=0
+ for pkg in "${pkgs[@]}"; do
+ local line="$(blacklist-cat|blacklist-lookup "$pkg")"
+ local rep="$(blacklist-get-rep <<<"$line")"
+ if [[ -z $line ]]; then
+ # not mentioned in blacklist; free
+ plain '%s: not blacklisted' "$pkg"
+ continue
+ elif [[ -z $rep ]]; then
+ # non-free with no replacement
+ plain '%s: blacklisted' "$pkg"
+ ret=1
+ else
+ # non-free with free replacement
+ if [[ "$rep" == "$pkg" ]]; then
+ plain '%s: repackaged with the same name' "$pkg"
+ else
+ plain '%s: replaced by %s' "$pkg" "$rep"
+ fi
+ fi
+ done
+ return $ret
+)
+
+usage() {
+ print "Usage: %s [OPTIONS] [PKGBUILD1 PKGBUILD2 ...]" "${0##*/}"
+ echo
+ prose 'If no PKGBUILD is specified, `./PKGBUILD` is implied.'
+ echo
+ print "Exit status:"
+ print " 0: Everything OK, no freedom issues"
+ print " 1: Ran with error"
+ print " 15: Depends on non-free packages"
+ echo
+ print "Options:"
+ flag '-c' 'Use the cached blacklist, do not try downloading.'
+ flag '-f' 'Allow running as root user'
+ flag '-h' 'Show this message'
+}
+
+main() {
+ local asroot=false
+ local cache=false
+ while getopts 'cfh' arg; do
+ case "$arg" in
+ c) cache=true;;
+ f) asroot=true;;
+ h) usage; return 0;;
+ *) usage; return 1;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ if [[ $# -lt 1 ]]; then
+ pkgbuilds=("`pwd`/PKGBUILD")
+ else
+ pkgbuilds=("$@")
+ fi
+
+ if [[ -w / ]] && ! $asroot; then
+ error "Run as normal user, or use the -f option to run as root."
+ return 1
+ fi
+
+ $cache || blacklist-update || return 1
+
+ local ret=0
+ for pkgbuild in "${pkgbuilds[@]}"; do
+ check_deps "$pkgbuild" || ret=15
+ done
+ return $ret
+}
+
+main "$@"