From e9bc885c355babf7851de31db8e1920dde752993 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 7 Nov 2012 00:17:08 -0500 Subject: organize the files --- src/pkgbuild-check-nonfree | 205 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100755 src/pkgbuild-check-nonfree (limited to 'src/pkgbuild-check-nonfree') diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree new file mode 100755 index 0000000..df0ff36 --- /dev/null +++ b/src/pkgbuild-check-nonfree @@ -0,0 +1,205 @@ +#!/bin/bash +# pkgbuild-check-nonfree +# Copyright 2010 Joshua Ismael Haase Hernández, Joseph Graham + +# ---------- GNU General Public License 3 ---------- + +# 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 . + +# function log_end { +# kill "$teepid" +# rm "$logpipe" +# } + +# function log { +# 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")" +# mkfifo "$logpipe" +# tee "$LOG" < "$logpipe" & +# teepid=$! +# trap log_end ERR EXIT +# } + + +function 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 { + + if [ -e "$1" ]; then + + source "$1" + if [ -n "${pkgname[0]}" ]; then + return 0 # valid PKGBUILD + fi + + fi + + error "$1 is not a valid PKGBUILD" + return 1 +} + +function 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)" + + if [ "$item" == "$needle" ]; then + if [ -z "$rep" ]; then + return 15 # Nonfree (found) + else + echo "$rep" + return 0 # Free (has replacement) + fi + fi + + done + return 0 # Free (not found) +} + +function get_blacklist { # Download the blacklist. + + pushd "$XDG_CONFIG_HOME/libretools" >/dev/null + + msg "Downloading the blacklist of proprietary software packages." + + if ! wget -N -q -O blacklist.txt "${BLACKLIST}" 2>/dev/null; then + + if [ -e "$XDG_CONFIG_HOME/libretools/blacklist.txt" ]; then + warning "Using local copy of blacklist" + else + error "Download failed, exiting" + fi + + fi + + popd > /dev/null +} + +function check_deps { # Check wheter a package depends on non-free + + unset_pkgbuild + + if ! assert_pkgbuild "$1"; then + return 1 # not PKGBUILD + fi + + msg2 "${pkgbase:-${pkgname[0]}} $pkgver $pkgrel ${epoch:-""}" # > "$logpipe" + + for pkg in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ${checkdepends[@]}; do + + lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_")) + + rep="$(check_replacement $pkg ${lines[@]})" + freedom=$? + + if [ "$freedom" -eq 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 { + # TODO: implement PKGBUILD arguments + echo "" + echo "$(basename $0) [options] [PKGBUILD1 PKGBUILD2 ...]" + echo "" + echo "OPTIONS" + echo "" + echo " -h : this message" + echo "" + echo "If no PKGBUILD is specified, one is searched on current directory" + + exit 1 +} + +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 + +shift $(( OPTIND - 1)) + +msg "Looking for unfree dependencies" + +if [ $# -ge 1 ]; then + + for p in $@; do + if [ -n "$p" ]; then + check_deps "$p" + fi + done + +else + + check_deps "`pwd`/PKGBUILD" + +fi + +exit $ev -- cgit v1.2.3-2-g168b From c611090157e9c7d04e6f411c0c5f9ca5834835fd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:43:41 -0500 Subject: pkgbuild-check-nonfree: fix a few errors, clean up This includes the notorious command-not-found error triggered in libremakepkg --- src/pkgbuild-check-nonfree | 139 +++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 80 deletions(-) (limited to 'src/pkgbuild-check-nonfree') 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 . -# 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 "$@" -- cgit v1.2.3-2-g168b From 444cc22bc5cda7a4adc26982d3edbcfd1af426ed Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:44:38 -0500 Subject: add an '-f' flag to pkgbuild-check-nonfree to let libremakepkg run as root --- src/pkgbuild-check-nonfree | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pkgbuild-check-nonfree') diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree index fba4b7b..0fd480c 100755 --- a/src/pkgbuild-check-nonfree +++ b/src/pkgbuild-check-nonfree @@ -146,12 +146,15 @@ usage() { echo "If no PKGBUILD is specified, \`./PKGBUILD' is implied" 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; exit 0;; *) usage; exit 1;; esac @@ -162,7 +165,7 @@ main() { pkgbuilds=("`pwd`/PKGBUILD") fi - if [[ -w / ]]; then + if [[ -w / ]] && ! $asroot; then error "Run as normal user" exit 1 fi -- cgit v1.2.3-2-g168b