summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/pkgbuild-check-nonfree139
1 files changed, 59 insertions, 80 deletions
diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree
index df0ff36..fba4b7b 100755
--- a/src/pkgbuild-check-nonfree
+++ b/src/pkgbuild-check-nonfree
@@ -1,6 +1,7 @@
#!/bin/bash
# pkgbuild-check-nonfree
# Copyright 2010 Joshua Ismael Haase Hernández, Joseph Graham
+# Copyright 2012 Luke Shumaker
# ---------- GNU General Public License 3 ----------
@@ -19,15 +20,20 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-# function log_end {
+. /etc/libretools.conf
+
+cmd=${0##*/}
+ev=0
+
+# log_end() {
# kill "$teepid"
# rm "$logpipe"
# }
-# function log {
-# LOG="pkgbuild-check-nonfree-$(date -u +%Y%m%d).log"
+# log() {
+# local LOG="pkgbuild-check-nonfree-$(date -u +%Y%m%d).log"
# # ensure overridden package variables survive tee with split packages
-# logpipe="$(mktemp -u "$startdir/logpipe.XXXXXXXX")"
+# logpipe="$(mktemp)"
# mkfifo "$logpipe"
# tee "$LOG" < "$logpipe" &
# teepid=$!
@@ -35,18 +41,15 @@
# }
-function unset_pkgbuild {
-
+unset_pkgbuild() {
unset 'pkgbase' 'pkgname' 'pkgver' 'pkgrel' 'epoch' 'pkgdesc' \
'arch' 'url' 'license' 'groups' 'optdepends' 'provides' \
'conflicts' 'replaces' 'backup' 'options' 'install' \
'changelog' 'source' 'noextract' 'md5sums' 'build' \
'check' 'package' 'depends' 'makedepends' 'checkdepends'
-
}
-function assert_pkgbuild {
-
+assert_pkgbuild() {
if [ -e "$1" ]; then
source "$1"
@@ -60,16 +63,15 @@ function assert_pkgbuild {
return 1
}
-function check_replacement {
-
+check_replacement() {
[ $2 ] || return 0 # Free (not found)
local needle=$1; shift
local item
local rep
for line in $@; do
- item="$(echo "$line" | cut -d':' -f1)"
- rep="$(echo "$line" | cut -s -d':' -f2)"
+ local item="$(echo "$line" | cut -d':' -f1)"
+ local rep="$(echo "$line" | cut -s -d':' -f2)"
if [ "$item" == "$needle" ]; then
if [ -z "$rep" ]; then
@@ -84,8 +86,11 @@ function check_replacement {
return 0 # Free (not found)
}
-function get_blacklist { # Download the blacklist.
-
+##
+# Download the blacklist.
+##
+get_blacklist() {
+ mkdir -p "$XDG_CONFIG_HOME/libretools"
pushd "$XDG_CONFIG_HOME/libretools" >/dev/null
msg "Downloading the blacklist of proprietary software packages."
@@ -103,103 +108,77 @@ function get_blacklist { # Download the blacklist.
popd > /dev/null
}
-function check_deps { # Check wheter a package depends on non-free
-
+##
+# Check wheter a package depends on non-free
+##
+check_deps() {
unset_pkgbuild
-
if ! assert_pkgbuild "$1"; then
- return 1 # not PKGBUILD
+ exit 1 # not PKGBUILD
fi
msg2 "${pkgbase:-${pkgname[0]}} $pkgver $pkgrel ${epoch:-""}" # > "$logpipe"
- for pkg in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ${checkdepends[@]}; do
+ for pkg in "${pkgname[@]}" "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"; do
- lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_"))
+ local lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_"))
- rep="$(check_replacement $pkg ${lines[@]})"
- freedom=$?
+ local rep="$(check_replacement $pkg ${lines[@]})"
+ local freedom=$?
- if [ "$freedom" -eq 15 ]; then
+ if [[ $freedom = 15 ]]; then
warning "found $pkg" # > "$logpipe"
ev=15
- continue
-
elif [ -n "$rep" ]; then
-
if [ "$rep" = "$pkg" ]; then
plain "$pkg is repackaged with the same name." # > "$logpipe"
- continue
else
plain "$pkg -> $rep" # > "$logpipe"
- continue
fi
-
fi
-
done
-
}
-function usage {
+usage() {
# TODO: implement PKGBUILD arguments
+ echo "Usage: $cmd [OPTIONS] [PKGBUILD1 PKGBUILD2 ...]"
echo ""
- echo "$(basename $0) [options] [PKGBUILD1 PKGBUILD2 ...]"
- echo ""
- echo "OPTIONS"
+ echo "If no PKGBUILD is specified, \`./PKGBUILD' is implied"
echo ""
- echo " -h : this message"
- echo ""
- echo "If no PKGBUILD is specified, one is searched on current directory"
-
- exit 1
+ echo "Options:"
+ echo " -h Show this message"
}
-while getopts 'h' arg; do
- case "$arg" in
- h) usage ;;
- esac
-done
-
-if [ -w / ]; then
- error "Run as normal user"
-fi
-
-source /etc/libretools.conf
-if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then
- source "$XDG_CONFIG_HOME/libretools/libretools.conf"
-fi
-
-if [ -z "${BLACKLIST}" ]; then
- error "BLACKLIST variable is not set your libretools.conf file"
- exit 1
-fi
-
-if [ ! -d "$XDG_CONFIG_HOME/libretools" ]; then
- mkdir -p "$XDG_CONFIG_HOME/libretools"
-fi
-
-startdir=`pwd`
-
-get_blacklist
-# log
+main() {
+ while getopts 'fh' arg; do
+ case "$arg" in
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ pkgbuilds=("$@")
+ if [[ $# < 1 ]]; then
+ pkgbuilds=("`pwd`/PKGBUILD")
+ fi
-shift $(( OPTIND - 1))
+ if [[ -w / ]]; then
+ error "Run as normal user"
+ exit 1
+ fi
-msg "Looking for unfree dependencies"
+ get_blacklist
+ # log
-if [ $# -ge 1 ]; then
+ msg "Looking for unfree dependencies"
- for p in $@; do
- if [ -n "$p" ]; then
+ for p in "${pkgbuilds[@]}"; do
+ if [[ -n "$p" ]]; then
check_deps "$p"
fi
done
-else
-
- check_deps "`pwd`/PKGBUILD"
-
-fi
+ return $ev
+}
-exit $ev
+main "$@"