summaryrefslogtreecommitdiff
path: root/src/pkgbuild-check-nonfree
diff options
context:
space:
mode:
authorNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-11-30 01:00:18 -0300
committerNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-11-30 01:00:18 -0300
commitb021874d73c9dded2e05f2095efa5c3a6d23b496 (patch)
treeb2b9a7bd88f0476accd17d23c1ef53c7cc920be7 /src/pkgbuild-check-nonfree
parent73b813613aa08646515f4e06c71503b18125cec3 (diff)
parentba312fb72ec0843297978796a20c6ffc1fe3ef6e (diff)
Merge branch 'master' of http://projects.parabolagnulinux.org/libretools
Conflicts: src/aur src/chroot-tools/librechroot src/librerepkg
Diffstat (limited to 'src/pkgbuild-check-nonfree')
-rwxr-xr-xsrc/pkgbuild-check-nonfree142
1 files changed, 62 insertions, 80 deletions
diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree
index df0ff36..0fd480c 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,80 @@ 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 " -f Allow running as root user"
+ 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() {
+ local asroot=false
+ while getopts 'fh' arg; do
+ case "$arg" in
+ f) asroot=true;;
+ 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 / ]] && ! $asroot; 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 "$@"