#!/bin/bash database=/etc/portage/package.keywords tempfile=/tmp/keywords.$$ cleanup() { rm -f ${tempfile} } die() { echo "${0//#*\//}: $*" >&2 exit 1 } append-package() { local package=${1} local keyword=${2:-~x86} test -z "${package}" && die "No package specified" echo "${package} ${keyword}" >> ${database} } remove-packages() { if show-packages "$@" then echo "Press RETURN to remove those packages." read GREPFLAGS=-v show-packages "$@" > ${tempfile} diff -u "${database}" "${tempfile}" echo "Press RETURN to apply this changes." read mv "${tempfile}" "${database}" else echo "No matches found." fi } show-packages() { test $# = 0 && die "No packages specified" local pattern="$*" pattern="${pattern// /\\|}" pattern="${pattern//./\\.}" grep ${GREPFLAGS} "^\(=\|>=\|<=\)\?\(${pattern}\)" < ${database} } check-keyword() { local keyword=$1; shift grep -q "^KEYWORDS=.*[\"[:space:]]${keyword}\>" "$@" } check-packages() { sed -ne 's|^=\(\S\+\)/\(\S*\)-\([0-9.*]\+[a-z]\?\(_\w\+[0-9]\+\)\?\(-r[0-9]\+\)\?\)\s.*|\1 \2 \3|p' < ${database} | while read category package version do test -d "/usr/portage/${category}" || echo "Bad category: ${category}" local cdirs=$(find /usr/{portage,local/overlay/*} -type d -name ${category} -maxdepth 1) local pdirs=$(find ${cdirs} -type d -maxdepth 1 -name ${package}) if test -n "${pdirs}" then local efiles=$(find ${pdirs} -type f -maxdepth 1 -name "${package}-${version}.ebuild") if test -z "${efiles}" then local stable= unstable= for ebuild in $( find ${pdirs} -type f -maxdepth 1 -name "*.ebuild") do ev=$(echo ${ebuild} | sed -e "s|.*/||" -e "s|^${package}-||" -e "s|\.ebuild$||g") { check-keyword 'x86' ${ebuild} && stable="${stable} ${ev}"; } || { check-keyword '~x86' ${ebuild} && unstable="${unstable} ${ev}"; } done stable=${stable/# /} unstable=${unstable/# /} echo "No ebuild found: ${category}/${package}-${version} [${stable:-none}][${unstable:-none}]" elif echo "${version}" | fgrep -q -v '*' then check-keyword '~x86' ${efiles} || { check-keyword 'x86' ${efiles} && echo "Ebuild is stable: ${category}/${package}-${version}" || echo "Platform not supported: ${category}/${package}-${version}" } fi else echo "Bad package: ${category}/${package}" fi done } show-usage() { cat <