From a0a11867a85d5694a24de22751d8db7f59c1f347 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 5 Jun 2013 19:33:49 -0600 Subject: pull code from `aur` into new prog `pkgbuild-check-licenses`, enhance --- src/pkgbuild-check-licenses | 133 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 src/pkgbuild-check-licenses (limited to 'src/pkgbuild-check-licenses') diff --git a/src/pkgbuild-check-licenses b/src/pkgbuild-check-licenses new file mode 100755 index 0000000..347b48f --- /dev/null +++ b/src/pkgbuild-check-licenses @@ -0,0 +1,133 @@ +#!/bin/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 . + +. libremessages + +# Unset any PKGBUILD variables inherited from the environment +# I took these from makepkg 4.1.1-1 +unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides +unset md5sums replaces depends conflicts backup source install changelog build +unset makedepends optdepends options noextract + +# 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 + . "$pkgbuild" + if [[ -z $pkgname ]]; then + return 1 # not a PKGBUILD + fi + if [[ -z "${license[*]}" ]]; then + error "license array of ${pkgbase:-${pkgname[0]}} $(get_full_version) is not set" + return 1 + fi + + msg2 "Looking at license array of ${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 of the text must be customized + :;; + BSD4) + warning "The 4-clause BSD license is free but has practical problems.";; + BSD) + warning "License \"BSD\" is ambiguous, please use one of \"BSD{1..4}\" to specify the number of clauses." + s=$_E_UNCOMMON + ;; + JSON) + error "License \"$_license\" is a known non-free license." + s=$_E_NONFREE + ;; + *) + warning "License \"$_license\" is not a common license." + s=$_E_UNCOMMON + ;; + esac + ret=$(($ret|$s)) + fi + done + return $ret +) + +cmd=${0##*/} +usage() { + echo "Usage: $cmd [OPTIONS] [PKGBUILD1 PKGBUILD2 ...]" + echo '' + echo "If no PKGBUILD is specified, \`./PKGBUILD' is implied" + echo '' + echo "Exit status (add them for combinations):" + echo " 0: Everything OK, no freedom issues" + echo " 1: Ran with error" + echo " 2: Uses uncommon licenses, check them" + echo " 4: Uses known unacceptable licenses" + echo '' + echo "Options:" + echo ' -f Allow running as root user' + echo ' -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 0;; + *) usage; return 1;; + esac + done + shift $(($OPTIND - 1)) + if [[ $# < 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 + + blacklist-update || return 1 + + local ret=0 + for pkgbuild in "${pkgbuilds[@]}"; do + check_deps "$pkgbuild" || ret=$(($ret|$?)) + done + return $ret +} + +main "$@" -- cgit v1.2.2