#!/bin/bash # $Header$ # bash replacement for the original euse by Arun Bhanu # Author: Marius Mauch # Licensed under the GPL v2 PROGRAM_NAME=euse PROGRAM_VERSION=$(cat /usr/share/gentoolkit/VERSION) MAKE_CONF_PATH=/etc/make.conf MAKE_GLOBALS_PATH=/etc/make.globals MAKE_PROFILE_PATH=/etc/make.profile MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup 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) 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 } fatal() { echo -e "${*}" | sed -e "s/^/ERROR: /g" set +f exit 1 } error() { echo -e "${*}" | sed -e "s/^/ERROR: /g" } warn() { echo -e "${*}" | sed -e "s/^/WARNING: /g" } 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 descdir="$(get_portdir)/profiles" [ ! -r "${MAKE_CONF_PATH}" ] && fatal "${MAKE_CONF_PATH} is not readable" [ ! -r "${MAKE_GLOBALS_PATH}" ] && fatal "${MAKE_GLOBALS_PATH} is not readable" [ ! -h "${MAKE_PROFILE_PATH}" ] && fatal "${MAKE_PROFILE_PATH} is not a symlink" [ -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" } # }}} showhelp() { cat << HELP ${PROGRAM_NAME} (${PROGRAM_VERSION}-JJ0) Syntax: ${PROGRAM_NAME}