#!/bin/bash # $Header$ # bash replacement for the original euse by Arun Bhanu # Author: Marius Mauch # Jared Hancock (Signigicant rewrite for package.use support) # Licensed under the GPL v2 PROGRAM_NAME=euse VERSION="svn" EPREFIX=${EPREFIX:-$(portageq envvar EPREFIX)} ETC="${EPREFIX}/etc" USR_SHARE_PORTAGE="${EPREFIX}/usr/share/portage" # define error functions so they can be used immediately fatal() { echo -e "ERROR: ${*}" set +f exit 1 } error() { echo -e "ERROR: ${*}" } warn() { echo -e "WARNING: ${*}" } # /etc/make.conf can now exist in /etc/portage/make.conf, prefer it over # /etc/make.conf for changes. Since this will only be used for modifying # the USE variable, we need to make sure the one we pick is the one with # the USE variable defined. if [[ -n $(grep '^USE="' "${ETC}/portage/make.conf" 2>/dev/null) ]]; then MAKE_CONF_PATH="${ETC}/portage/make.conf" elif [[ -e "${ETC}/make.conf" ]]; then MAKE_CONF_PATH="${ETC}/make.conf" else fatal "make.conf does not exist" fi MAKE_CONF_BACKUP_PATH="${MAKE_CONF_PATH}.euse_backup" # /etc/make.globals has been moved to /usr/share/portage/config/make.globals if [ -e "${USR_SHARE_PORTAGE}/config/make.globals" ]; then MAKE_GLOBALS_PATH="${USR_SHARE_PORTAGE}/config/make.globals" else MAKE_GLOBALS_PATH="${ETC}/make.globals" fi # /etc/make.profile or /etc/portage/make.profile, if /etc/make.profile exists, it will be used if [ -e "${ETC}/make.profile" ]; then MAKE_PROFILE_PATH="${ETC}/make.profile" elif [ -e "${ETC}/portage/make.profile" ]; then MAKE_PROFILE_PATH="${ETC}/portage/make.profile" else fatal "make.profile does not exist" fi PACKAGE_USE_PATH=${ETC}/portage/package.use [ -z "${MODE:-}" ] && MODE="showhelp" # available operation modes: showhelp, showversion, showdesc, showflags, modify parse_arguments() { if [ -z "${1}" ]; then return fi while [ -n "${1}" ]; do case "${1}" in -h | --help) MODE="showhelp";; -V | -v | --version) MODE="showversion";; -i | --info) MODE="showdesc";; -I | --info-installed) MODE="showinstdesc";; -l | --local) SCOPE="local";; -g | --global) SCOPE="global";; -a | --active) MODE="showflags";; -E | --enable) MODE="modify"; ACTION="add";; -D | --disable) MODE="modify"; ACTION="remove";; -P | --prune | -R | --remove) MODE="modify"; ACTION="prune";; -p | --package) MODE="modify"; shift; PACKAGE=${1}; SCOPE="local";; -*) echo "ERROR: unknown option ${1} specified." echo MODE="showhelp" ;; "%active") get_portageuseflags ARGUMENTS="${ARGUMENTS:-} ${ACTIVE_FLAGS[9]}" ;; *) ARGUMENTS="${ARGUMENTS:-} ${1}" ;; esac shift done } get_real_path() { set -P cd "$1" pwd cd "$OLDPWD" set +P } # Function: check_sanity {{{ # Performs some basic system sanity checks check_sanity() { # file permission tests local descdir local make_defaults local make_conf [[ ! -d "${MAKE_PROFILE_PATH}" || ! -r "${MAKE_PROFILE_PATH}" ]] && error "${MAKE_PROFILE_PATH} is not readable" # for make_conf in $(get_all_make_conf); do [ ! -r "${make_conf}" ] && fatal "${make_conf} is not readable" done descdir="$(get_portdir)/profiles" [ ! -r "${MAKE_GLOBALS_PATH}" ] && fatal "${MAKE_GLOBALS_PATH} is not readable" [ -z "$(get_portdir)" ] && fatal "\$PORTDIR couldn't be determined" [ ! -d "${descdir}" ] && fatal "${descdir} does not exist or is not a directory" [ ! -r "${descdir}/use.desc" ] && fatal "${descdir}/use.desc is not readable" [ ! -r "${descdir}/use.local.desc" ] && fatal "${descdir}/use.local.desc is not readable" for make_defaults in $(get_all_make_defaults); do [ ! -r "$make_defaults" ] && fatal "$_make_defaults is not readable" done [ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && fatal ""${MAKE_CONF_PATH}" is not writable" [ "${MODE}" == "modify" -a -s "${PACKAGE_USE_PATH}" -a ! -w "${PACKAGE_USE_PATH}" ] && fatal ""${PACKAGE_USE_PATH}" is not writable" return 0 } # }}} showhelp() { cat << HELP ${PROGRAM_NAME} (${VERSION}) Syntax: ${PROGRAM_NAME}