summaryrefslogtreecommitdiff
path: root/src/pkgbuild-summarize-nonfree
blob: 9b3d8e6817604a972dd13b74c72809c3ec842265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# Copyright (C) 2013 Luke Shumaker <lukeshu@sbcglobal.net>
#
# License: GNU GPLv3+
#
# 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/>.

. $(librelib messages)

# Make sure these match pkgbuild-check-nonfree
declare -ri _E_OK=0
declare -ri _E_ERROR=1
declare -ri _E_LIC_UNKNOWN=2
declare -ri _E_LIC_NOGPL=4
declare -ri _E_LIC_NONFREE=8
declare -ri _E_DEP_NONFREE=16
declare -ri _E_PKG_NONFREE=32

usage() {
	print "Usage: %s [OPTIONS] STATUS" "${0##*/}"
	print "Summarizes a status code from pkgbuild-check-nonfree"
	echo
	prose 'It thresholds the issues it finds, only failing for error-level
	       issues, and ignoring warnings.  Unless `-q` is specified, it also
	       prints a summary of the issues it found.'
	echo
	print 'Options:'
	flag '-q' 'Be quiet'
	flag '-h' 'Show this message'
}

main() {
	local quiet=false
	while getopts 'qh' arg; do
		case "$arg" in
			q) quiet=true;;
			h) usage; return 0;;
			*) usage >&2; return 1;;
		esac
	done
	shift $(($OPTIND - 1))
	if [[ $# -ne 1 ]]; then
		usage >&2
		return 1
	fi
	if ! [[ $1 =~ ^[0-9]+$ ]]; then
		error 'STATUS must be an integer'
		usage >&2
		return 1
	fi

	if $quiet; then
		error() { :; }
		warning() { :; }
	fi

	parse $1;
	return $?
}

parse() {
	[[ $# == 1 ]] || panic 'malformed call to parse'
	declare -i s=$1;

	declare -i ret=0
	declare -i i
	for i in 1 2 4 8 16 32; do
		if [[ $(($s & $i)) -gt 0 ]]; then
			case $i in
				$_E_ERROR)
					# could be anything, assume the worst
					error "There was an error processing the PKGBUILD"
					ret=1;;
				$_E_LIC_UNKNOWN)
					warning "This PKGBUILD has an unknown license";;
				$_E_LIC_NOGPL)
					warning "This PKGBUILD has a GPL-incompatible license";;
				$_E_LIC_NONFREE)
					error "This PKGBUILD has a known nonfree license"
					ret=1;;
				$_E_DEP_NONFREE)
					error "This PKGBUILD depends on known nonfree packages"
					ret=1;;
				$_E_PKG_NONFREE)
					error "This PKGBUILD is for a known nonfree package"
					ret=1;;
			esac
		fi
	done
	return $ret
}

main "$@"