diff options
author | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-12-26 00:02:20 -0600 |
---|---|---|
committer | Joshua Ismael Haase Hernández <hahj87@gmail.com> | 2011-12-26 00:02:20 -0600 |
commit | c4eecdae6106541bfd94c17302c7c55b20754adb (patch) | |
tree | b4222d46845da178e41b3e9e362933589a12bd64 | |
parent | 69acc962f6277cf591125ba111716a7c5723e70e (diff) |
pkgbuild-check-nonfree: optimized + checks multiple PKGBUILDS
-rwxr-xr-x | pkgbuild-check-nonfree | 177 |
1 files changed, 142 insertions, 35 deletions
diff --git a/pkgbuild-check-nonfree b/pkgbuild-check-nonfree index fd7b69e..6f365e3 100755 --- a/pkgbuild-check-nonfree +++ b/pkgbuild-check-nonfree @@ -19,80 +19,187 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see <http://www.gnu.org/licenses/>. -source /etc/libretools.conf +# 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 -function in_array { # usage : in_array( $needle, $haystack ) + fi - [[ $2 ]] || return 1 # Not found + error "$1 is not a valid PKGBUILD" + return 1 +} + +function check_replacement { + + [ $2 ] || return 0 # Free (not found) local needle=$1; shift local item - for item in "$@"; do - [[ ${item#@} = $needle ]] && return 0 # Found + 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 1 # Not Found + 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." - wget -N -q -O blacklist.txt "${BLACKLIST}" 2>/dev/null || { - [ -e $XDG_CONFIG_HOME/libretools/blacklist.txt ] || { + + 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" - exit 1 - } - warning "Using local copy of blacklist" - } + fi + + fi + popd > /dev/null } function check_deps { # Check wheter a package depends on non-free - pushd "$XDG_CONFIG_HOME/libretools/" >/dev/null - local unfree=($(cut -d: -f1 blacklist.txt)) # pkgname:free-replacement:comments - local freerep=($(cut -d: -f2 blacklist.txt)) # pkgname:free-replacement:comments - popd >/dev/null + unset_pkgbuild - msg "Looking for unfree dependencies" - for item in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ; do + if ! assert_pkgbuild "$1"; then + return 1 # not PKGBUILD + fi - if in_array $item ${unfree[@]} ; then + msg "${pkgbase:-${pkgname[0]}} $pkgver $pkgrel ${epoch:-""}" # > "$logpipe" - if in_array $item ${freerep[@]} ; then - warning "$item is repackaged with the same name." - continue + for pkg in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ${checkdepends[@]}; do + + lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_")) + + rep="$(check_replacement $pkg ${lines[@]})" + freedom=$? - elif in_array $item-libre ${freerep[@]} ; then - warning "$item -> $item-libre" + if [ "$freedom" -eq 15 ]; then + warning "found $pkg" # > "$logpipe" + ev=15 + continue + + elif [ -n "$rep" ]; then + + if [ "$rep" = "$pkg" ]; then + msg2 "$pkg is repackaged with the same name." # > "$logpipe" continue else - ev=15 - msg2 "found $item" + msg2 "$pkg -> $rep" # > "$logpipe" + continue fi + fi + done + } -if [ -e $XDG_CONFIG_HOME/libretools/libretools.conf ]; then - source $XDG_CONFIG_HOME/libretools/libretools.conf +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 (( ! EUID )); then + error "Run as normal user" fi -if [ -z "${BLACKLIST}" ]; then - error "BLACKLIST variable is not set your libretools.conf file"; exit 1 +source /etc/libretools.conf +if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then + source "$XDG_CONFIG_HOME/libretools/libretools.conf" fi -if [ -r PKGBUILD ]; then - source PKGBUILD -else - error "There is no PKGBUILD in dir"; exit 1 +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 [ $# -gt 1 ]; then + + for p in $@; do + if [ -n "$p" ]; then + check_deps "$p" + fi + done + +else + + check_deps "`pwd`/PKGBUILD" -check_deps +fi exit $ev |