blob: ada95b57e6d8b42a3e87f97fb81c8edcbf35ec6d (
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#!/bin/bash
# pkgbuild-check-nonfree
# Copyright 2010 Joshua Ismael Haase Hernández, Joseph Graham
# 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
. /usr/share/libretools/conf.sh
# 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: blacklist_lookup $pkg
# Look up the blacklist entry for $pkg
blacklist_lookup() {
local pkg=$1
sed 's/^/^/;s/$/:/' "$XDG_CONFIG_HOME/libretools/blacklist.txt" |
grep -F "^$pkg:" |
sed 's/^^//;s/:*$//'
}
# Usage: update_blacklist $url
# Update the cached blacklist file
update_blacklist() {
local remote_blacklist="$1"
local local_blacklist="$XDG_CONFIG_HOME/libretools/blacklist.txt"
stat_busy "Downloading blacklist of proprietary software packages"
mkdir -p "${local_blacklist%/*}"
if wget -N -q -O "${local_blacklist}.part" "$remote_blacklist" 2>/dev/null; then
stat_done
mv "${local_blacklist}.part" "$local_blacklist"
else
stat_done
rm "${local_blacklist}.part"
if [[ -e "$XDG_CONFIG_HOME/libretools/blacklist.txt" ]]; then
warning "Using local copy of blacklist"
else
error "Download failed, exiting"
return 1
fi
fi
}
# 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 up
local pkgbuild=$1
. "$pkgbuild"
if [[ -z "$pkgname" ]]; then
return 1 # not a PKGBUILD
fi
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=0
for pkg in "${pkgs[@]}"; do
local line="$(blacklist_lookup $pkg)"
local rep="$(cut -d: -f2 <<<"$line:")"
if [[ -z $line ]]; then
# not mentioned in blacklist; free
plain "$pkg: free"
continue
elif [[ -z $rep ]]; then
# non-free with no replacement
plain "$pkg: non-free"
ret=1
else
# non-free with free replacement
if [[ "$rep" == "$pkg" ]]; then
plain "$pkg: repackaged with the same name."
else
plain "$pkg: replaced by $rep"
fi
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:"
echo " 0: Everything OK, no freedom issues"
echo " 1: Ran with error"
echo " 15: Depends on non-free packages"
echo ''
echo "Options:"
echo ' -f Allow running as root user'
echo ' -h Show this message'
}
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
load_conf_libretools || return 1 # load ${BLACKLIST}
update_blacklist "$BLACKLIST" || return 1
local ret=0
for pkgbuild in "${pkgbuilds[@]}"; do
check_deps "$pkgbuild" || ret=15
done
return $ret
}
main "$@"
|