#!/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 # 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 ${pkgbase:-${pkgname[0]}} $(get_full_version) is not set" return $_E_ERROR 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 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 ) 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 $_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 "$@"