summaryrefslogtreecommitdiff
path: root/src/pkgbuild-check-licenses
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkgbuild-check-licenses')
-rwxr-xr-xsrc/pkgbuild-check-licenses126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/pkgbuild-check-licenses b/src/pkgbuild-check-licenses
new file mode 100755
index 0000000..85ca2c3
--- /dev/null
+++ b/src/pkgbuild-check-licenses
@@ -0,0 +1,126 @@
+#!/usr/bin/env bash
+# pkgbuild-check-licenses
+
+# Copyright 2010 Haase Hernández
+# Copyright 2010 Joseph Graham
+# Copyright 2010 Joshua Ismael
+# Copyright 2010 Nicolás Reynolds
+# 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
+. $(librelib conf)
+
+# Usage: check_deps $pkgbuild
+# Check whether a PKGBUILD package depends on non-free packages
+check_licenses() (
+ # 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
+ return $_E_ERROR # not a PKGBUILD
+ fi
+ if [[ -z "${license[*]}" ]]; then
+ error "license array of %s %s is not set" "${pkgbase:-${pkgname[0]}}" "$(get_full_version)"
+ return $_E_ERROR
+ fi
+
+ msg2 "Looking at license array of %s %s" "${pkgbase:-${pkgname[0]}}" "$(get_full_version)"
+
+ local ret=$_E_OK
+ for _license in "${license[@]}"; do
+ if [[ ! -e "/usr/share/licenses/common/$_license" ]]; then
+ local s=$_E_OK
+ case "${_license#custom:}" in
+ WTFPL)
+ # accept as common, I think it should be in the licenses package
+ :;;
+ BSD1|BSD2|BSD3|MIT|X11)
+ # accept these as common; they can't be included in the
+ # 'licenses' package because some text must be customized
+ :;;
+ BSD4)
+ warning "The 4-clause BSD license is free but has practical problems.";;
+ BSD)
+ warning "License 'BSD' is ambiguous, use 'BSD{1..4}' to specify the number of clauses."
+ s=$_E_UNCOMMON
+ ;;
+ JSON)
+ error "License '%s' is a known non-free license." "$_license"
+ s=$_E_NONFREE
+ ;;
+ *)
+ warning "License '%s' is not a common license." "$_license"
+ s=$_E_UNCOMMON
+ ;;
+ esac
+ ret=$(($ret|$s))
+ 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 (add them for combinations):"
+ print " 0: Everything OK, no freedom issues"
+ print " 1: Ran with error"
+ print " 2: Uses uncommon licenses, check them"
+ print " 4: Uses known unacceptable licenses"
+ echo
+ print "Options:"
+ flag '-f' 'Allow running as root user'
+ flag '-h' 'Show this message'
+}
+_E_OK=0
+_E_ERROR=1
+_E_UNCOMMON=2
+_E_NONFREE=4
+
+main() {
+ local asroot=false
+ while getopts 'fh' arg; do
+ case "$arg" in
+ f) asroot=true;;
+ h) usage; return $_E_OK;;
+ *) usage; return $_E_ERROR;;
+ 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
+
+ local ret=0
+ for pkgbuild in "${pkgbuilds[@]}"; do
+ check_licenses "$pkgbuild" || ret=$(($ret|$?))
+ done
+ return $ret
+}
+
+main "$@"