#!/bin/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
# 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 uplocal pkgbuild=$1
load_PKGBUILD "$pkgbuild"if[[-z"$pkgname"]];thenexit1# not a PKGBUILDfi
msg2 "Looking for unfree dependencies of${pkgbase:-${pkgname[0]}} $(get_full_version)"local pkgs=(# packages being built"${pkgname[@]}"# depends"${depends[@]}""${makedepends[@]}""${checkdepends[@]}"# mksource depends"${mkdepends[@]}""${mkmakedepends[@]}""${mkcheckdepends[@]}")local ret=0for pkg in"${pkgs[@]}";dolocal line="$(blacklist-cat|blacklist-lookup "$pkg")"local rep="$(blacklist-get-rep <<<"$line")"if[[-z$line]];then# not mentioned in blacklist; free
plain "$pkg: free"continueelif[[-z$rep]];then# non-free with no replacement
plain "$pkg: non-free"
ret=1else# non-free with free replacementif[["$rep"=="$pkg"]];then
plain "$pkg: repackaged with the same name."else
plain "$pkg: replaced by$rep"fifidonereturn$ret)
cmd=${0##*/}
usage() {echo"Usage:$cmd[OPTIONS] [PKGBUILD1 PKGBUILD2 ...]"echo''echo"If no PKGBUILD is specified, \`./PKGBUILD' is implied"echo''echo"Exit status:"echo" 0: Everything OK, no freedom issues"echo" 1: Ran with error"echo" 15: Depends on non-free packages"echo''echo"Options:"echo' -c Use the cached blacklist, do not try downloading.'echo' -f Allow running as root user'echo' -h Show this message'}
main() {local asroot=false
local cache=false
whilegetopts'cfh' arg;docase"$arg"in
c) cache=true;;
f) asroot=true;;
h) usage;return0;;*) usage;return1;;esacdoneshift $(($OPTIND-1))if[[$#-lt1]];then
pkgbuilds=("`pwd`/PKGBUILD")else
pkgbuilds=("$@")fiif[[-w/ ]] && !$asroot;then
error "Run as normal user, or use the -f option to run as root."return1fi$cache|| blacklist-update ||return1local ret=0for pkgbuild in"${pkgbuilds[@]}";do
check_deps "$pkgbuild"|| ret=15donereturn$ret}
main "$@"