#!/Users/tetsushi/Gentoo/bin/bash
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# Where are our data?
ESELECT_DATA_PATH="/Users/tetsushi/Gentoo/usr/share/eselect"
# Where are modules installed by default?
ESELECT_DEFAULT_MODULES_PATH="${ESELECT_DATA_PATH}/modules"
# Look in these places for modules
ESELECT_MODULES_PATH=( \
"${HOME}/.eselect/modules" \
"${ESELECT_DEFAULT_MODULES_PATH}" )
# Look in this place for libraries
ESELECT_CORE_PATH="${ESELECT_DATA_PATH}/libs"
# Look here for the default contents of a module
ESELECT_DEFAULT_ACTIONS="${ESELECT_CORE_PATH}/default.eselect"
# Our program name and version
ESELECT_VERSION="1.3.5"
ESELECT_PROGRAM_NAME="eselect"
# Invocation information
ESELECT_BINARY_NAME="$0"
ESELECT_KILL_TARGET="$$"
# Support variables for Gentoo Prefix
EPREFIX="/Users/tetsushi/Gentoo"
EROOT="${ROOT%${EPREFIX:+/}}${EPREFIX}"
# Remove all alias definitions. Unset functions and variables that are
# known to cause trouble.
"unalias" -a
unset -f rm
unset CDPATH GLOBIGNORE
IFS=$' \t\n'
shopt -s extglob
shopt -s expand_aliases
# Save stderr file descriptor
# exec {ESELECT_STDERR}>&2 # >=bash-4.1
exec 3>&2
ESELECT_STDERR=3
# Load core functions
source "${ESELECT_CORE_PATH}/core.bash" || exit 255
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# check_do function args
# Check that function exists, and call it with args.
check_do() {
local function=$1
shift
if is_function "${function}" ; then
${function} "$@"
else
die "No function ${function}"
fi
}
# die [-q] "Message" PUBLIC
# Display "Message" as an error. If -q is not provided, gives a stacktrace.
die() {
local item funcname="" sourcefile="" lineno="" n e s="yes"
# Restore stderr if it was redirected
exec 2>&${ESELECT_STDERR}
# do we have a working write_error_msg?
if is_function "write_error_msg"; then
e="write_error_msg"
else
e="echo"
fi
# quiet?
if [[ $1 == "-q" ]]; then
s=""
shift
fi
$e "${@:-(no message)}" >&2
if [[ -n ${s} ]]; then
echo "Call stack:" >&2
for (( n = 1; n < ${#FUNCNAME[@]}; ++n )); do
funcname=${FUNCNAME[n]}
sourcefile=$(basename ${BASH_SOURCE[n]})
lineno=${BASH_LINENO[n-1]}
echo " * ${funcname} (${sourcefile}:${lineno})" >&2
done
fi
# Evil, but effective.
kill ${ESELECT_KILL_TARGET}
exit 249
}
# do_action action args...
# Load and do 'action' with the specified args
do_action() {
local action="${1##--}" modfile="" subaction="${2##--}"
[[ -z ${action} ]] && die "Usage: do_action "
shift; shift
ESELECT_MODULE_NAME="${action}"
ESELECT_COMMAND="${ESELECT_PROGRAM_NAME} ${ESELECT_MODULE_NAME}"
[[ ${ESELECT_BINARY_NAME##*/} != "${ESELECT_PROGRAM_NAME}" ]] \
&& ESELECT_COMMAND="${ESELECT_BINARY_NAME##*/}"
modfile=$( es_find_module "${action}" )
(
source "$ESELECT_DEFAULT_ACTIONS" 2>/dev/null \
|| die "Couldn't source ${ESELECT_DEFAULT_ACTIONS}"
source "${modfile}" 2>/dev/null \
|| die "Couldn't source ${modfile}"
if [[ -z ${subaction} ]]; then
check_do "do_${DEFAULT_ACTION:-usage}" "$@"
else
is_function "do_${subaction}" \
|| die -q "Action ${subaction} unknown"
check_do "do_${subaction}" "$@"
fi
)
}
# inherit module PUBLIC
# Sources a given eselect library file
inherit() {
local x
for x in "$@"; do
[[ -e ${ESELECT_CORE_PATH}/${x}.bash ]] \
|| die "Couldn't find ${x}.bash"
source "${ESELECT_CORE_PATH}/${x}.bash" \
|| die "Couldn't source ${x}.bash"
done
}
# GNU sed wrapper (real path to GNU sed determined by configure)
sed() {
/Users/tetsushi/Gentoo/bin/sed "$@"
}
# Load necessary functions for the main script
inherit manip output path-manipulation tests
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# svn_date_to_version PUBLIC
# Turn an SVN or CVS date string into a nice version number, for those
# of us who are too lazy to manually update VERSION in modules. Safe to
# use in global scope.
svn_date_to_version() {
local s=${1}
s=${s#* }
s=${s%% *}
echo "${s//[-\/]}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# Colours
colours() {
COLOUR_NORMAL=$(tput sgr0)
COLOUR_BOLD=$(tput bold)
COLOUR_HI=$(tput setaf 4)${COLOUR_BOLD} # blue
COLOUR_WARN=$(tput setaf 1)${COLOUR_BOLD} # red
COLOUR_ERROR=${COLOUR_WARN}
COLOUR_LIST_HEADER=$(tput setaf 2)${COLOUR_BOLD} # green
COLOUR_LIST_LEFT=${COLOUR_BOLD}
COLOUR_LIST_RIGHT=${COLOUR_NORMAL}
}
# disable all colours
nocolours() {
COLOUR_NORMAL=""
COLOUR_BOLD=""
COLOUR_HI=""
COLOUR_WARN=""
COLOUR_ERROR=""
COLOUR_LIST_HEADER=""
COLOUR_LIST_LEFT=""
COLOUR_LIST_RIGHT=""
}
# set output mode to $1
set_output_mode() {
ESELECT_OUTPUT_MODE=${1}
}
# is_output_mode PUBLIC
# test if $1 is the current output mode
is_output_mode() {
[[ ${ESELECT_OUTPUT_MODE} = ${1} ]]
}
# Determine width of terminal and set COLUMNS variable
init_columns() {
[[ -n ${COLUMNS} ]] || COLUMNS=$(tput cols) || COLUMNS=80
}
# write_error_msg PUBLIC
# write an error
write_error_msg() {
echo -e "${COLOUR_ERROR}!!! Error: ${COLOUR_NORMAL}${*}" 1>&2
}
# write_warning_msg PUBLIC
# write a warning
write_warning_msg() {
echo -e "${COLOUR_WARN}!!! Warning: ${COLOUR_NORMAL}${*}" 1>&2
}
# write_list_start PUBLIC
# Write a list heading. Args may include text highlighting. If -p is passed,
# use 'plain' highlighting.
write_list_start() {
is_output_mode brief && return
local colour=${COLOUR_LIST_HEADER} normal=${COLOUR_NORMAL}
if [[ ${1} == "-p" ]] ; then
colour=; normal=
shift
fi
echo -n -e "${colour}"
echo -n -e "$(apply_text_highlights "${colour}" "$*")"
echo -n -e "${normal}"
echo
}
# write_kv_list_entry PUBLIC
# Write a key/value list entry with $1 on the left and $2 on the right.
# Args may include text highlighting. If -p is passed, use 'plain'
# highlighting rather than bold.
write_kv_list_entry() {
local n text key val lindent rindent ifs_save=${IFS}
local left=${COLOUR_LIST_LEFT} right=${COLOUR_LIST_RIGHT}
local normal=${COLOUR_NORMAL}
IFS=$' \t\n'
if [[ ${1} == "-p" ]] ; then
left=; right=; normal=
shift
fi
lindent=${1%%[^[:space:]]*}
rindent=${2%%[^[:space:]]*}
key=${1##*([[:space:]])}
val=${2##*([[:space:]])}
echo -n -e " ${lindent}${left}"
echo -n -e "$(apply_text_highlights "${left}" "${key}")"
echo -n -e "${normal}"
text=${key//\%%%??%%%/}
n=$(( 26 + ${#rindent} - ${#lindent} - ${#text} ))
# if ${n} is less than or equal to zero then we have a long ${key}
# that will mess up the formatting of ${val}, so end the line, indent
# and let ${val} go on the next line.
if [[ ${n} -le 0 ]] ; then
echo
n=$(( 28 + ${#rindent} ))
fi
space ${n}
echo -n -e "${right}"
n=$(( 28 + ${#rindent} ))
local cols=${COLUMNS:-80}
local cwords=$(apply_text_highlights "${right}" "${val}")
text=${val//\%%%??%%%/}
# only loop if it doesn't fit on the same line
if [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then
local i=0 spc=""
rindent=$(space ${n})
cwords=( ${cwords} )
for text in ${val} ; do
text=${text//\%%%??%%%/}
# put the word on the same line if it fits
if [[ $(( ${n} + ${#spc} + ${#text} )) -lt ${cols} ]] ; then
echo -n -e "${spc}${cwords[i]}"
n=$(( ${n} + ${#spc} + ${#text} ))
# otherwise, start a new line and indent
else
echo -n -e "\n${rindent}${cwords[i]}"
n=$(( ${#rindent} + ${#text} ))
fi
i=$(( ${i} + 1 ))
spc=" "
done
else
echo -n -e "${cwords}"
fi
echo -e "${normal}"
IFS=${ifs_save}
}
# write_numbered_list_entry PUBLIC
# Write out a numbered list entry with index $1 and text $2. Args may
# include text highlighting. If -p is passed, use 'plain' highlighting.
write_numbered_list_entry() {
local left=${COLOUR_LIST_LEFT} right=${COLOUR_LIST_RIGHT}
local normal=${COLOUR_NORMAL}
if [[ ${1} == "-p" ]] ; then
left=; right=; normal=
shift
fi
if ! is_output_mode brief; then
echo -n -e " ${left}"
echo -n -e "[$(apply_text_highlights "${left}" "$1")]"
echo -n -e "${normal}"
space $(( 4 - ${#1} ))
fi
echo -n -e "${right}"
echo -n -e "$(apply_text_highlights "${right}" "$2")"
echo -e "${normal}"
}
# write_numbered_list PUBLIC
# Write out a numbered list. Args may include text highlighting.
# If called with the -m option and an empty list, output a negative report.
write_numbered_list() {
local n=1 m p
while [[ $1 == -* ]]; do
case $1 in
"-m") shift; m=$1 ;;
"-p") p="-p" ;;
"--") shift; break ;;
esac
shift
done
if [[ $# -eq 0 && -n ${m} ]] && ! is_output_mode brief; then
write_kv_list_entry ${p} "${m}" ""
fi
while [[ $# -gt 0 ]] ; do
item=${1}
shift
if [[ ${item##*\\} == "" ]] ; then
item="${item%\\} ${1}"
shift
fi
write_numbered_list_entry ${p} "${n}" "${item}"
n=$(( ${n} + 1 ))
done
}
# apply_text_highlights INTERNAL
# Apply text highlights. First arg is the 'restore' colour, second arg
# is the text.
apply_text_highlights() {
local restore=${1:-${COLOUR_NORMAL}} text=${2}
text="${text//?%%HI%%%/${COLOUR_HI}}"
text="${text//?%%WA%%%/${COLOUR_WARN}}"
text="${text//?%%RE%%%/${restore}}"
echo -n "${text}"
}
# highlight PUBLIC
# Highlight all arguments. Text highlighting function.
highlight() {
echo -n "%%%HI%%%${*}%%%RE%%%"
}
# highlight_warning PUBLIC
# Highlight all arguments as a warning (red). Text highlighting function.
highlight_warning() {
echo -n "%%%WA%%%${*}%%%RE%%%"
}
# highlight_marker PUBLIC
# Mark list entry $1 as active/selected by placing a highlighted star
# (or $2 if set) behind it.
highlight_marker() {
local text=${1} mark=${2-*}
echo -n "${text}"
if [[ -n ${mark} ]] && ! is_output_mode brief; then
echo -n " "
highlight "${mark}"
fi
}
# space PUBLIC
# Write $1 numbers of spaces
space() {
local n ret=""
for (( n = 1 ; n <= ${1} ; ++n )) ; do
ret="${ret} "
done
echo -n "${ret}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# basename and dirname functions
# transparent bash-only replacements for the external commands
# extended pattern matching (shopt -s extglob) is required
basename() {
local path=$1 suf=$2
if [[ -z ${path} ]]; then
echo
return
fi
# remove any trailing slashes
path=${path%%*(/)}
# remove everything up to and including the last slash
path=${path##*/}
# remove any suffix
[[ ${suf} != "${path}" ]] && path=${path%"${suf}"}
# output the result, or "/" if we ended up with a null string
echo "${path:-/}"
}
dirname() {
local path=$1
if [[ -z ${path} ]]; then
echo .
return
fi
# remove any trailing slashes
path=${path%%*(/)}
# if the path contains only non-slash characters, then dirname is cwd
[[ ${path:-/} != */* ]] && path=.
# remove any trailing slashes followed by non-slash characters
path=${path%/*}
path=${path%%*(/)}
# output the result, or "/" if we ended up with a null string
echo "${path:-/}"
}
# Wrapper function for either GNU "readlink -f" or "realpath".
canonicalise() {
/Users/tetsushi/Gentoo/usr/bin/readlink -f "$@"
}
# relative_name
# Convert filename $1 to be relative to directory $2.
# For both paths, all but the last component must exist.
relative_name() {
local path=$(canonicalise "$1") dir=$(canonicalise "$2") c
while [[ -n ${dir} ]]; do
c=${dir%%/*}
dir=${dir##"${c}"*(/)}
if [[ ${path%%/*} = "${c}" ]]; then
path=${path##"${c}"*(/)}
else
path=..${path:+/}${path}
fi
done
echo "${path:-.}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# has test list
# Return true if list contains test
has() {
local test=${1} item
shift
for item in "$@" ; do
[[ ${item} == ${test} ]] && return 0
done
return 1
}
# is_function function PUBLIC
# Test whether function exists
is_function() {
[[ $(type -t "${1}" ) == "function" ]]
}
# is_number PUBLIC
# Returns true if and only if $1 is a positive whole number
is_number() {
[[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
}
# Sneaky trick to make die in subshells work. If you don't get
# it, don't ask...
trap 'echo "exiting" >&2; exit 250' 15
# es_find_module foo
# Find and echo the filename of the foo module. If there's no foo module,
# die.
es_find_module() {
local modname="$1" modpath="" modfile=""
[[ -z ${modname} ]] && die "Usage: ${FUNCNAME} "
for modpath in "${ESELECT_MODULES_PATH[@]}"; do
[[ -f ${modpath}/${modname}.eselect ]] && break
done
modfile="${modpath}/${modname}.eselect"
[[ -r ${modfile} ]] || die -q "Can't load module ${modname}"
echo ${modfile}
}
# es_do_usage
# Display eselect usage
es_do_usage() {
echo "Usage: eselect "
}
# es_do_help
# Display eselect help
es_do_help() {
set_output_mode default
es_do_usage
echo
es_do_list_options
echo
es_do_list_modules
}
# es_do_version
# Display eselect version
es_do_version() {
echo "eselect ${ESELECT_VERSION}"
echo
echo "Copyright (c) 2005-2013 Gentoo Foundation."
echo "Distributed under the terms of the GNU GPL version 2 or later."
}
# es_do_list_options
# Display all recognized global options
es_do_list_options() {
write_list_start "Global options:"
write_kv_list_entry "--brief" "Make output shorter"
write_kv_list_entry "--colour=" \
"Enable or disable colour output (default 'auto')"
}
# es_do_list_modules
# Display all available eselect modules DEPRECATED
es_do_list_modules() {
do_action modules list "$@"
}
### main code ###
# figure out what the action is. we need to know whether we're
# invoked as a something-config/something-update.
action=""
for suffix in config update{,r} tool manager reader; do
if [[ ${0%%-${suffix}} != "$0" ]]; then
action=$(basename "$0")
action=${action%%-${suffix}}
break
fi
done
unset suffix
if [[ -z ${action} ]]; then
binname=$(basename "$0")
for prefix in config update{,r} manage 'read'; do
if [[ ${binname##${prefix}-} != ${binname} ]]; then
action=$(basename "$0")
action=${action##${prefix}-}
break
fi
done
unset binname prefix
fi
basename "$0"
if [[ -z ${action} ]] && [[ -n ${1##--} ]]; then
while [[ ${1##--} != "$1" ]]; do
case ${1##--} in
brief)
set_output_mode brief
;;
colour=*|color=*|colour|color)
# accept all arguments that are valid for ls or emerge
case ${1#*=} in
yes|y|always|force|$1) colour=yes ;;
no|n|never|none) colour=no ;;
auto|tty|if-tty) colour="" ;;
*) die -q "Invalid argument for ${1%%=*} option" ;;
esac
;;
no-colour|no-color) # legacy option
colour=no
;;
help|version)
action=${1##--}
;;
*)
die -q "Unknown option $1"
;;
esac
shift
done
if [[ -z ${action} ]]; then
action=$1
shift
fi
fi
# enable colour output and get width of terminal iff stdout is a tty
if [[ -t 1 ]]; then
if [[ ${colour} = no ]]; then nocolours; else colours; fi
init_columns
else
if [[ ${colour} = yes ]]; then colours; else nocolours; fi
fi
unset colour
if [[ -n ${action} ]]; then
if is_function "es_do_${action//-/_}"; then
[[ $# -gt 0 ]] && die -q "Too many parameters"
es_do_${action//-/_}
else
do_action "${action}" "$@"
fi
else
es_do_help
fi
Usage: eselect
apply_text_highlights "${colour}" "$*"
Global options:
apply_text_highlights "${left}" "${key}"
--brief apply_text_highlights "${right}" "${val}"
Make output shorter
apply_text_highlights "${left}" "${key}"
--colour= apply_text_highlights "${right}" "${val}"
Enable or disable colour output (default 'auto')
es_find_module "${action}"
type -t "${1}"
type -t "${1}"
apply_text_highlights "${colour}" "$*"
Built-in modules:
apply_text_highlights "${left}" "${key}"
help apply_text_highlights "${right}" "${val}"
Display a help message
apply_text_highlights "${left}" "${key}"
usage apply_text_highlights "${right}" "${val}"
Display a usage message
apply_text_highlights "${left}" "${key}"
version apply_text_highlights "${right}" "${val}"
Display version information
apply_text_highlights "${colour}" "$*"
Extra modules:
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
DESCRIPTION="Manage contributed bash-completion scripts"
MAINTAINER="eselect@gentoo.org"
find_targets() {
local bcdir bc
for bcdir in "${EROOT%/}/usr/share/bash-completion" ${ES_BASHCOMP_DIRS}
do
for bc in "${bcdir}"/*; do
[[ -f ${bc} && ${bc} != *~ ]] && basename "${bc}"
done
done | sort -u
}
is_enabled() {
local bcdir
bcdir=${ROOT%/}/${HOME}/.bash_completion.d
if [[ $1 == "--global" ]]; then
bcdir=${EROOT%/}/etc/bash_completion.d
shift
fi
[[ -e ${bcdir}/$1 ]]
}
### list action ###
describe_list() {
echo "List available completions"
}
describe_list_options() {
echo "--global : List globally enabled completions"
}
do_list() {
local targets opts i
targets=( $(find_targets) )
if [[ $1 == "--global" ]]; then
opts="--global"
shift
fi
for (( i = 0; i < ${#targets[@]}; i++ )); do
is_enabled ${opts} "${targets[i]}" \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_list_start "Available completions:"
write_numbered_list -m "(none found)" "${targets[@]}"
}
### enable action ###
describe_enable() {
echo "Enable specified completion(s)"
}
describe_enable_parameters() {
echo ""
}
describe_enable_options() {
echo "--global : Enable for all users"
echo " : Target name or number (from 'list' action)"
}
do_enable() {
local bcdir bc mode="" file target targets
bcdir=${ROOT%/}/${HOME}/.bash_completion.d
if [[ $1 == "--global" ]]; then
bcdir=${EROOT%/}/etc/bash_completion.d
mode="-m 0755"
shift
fi
[[ $# -eq 0 ]] && die -q "You didn't specify any completions to enable."
# create directory if necessary
if [[ ! -d ${bcdir} && -w $(dirname ${bcdir}) ]]; then
mkdir ${mode} "${bcdir}" || die -q "Failed to create ${bcdir}"
elif [[ ! -d ${bcdir} ]]; then
die -q "You don't have permission to create ${bcdir}"
fi
# make sure we have proper permissions
[[ -w ${bcdir} ]] \
|| die -q "You don't have permission to write to ${bcdir}"
targets=( $(find_targets) )
for bc in "$@"; do
# ignore any unrecognized options
[[ ${bc} == --* ]] && continue
target=${bc}
is_number "${target}" && target=${targets[target-1]}
[[ -z ${target} ]] \
&& die -q "Target \"${bc}\" doesn't appear to be valid!"
bc=${target}
# what form is the argument in?
case "${bc}" in
# absolute path
/*)
file=${ROOT%/}/${bc}
;;
# relative path
*/*)
file=${ROOT%/}/${PWD}/${bc}
;;
# no path
*)
# assume /usr/share/bash-completion
file=${EROOT%/}/usr/share/bash-completion/${bc}
if [[ ! -f ${file} ]]; then
for x in ${ES_BASHCOMP_DIRS}; do
[[ -f ${x}/${bc} ]] && file=${x}/${bc}
done
fi
;;
esac
# does it exist?
if [[ ! -f ${file} ]]; then
write_error_msg "${file} doesn't exist"
continue
fi
# already installed?
if [[ -e ${bcdir}/$(basename ${bc}) ]]; then
write_error_msg "$(basename ${bc}) is already installed"
continue
fi
# finally, create the symlink
ln -s "$(relative_name "${file}" "${bcdir}")" "${bcdir}/" \
|| die -q "Failed to create symlink from ${file} to ${bcdir}"
done
}
### disable action ###
describe_disable() {
echo "Disable specified completion(s)"
}
describe_disable_parameters() {
echo ""
}
describe_disable_options() {
echo "--global : Disable for all users"
echo " : Target name or number (from 'list' action)"
}
do_disable() {
local bcdir bc targets target file
bcdir=${ROOT%/}/${HOME}/.bash_completion.d
if [[ $1 == "--global" ]]; then
bcdir=${EROOT%/}/etc/bash_completion.d
shift
fi
[[ $# -eq 0 ]] && die -q "You didn't specify any completions to disable"
targets=( $(find_targets) )
for bc in "$@"; do
# ignore any unrecognized options
[[ ${bc} == --* ]] && continue
target=${bc}
is_number "${target}" && target=${targets[target-1]}
[[ -z ${target} ]] \
&& die -q "Target \"${bc}\" doesn't appear to be valid!"
bc=${target}
file=${bcdir}/${bc}
# is it installed?
if [[ ! -e ${file} ]]; then
write_error_msg "${bc} is not installed"
continue
fi
# remove it if we have permissions
if [[ -w $(dirname ${file}) ]]; then
rm "${file}" || die -q "Failed to remove ${file}"
else
die -q "You don't have permission to remove ${file}"
fi
done
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
bashcomp apply_text_highlights "${right}" "${val}"
Manage contributed bash-completion scripts
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit config package-manager
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# package_manager PRIVATE
# Return the package manager we're going to use.
package_manager() {
local pm
case ${PACKAGE_MANAGER} in
portage) pm=portage ;;
pkgcore) pm=pkgcore ;;
paludis) pm=paludis ;;
esac
echo "${pm:-portage}"
}
# portageq
# Run portageq with safe filename as set by configure. Redirect stderr
portageq() {
/Users/tetsushi/Gentoo/usr/bin/portageq "$@" 2>/dev/null
}
# run_paludis PRIVATE
# Run CAVE (defaults to "cave"). Redirect stderr
run_paludis() {
${CAVE:-cave} "$@" 2>/dev/null
}
# arch
# Return the architecture we're running on...
arch() {
local ret=$(envvar sys-devel/gcc ARCH)
if [[ -n ${EPREFIX} && -n ${ret} && ${ret%-*} = "${ret}" ]]; then
# prefix/linux profiles lie about their ARCH
case $(envvar sys-devel/gcc KERNEL) in
linux) ret+="-linux" ;;
*)
write_warning_msg \
"Failed to determine \${ARCH}." \
"Please submit a bug report."
return 1
;;
esac
fi
# $arch will be null if there's no current make.profile symlink.
# We cannot get a list of valid profiles without it.
if [[ -z ${ret} ]]; then
if [[ -n ${ROOT} && ${ROOT} != "/" ]]; then
write_warning_msg \
"Failed to determine \${ARCH}." \
"Is your make.profile symlink valid?"
return 1
fi
# Try to determine arch from HOSTTYPE and OSTYPE, which are
# derived from the GNU triplet (at build time of bash)
case ${HOSTTYPE} in
alpha*) ret=alpha ;;
arm*) ret=arm ;;
hppa*) ret=hppa ;;
i?86) ret=x86 ;;
ia64) ret=ia64 ;;
m68k) ret=m68k ;;
mips*) ret=mips ;;
powerpc) ret=ppc ;;
powerpc64) ret=ppc64 ;;
s390*) ret=s390 ;;
sh*) ret=sh ;;
sparc) ret=sparc ;;
sparc64) ret=sparc64 ;;
x86_64) ret=amd64 ;;
*)
write_warning_msg \
"Unknown architecture \"${HOSTTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
if [[ -z ${EPREFIX} ]]; then
case ${OSTYPE} in
linux*) ;;
dragonfly*) ret+="-dfly" ;;
freebsd*) ret+="-fbsd" ;;
netbsd*) ret+="-nbsd" ;;
openbsd*) ret+="-obsd" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
else
# Prefix architectures
if [[ ${ret} = amd64 && ${OSTYPE} != linux* ]]; then
# amd64 is sometimes called x64 on Prefix
ret=x64
fi
case ${OSTYPE} in
aix*) ret+="-aix" ;;
cygwin*) ret+="-cygwin" ;;
darwin*) ret+="-macos" ;;
freebsd*) ret+="-freebsd" ;;
hpux*) ret+="-hpux" ;;
interix*) ret+="-interix" ;;
linux*) ret+="-linux" ;;
mint*) ret+="-mint" ;;
netbsd*) ret+="-netbsd" ;;
openbsd*) ret+="-openbsd" ;;
solaris*) ret+="-solaris" ;;
winnt*) ret+="-winnt" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
fi
fi
echo "${ret}"
}
# envvar
# Return the contents of environment variable $2 as seen by package manager
# for package $1.
envvar() {
[[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
case $(package_manager) in
# portage does not support per-package envvar lookup
portage) portageq envvar "$2" ;;
pkgcore) pinspect portageq envvar "$2" ;;
paludis) run_paludis print-id-environment-variable --best \
--variable-name "$2" --format '%v\n' "$1" ;;
esac
}
# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
[[ $# -eq 1 ]] || die "best_version expects exactly one argument"
case $(package_manager) in
portage) portageq best_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq best_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis print-best-version --format name-version "$1" ;;
esac
}
# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
[[ $# -eq 1 ]] || die "has_version expects exactly one argument"
case $(package_manager) in
portage) portageq has_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq has_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis has-version "$1" ;;
esac
}
# get_repositories
# return list of repositories known to the package manager
get_repositories() {
case $(package_manager) in
portage) portageq get_repos "${EROOT:-/}" ;;
pkgcore) pinspect portageq get_repositories ;;
paludis) run_paludis print-repositories ;;
esac
}
# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
[[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
local repo=$1
case $(package_manager) in
portage) echo "$(portageq get_repo_path \
"${EROOT:-/}" "${repo}")/metadata/news" ;;
pkgcore) pinspect portageq get_repo_news_path "${repo}" ;;
paludis) run_paludis print-repository-metadata ${repo} \
--raw-name newsdir --format '%v\n' ;;
esac
}
# env_update
# Run env-update command, if available with the package manager
# If $1 is non-zero: also run ldconfig to update /etc/ld.so.cache
env_update() {
local noldconfig
[[ $1 -ne 0 ]] || noldconfig=y
case $(package_manager) in
portage) "/Users/tetsushi/Gentoo/usr/sbin/env-update" ${noldconfig:+--no-ldconfig} ;;
pkgcore) pmaint env-update ${noldconfig:+--skip-ldconfig} ;;
paludis) return 127 ;;
esac
}
DESCRIPTION="Manage installed versions of sys-devel/binutils"
MAINTAINER="eselect@gentoo.org"
BINUTILS_ENVFILE=${EROOT}/etc/env.d/05binutils
# find_targets [patterns]
# find all possible targets [that match one of ${@}]
find_targets() {
local item file
local -a targets
[[ $# -eq 0 ]] && set -- "-*"
for item; do
item=${item%%-[1-9]*}
[[ ${item:0:1} == "-" ]] || item=-${item}
for file in "${EROOT}"/etc/env.d/binutils/config${item}; do
[[ -f ${file} ]] || continue
targets=("${targets[@]}" "${file##*/config-}")
done
done
echo "${targets[@]}"
}
# find_versions
# find all installed version of installed binutils
find_versions() {
local target file last_versions_count
local -a versions
for target in $(find_targets) ; do
last_version_count=${#versions[@]}
for file in "${EROOT}"/etc/env.d/binutils/${target}-* ; do
[[ -f ${file} ]] || continue
versions=(${versions[@]} "${file##*/}")
done
[[ ${last_version_count} == ${#versions[@]} ]] \
&& die -q "Please remove stray file: ${EROOT}/etc/env.d/binutils/config-${target}"
done
echo ${versions[@]}
}
# is_active $target $version
# returns true if $version is currently used
is_active() {
local current
[[ ${#@} -eq 2 ]] || die "Need exactly 2 arguments!"
current=$(load_config "${EROOT}/etc/env.d/binutils/config-${1}" CURRENT)
[[ ${current} == ${2} ]]
}
# is_valid $profile
is_valid() {
[[ ${#@} -eq 1 && -e "${EROOT}/etc/env.d/binutils/${profile}" ]] \
|| die "Need exactly 1 argument!"
}
# swtich_profile $profile
# switches binutils to $profile
switch_profile() {
# set us up
[[ ${#@} -eq 1 ]] || die "Need exactly 1 argument!"
local profile=${1##*/}
local profile_file=${EROOT}/etc/env.d/binutils/${profile}
local target targets version binutilspath libpath chost
version=$(load_config ${profile_file} VER)
target=$(load_config ${profile_file} TARGET)
is_active ${target} ${version} \
&& die -q "Profile \"${profile}\" is already active!"
chost=$(envvar sys-devel/binutils CHOST)
libpath=$(load_config ${profile_file} LIBPATH)
libpath=${libpath:-${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}
faketargets=( $(load_config ${profile_file} FAKE_TARGETS) )
# Generate binary symlinks
echo "Switching to ${profile}..."
[[ -d "${EROOT}/usr/${target}/binutils-bin/${version}" ]] \
|| die -q "Can't cd ${EROOT}/usr/${target}/binutils-bin/${version}!"
mkdir -p "${EROOT}/usr/${target}/bin" \
|| die -q "Can't create ${EROOT}/usr/${target}/bin!"
binutilspath=${EPREFIX}/usr/${target}/binutils-bin/${version}
for app in "${ROOT}${binutilspath}"/* ; do
app=${app##*/}
ln -sf \
"${binutilspath}/${app}" \
"${EROOT}/usr/${target}/bin/${app}" \
|| die -q "Linking ${ROOT}/${binutilspath}/${app} failed!"
ln -sf \
../${target}/bin/${app} \
"${EROOT}/usr/bin/${target}-${app}" \
|| die -q "Linking ${EROOT}/usr/bin/${target}-${app} failed!"
for fake in ${faketargets} ; do
[[ -f ${EROOT}/etc/env.d/binutils/config-${fake} ]] \
&& continue
ln -sf ../${target}/bin/${app} "${EROOT}/usr/bin/${fake}-${app}"
done
[[ ${chost} == ${target} ]] || continue
ln -sf \
${target}-${app} \
"${EROOT}/usr/bin/${app}" \
|| die -q "Linking ${EROOT}/usr/bin/${app} failed!"
done
# Generate library and ldscripts symlinks
mkdir -p "${EROOT}/usr/${target}/lib"
rm -r "${EROOT}/usr/${target}/lib/ldscripts"
ln -sf "${libpath}/ldscripts" "${EROOT}/usr/${target}/lib/ldscripts"
[[ ${target} == ${chost} ]] \
&& dest="${EROOT}/usr/${chost}/lib" \
|| dest="${EROOT}/usr/${chost}/${target}/lib"
mkdir -p "${dest}"
for lib in "${ROOT}${libpath}"/lib* ; do
ln -sf "${libpath}/${lib##*/}" "${dest}/${lib##*/}"
done
# Generate include symlink
[[ ${target} == ${chost} ]] \
&& dest="${EROOT}/usr/include" \
|| dest="${EROOT}/usr/${target}/include"
mkdir -p "${dest}"
for inc in "${ROOT}${libpath}"/include/* ; do
ln -sf "${inc##${ROOT}}" "${dest}/${inc##*/}"
done
# Update the environment
if [[ ${target} == ${chost} ]] ; then
datapath=${EPREFIX}/usr/share/binutils-data/${target}/${version}
[[ -d ${datapath}/man ]] \
&& store_config ${BINUTILS_ENVFILE} MANPATH "${datapath}/man"
[[ -d ${datapath}/info ]] \
&& store_config ${BINUTILS_ENVFILE} INFOPATH "${datapath}/info"
store_config ${BINUTILS_ENVFILE} LDPATH "${EPREFIX}/usr/${target}/lib"
fi
store_config \
"${EROOT}/etc/env.d/binutils/config-${target}" \
CURRENT ${version}
if [[ ${ROOT:-/} == / ]] && [[ ${target} == ${chost} ]] ; then
do_action env update
echo "Please remember to run:"
echo
echo " # source /etc/profile"
echo
echo "in order to let changes take effect!"
fi
}
### list action
describe_list() {
echo "List all installed version of binutils"
}
do_list() {
local targets i=0 version files last_processed_count
local -a processed
targets=( $(find_targets ${@}) )
[[ -z ${targets[@]} ]] \
&& die -q "Pattern ${@} does not match any installed version of binutils!"
for target in $(find_targets) ; do
[[ ${targets[@]/${target}/} == ${targets[@]} ]] \
|| write_list_start "Installed binutils for target $(highlight ${target})"
last_processed_count=${#processed[@]}
for file in "${EROOT}"/etc/env.d/binutils/${@:-*} ; do
[[ -f ${file} ]] || continue
version=${file##*/${target}-}
[[ ${version} == ${file} ]] && continue
[[ ${processed[@]/${file}/} == ${processed[@]} ]] || continue
processed=(${processed[@]} "${file}")
i=$(( i + 1 ))
[[ ${targets[@]/${target}/} == ${targets[@]} ]] && continue
is_active ${target} ${version} \
&& version=$(highlight_marker "${version}")
write_numbered_list_entry $i "${version}"
done
[[ ${last_processed_count} == ${#processed[@]} ]] \
&& die -q "Please remove stray file: ${EROOT}/etc/env.d/binutils/config-${target}"
done
}
### set action
describe_set() {
echo "Activate one of the installed binutils"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
do_set() {
[[ ${#@} == 1 ]] \
|| die -q "Please specify exactly one version to activate!"
local versions file fail=0
versions=( $(find_versions) )
for item in ${@} ; do
if is_number ${item} ; then
if [[ ${item} -ge 1 ]] && [[ ${item} -le $(( ${#versions[@]} + 2)) ]] ; then
switch_profile ${versions[$(( ${item} -1 ))]}
else
fail=1
echo "Item not in range 1-$((${#versions[@]} + 1)): ${item}"
continue
fi
else
file=( "${EROOT}"/etc/env.d/binutils/${item} )
if [[ ${#file[@]} -gt 1 ]] ; then
fail=1
echo "Ambigious pattern: ${item}"
continue
fi
if ! [[ -f ${file} ]] ; then
fail=1
echo "Pattern doesn't match anything: ${item}"
continue
fi
switch_profile ${file##*/}
fi
done
[[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
}
### show action
describe_show() {
echo "Print the currently active binutils version"
}
do_show() {
local chost=${1:-$(envvar sys-devel/binutils CHOST)} version config
[[ -n ${chost} ]] \
|| die -q "Portage returned empty CHOST!"
config=${EROOT}/etc/env.d/binutils/config-${chost}
[[ ${#config[@]} -eq 1 ]] \
|| return
[[ -e ${config} ]] \
|| return
version=$(load_config \
"${EROOT}/etc/env.d/binutils/config-${chost}" CURRENT)
[[ -e ${EROOT}/etc/env.d/binutils/${chost}-${version} ]] \
|| die "File \"${EROOT}/etc/env.d/binutils/${chost}-${version}\" is missing!"
echo "${chost}-${version}"
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
binutils apply_text_highlights "${right}" "${val}"
Manage installed versions of sys-devel/binutils
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: blas.eselect-0.1,v 1.1 2006/06/18 20:59:04 spyderous Exp $
inherit skel
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2006-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# To use this library, you must set MODULE and IFACE.
# MODULE is the name you use to refer to whatever it is that you're selecting
# in help text and so forth.
# IFACE is the subdirectory of /etc/env.d/ that eselect config files are stored
# in for these packages.
#
# There is a file installed at /etc/env.d/$IFACE/$libdir/config containing the
# CURRENT variable, which is set to the current eselect setting. Also, each
# implementation installs a single file at /etc/env.d/$IFACE/$libdir/$implem.
# This file contains a list of symlinks to be created in "source destination"
# format. You must use relative symlinks. In other words, "source" must be
# relative to "destination" but "destination" must be absolute. You may have
# comments in the symlink map file -- any line containing a '#' is considered
# a comment. One caveat about the symlink map -- instead of using "lib" or
# "lib64" etc, you must use @LIBDIR@.
inherit config multilib tests
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
ES_VALID_MULTILIB_DIRS="lib lib32 lib64 libx32"
# list_libdirs PUBLIC
# Returns a space separated list of libdirs available on this machine
list_libdirs() {
local dir
local -a libdirs
for dir in ${ES_VALID_MULTILIB_DIRS}; do
[[ -d ${EROOT}/${dir} ]] && libdirs[${#libdirs[@]}]=${dir}
done
echo "${libdirs[@]}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# has test list
# Return true if list contains test
has() {
local test=${1} item
shift
for item in "$@" ; do
[[ ${item} == ${test} ]] && return 0
done
return 1
}
# is_function function PUBLIC
# Test whether function exists
is_function() {
[[ $(type -t "${1}" ) == "function" ]]
}
# is_number PUBLIC
# Returns true if and only if $1 is a positive whole number
is_number() {
[[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
}
# find_implems $iface $libdir
# find all possible implems for $libdir
find_implems() {
local -a implems
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
iface=$1 libdir=$2
for file in "${confdir}"/* ; do
[[ -f ${file} ]] || continue
[[ "${file##*/}" != "config" ]] || continue
implems=(${implems[@]} "${file##*/}")
done
echo ${implems[@]}
}
# is_active $iface $libdir $implem
# returns true if $implem is currently used for the $iface/$libdir combination
is_active() {
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
current=$(load_config "${EROOT}/etc/env.d/${1}/${2}/config" CURRENT)
[[ ${current} == ${3} ]]
}
# switch_implem $iface $libdir $implem
# switches $iface/$libdir combination to $implem
switch_implem() {
# set us up
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
local iface=${1}
local libdir=${2}
local implem=${3##*/}
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
local current=$(load_config "${confdir}/config" CURRENT)
local dest src
# Get rid of old symlinks, if we have a current config
if [[ -f ${confdir}/${current} ]]; then
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
dest=$2
rm -f "${ROOT}${dest}"
done < "${confdir}/${current}"
fi
# Set up new symlinks
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
src=$1
dest=$2
ln -sf "${src}" "${ROOT}${dest}"
done < "${confdir}/${implem}"
store_config "${confdir}/config" CURRENT ${implem}
}
# iface_do_list $libdir
# Lists the available implementations for $libdir
iface_do_list() {
local -a implems
local libdir=$1 iface=$IFACE
implems=( $(find_implems $iface $libdir ) )
# None installed for $libdir
[[ -z ${implems[@]} ]] \
&& return
write_list_start "Installed $MODULE for library directory $(highlight ${libdir})"
for implem in ${implems[@]} ; do
(( i++ ))
is_active ${iface} ${libdir} ${implem##*/} \
&& implem=$(highlight_marker "${implem}")
write_numbered_list_entry $i "${implem}"
done
}
# iface_do_show $libdir
# Shows the current implementation for $libdir
iface_do_show() {
local iface=$IFACE libdir=$1 implem
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
[[ -e ${confdir}/config ]] || return
implem=$(load_config "${confdir}/config" CURRENT)
[[ -e ${confdir}/${implem} ]] \
|| die "File \"${confdir}/${implem}\" is missing!"
echo "${libdir}: ${implem}"
}
# get_libdirs
# Wraps list_libdirs() to ensure that output is sorted consistently
get_libdirs() {
list_libdirs | sort
}
### list action
describe_list() {
echo "List all installed $MODULE implementations"
}
do_list() {
local libdir
# Count for listing IFACE/libdir combinations
# We keep it here so it doesn't reset on every call to iface_do_list()
local i=0
for libdir in $(get_libdirs); do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_list $libdir
done
}
### set action
describe_set() {
echo "Activate one of the installed $MODULE implementations"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "implementation : implementation name or number (from 'list' action)"
}
do_set() {
[[ $# -eq 0 ]] && die -q "Please specify exactly 1 implementation!"
local fail=0 iface=$IFACE
local libdirs=$(get_libdirs)
local libdir implem libdir_ct i=0
local -a file implems new_implems mylibdirs myimplems
# Build up list of all valid implems
for libdir in ${libdirs}; do
new_implems=( $(find_implems ${iface} ${libdir}) )
implems=( ${implems[@]} ${new_implems[@]} )
libdir_ct[$i]=${#new_implems[@]}
(( i++ ))
done
# Parse passed parameters into valid libdirs. Other arguments are considered
# implementations (or numbers for them) and are validated later.
# If libdirs are specified, then switch for them. Otherwise, switch for all
# libdirs.
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
else
myimplems=(${myimplems[@]} ${param})
fi
done
set ${myimplems[@]}
# We can only change one implem at a time
[[ ${#myimplems[@]} -ne 1 ]] && \
die -q "Please specify exactly 1 implemention."
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
i=0
for libdir in ${libdirs}; do
# Only move on if we actually have implems here, otherwise we screw up
# $libdir_max and waste time executing pointless code
if [[ ${libdir_ct[$i]} -gt 0 ]]; then
for item in ${@} ; do
if is_number ${item} ; then
# On the first libdir, minimum must be 1. Maxes and later
# mins are incremented by the size of the previous libdir_ct
if [[ -n ${libdir_min} ]]; then
libdir_min=$(( ${libdir_min} + ${libdir_ct[$(( $i - 1 ))]} ))
else
libdir_min="1"
fi
libdir_max=$(( ${libdir_min} + ${libdir_ct[$i]} - 1 ))
if [[ ${item} -ge ${libdir_min} ]] && [[ ${item} -le ${libdir_max} ]] ; then
if ! switch_implem ${iface} ${libdir} ${implems[$(( ${item} -1 ))]}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
else
fail=1
echo "Item not in range ${libdir_min}-${libdir_max} for ${libdir}: ${item}"
continue
fi
else
# Only attempt to switch to an implementation if it's available
# for that libdir
if has ${item} $(find_implems ${iface} ${libdir}); then
if ! switch_implem ${iface} ${libdir} ${item}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
fi
fi
done
fi
(( i++ ))
done
[[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
}
### show action
describe_show() {
echo "Print the currently active $MODULE implementation"
}
do_show() {
local libdir
local libdirs=$(get_libdirs)
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
fi
done
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
for libdir in ${libdirs}; do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_show $libdir
done
}
### add action
describe_add() {
echo "Add a new $MODULE implementation"
}
describe_add_parameters() {
echo " "
}
describe_add_options() {
echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
echo "file : path to file containing symlink map"
echo "implementation : name of the $MODULE implementation"
}
do_add() {
[[ $# -eq 3 ]] \
|| die -q "Please specify 1 library directory, 1 file to install and 1 implementation!"
# If $D is set, we're adding from portage so we want to respect sandbox.
# Otherwise, respect the ROOT variable.
local prefix=${D:-${ROOT}}${EPREFIX}
# Create directory if necessary
if [[ ! -e ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
mkdir -p "${prefix}/etc/env.d/${IFACE}/${1}"
elif [[ ! -d ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
die -q "${prefix}/etc/env.d/${IFACE}/${1} exists but isn't a directory!"
fi
if ! cp "${2}" "${prefix}/etc/env.d/${IFACE}/${1}/${3}"; then
die -q "Installing ${2} as ${prefix}/etc/env.d/${IFACE}/${1}/${3} failed!"
fi
}
MODULE="BLAS"
IFACE="blas"
DESCRIPTION="Manage installed $MODULE implementations"
MAINTAINER="spyderous@gentoo.org"
SVN_DATE='$Date: 2006/06/18 20:59:04 $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
svn_date_to_version "${SVN_DATE}"
# vim: set ft=eselect :
echo "${!key}"
apply_text_highlights "${left}" "${key}"
blas apply_text_highlights "${right}" "${val}"
Manage installed BLAS implementations
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: cblas.eselect-0.1,v 1.1 2006/06/18 21:04:41 spyderous Exp $
inherit skel
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2006-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# To use this library, you must set MODULE and IFACE.
# MODULE is the name you use to refer to whatever it is that you're selecting
# in help text and so forth.
# IFACE is the subdirectory of /etc/env.d/ that eselect config files are stored
# in for these packages.
#
# There is a file installed at /etc/env.d/$IFACE/$libdir/config containing the
# CURRENT variable, which is set to the current eselect setting. Also, each
# implementation installs a single file at /etc/env.d/$IFACE/$libdir/$implem.
# This file contains a list of symlinks to be created in "source destination"
# format. You must use relative symlinks. In other words, "source" must be
# relative to "destination" but "destination" must be absolute. You may have
# comments in the symlink map file -- any line containing a '#' is considered
# a comment. One caveat about the symlink map -- instead of using "lib" or
# "lib64" etc, you must use @LIBDIR@.
inherit config multilib tests
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
ES_VALID_MULTILIB_DIRS="lib lib32 lib64 libx32"
# list_libdirs PUBLIC
# Returns a space separated list of libdirs available on this machine
list_libdirs() {
local dir
local -a libdirs
for dir in ${ES_VALID_MULTILIB_DIRS}; do
[[ -d ${EROOT}/${dir} ]] && libdirs[${#libdirs[@]}]=${dir}
done
echo "${libdirs[@]}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# has test list
# Return true if list contains test
has() {
local test=${1} item
shift
for item in "$@" ; do
[[ ${item} == ${test} ]] && return 0
done
return 1
}
# is_function function PUBLIC
# Test whether function exists
is_function() {
[[ $(type -t "${1}" ) == "function" ]]
}
# is_number PUBLIC
# Returns true if and only if $1 is a positive whole number
is_number() {
[[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
}
# find_implems $iface $libdir
# find all possible implems for $libdir
find_implems() {
local -a implems
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
iface=$1 libdir=$2
for file in "${confdir}"/* ; do
[[ -f ${file} ]] || continue
[[ "${file##*/}" != "config" ]] || continue
implems=(${implems[@]} "${file##*/}")
done
echo ${implems[@]}
}
# is_active $iface $libdir $implem
# returns true if $implem is currently used for the $iface/$libdir combination
is_active() {
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
current=$(load_config "${EROOT}/etc/env.d/${1}/${2}/config" CURRENT)
[[ ${current} == ${3} ]]
}
# switch_implem $iface $libdir $implem
# switches $iface/$libdir combination to $implem
switch_implem() {
# set us up
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
local iface=${1}
local libdir=${2}
local implem=${3##*/}
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
local current=$(load_config "${confdir}/config" CURRENT)
local dest src
# Get rid of old symlinks, if we have a current config
if [[ -f ${confdir}/${current} ]]; then
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
dest=$2
rm -f "${ROOT}${dest}"
done < "${confdir}/${current}"
fi
# Set up new symlinks
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
src=$1
dest=$2
ln -sf "${src}" "${ROOT}${dest}"
done < "${confdir}/${implem}"
store_config "${confdir}/config" CURRENT ${implem}
}
# iface_do_list $libdir
# Lists the available implementations for $libdir
iface_do_list() {
local -a implems
local libdir=$1 iface=$IFACE
implems=( $(find_implems $iface $libdir ) )
# None installed for $libdir
[[ -z ${implems[@]} ]] \
&& return
write_list_start "Installed $MODULE for library directory $(highlight ${libdir})"
for implem in ${implems[@]} ; do
(( i++ ))
is_active ${iface} ${libdir} ${implem##*/} \
&& implem=$(highlight_marker "${implem}")
write_numbered_list_entry $i "${implem}"
done
}
# iface_do_show $libdir
# Shows the current implementation for $libdir
iface_do_show() {
local iface=$IFACE libdir=$1 implem
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
[[ -e ${confdir}/config ]] || return
implem=$(load_config "${confdir}/config" CURRENT)
[[ -e ${confdir}/${implem} ]] \
|| die "File \"${confdir}/${implem}\" is missing!"
echo "${libdir}: ${implem}"
}
# get_libdirs
# Wraps list_libdirs() to ensure that output is sorted consistently
get_libdirs() {
list_libdirs | sort
}
### list action
describe_list() {
echo "List all installed $MODULE implementations"
}
do_list() {
local libdir
# Count for listing IFACE/libdir combinations
# We keep it here so it doesn't reset on every call to iface_do_list()
local i=0
for libdir in $(get_libdirs); do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_list $libdir
done
}
### set action
describe_set() {
echo "Activate one of the installed $MODULE implementations"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "implementation : implementation name or number (from 'list' action)"
}
do_set() {
[[ $# -eq 0 ]] && die -q "Please specify exactly 1 implementation!"
local fail=0 iface=$IFACE
local libdirs=$(get_libdirs)
local libdir implem libdir_ct i=0
local -a file implems new_implems mylibdirs myimplems
# Build up list of all valid implems
for libdir in ${libdirs}; do
new_implems=( $(find_implems ${iface} ${libdir}) )
implems=( ${implems[@]} ${new_implems[@]} )
libdir_ct[$i]=${#new_implems[@]}
(( i++ ))
done
# Parse passed parameters into valid libdirs. Other arguments are considered
# implementations (or numbers for them) and are validated later.
# If libdirs are specified, then switch for them. Otherwise, switch for all
# libdirs.
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
else
myimplems=(${myimplems[@]} ${param})
fi
done
set ${myimplems[@]}
# We can only change one implem at a time
[[ ${#myimplems[@]} -ne 1 ]] && \
die -q "Please specify exactly 1 implemention."
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
i=0
for libdir in ${libdirs}; do
# Only move on if we actually have implems here, otherwise we screw up
# $libdir_max and waste time executing pointless code
if [[ ${libdir_ct[$i]} -gt 0 ]]; then
for item in ${@} ; do
if is_number ${item} ; then
# On the first libdir, minimum must be 1. Maxes and later
# mins are incremented by the size of the previous libdir_ct
if [[ -n ${libdir_min} ]]; then
libdir_min=$(( ${libdir_min} + ${libdir_ct[$(( $i - 1 ))]} ))
else
libdir_min="1"
fi
libdir_max=$(( ${libdir_min} + ${libdir_ct[$i]} - 1 ))
if [[ ${item} -ge ${libdir_min} ]] && [[ ${item} -le ${libdir_max} ]] ; then
if ! switch_implem ${iface} ${libdir} ${implems[$(( ${item} -1 ))]}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
else
fail=1
echo "Item not in range ${libdir_min}-${libdir_max} for ${libdir}: ${item}"
continue
fi
else
# Only attempt to switch to an implementation if it's available
# for that libdir
if has ${item} $(find_implems ${iface} ${libdir}); then
if ! switch_implem ${iface} ${libdir} ${item}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
fi
fi
done
fi
(( i++ ))
done
[[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
}
### show action
describe_show() {
echo "Print the currently active $MODULE implementation"
}
do_show() {
local libdir
local libdirs=$(get_libdirs)
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
fi
done
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
for libdir in ${libdirs}; do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_show $libdir
done
}
### add action
describe_add() {
echo "Add a new $MODULE implementation"
}
describe_add_parameters() {
echo " "
}
describe_add_options() {
echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
echo "file : path to file containing symlink map"
echo "implementation : name of the $MODULE implementation"
}
do_add() {
[[ $# -eq 3 ]] \
|| die -q "Please specify 1 library directory, 1 file to install and 1 implementation!"
# If $D is set, we're adding from portage so we want to respect sandbox.
# Otherwise, respect the ROOT variable.
local prefix=${D:-${ROOT}}${EPREFIX}
# Create directory if necessary
if [[ ! -e ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
mkdir -p "${prefix}/etc/env.d/${IFACE}/${1}"
elif [[ ! -d ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
die -q "${prefix}/etc/env.d/${IFACE}/${1} exists but isn't a directory!"
fi
if ! cp "${2}" "${prefix}/etc/env.d/${IFACE}/${1}/${3}"; then
die -q "Installing ${2} as ${prefix}/etc/env.d/${IFACE}/${1}/${3} failed!"
fi
}
MODULE="CBLAS"
IFACE="cblas"
DESCRIPTION="Manage installed $MODULE implementations"
MAINTAINER="spyderous@gentoo.org"
SVN_DATE='$Date: 2006/06/18 21:04:41 $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
svn_date_to_version "${SVN_DATE}"
# vim: set ft=eselect :
echo "${!key}"
apply_text_highlights "${left}" "${key}"
cblas apply_text_highlights "${right}" "${val}"
Manage installed CBLAS implementations
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*-
# Copyright 2005-2012 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
#
# DOCUMENTATION
# Following actions possible
# * show do_show()
# * list do_list()
# * set do_set()
# * update do_update()
#
# Behaviour:
# do_show():
# Checks if /usr/bin/ctags is a link and if the target exists,
# if yes, it outputs the currently linked ctags implementation.
# If it is no symlink, the user is told so, the same if there is
# no /usr/bin/ctags or the target does not exist.
# do_list(): List all available ctags implementations.
# do_set(): Set a version to be target of the symlink.
# do_update(): Set the target to the "best" available version. See below.
# This module is used for ctags and etags.
# Determine our name from ESELECT_MODULE_NAME, with BASH_SOURCE as fallback.
#CTAGS=${ESELECT_MODULE_NAME:-$(basename "${BASH_SOURCE[0]%.*}")}
CTAGS=ctags
DESCRIPTION="Manage /usr/bin/${CTAGS} implementations"
MAINTAINER="emacs@gentoo.org"
VERSION="1.14"
find_targets() {
# Return the list of available ctags implementations
# (X)Emacs: offer only one ctags implementation, namely for the
# currently active Emacs version (selected by emacs.eselect)
# The logic here is the same as in emacs.eselect, don't change it!
local emacs
if [[ -L ${EROOT}/usr/bin/emacs && -e ${EROOT}/usr/bin/emacs ]]; then
emacs=$(basename "$(readlink "${EROOT}/usr/bin/emacs")")
[[ -f ${EROOT}/usr/bin/${CTAGS}-${emacs} ]] && echo "${CTAGS}-${emacs}"
elif [[ -f ${EROOT}/usr/bin/xemacs ]]; then
[[ -f ${EROOT}/usr/bin/${CTAGS}-xemacs ]] && echo "${CTAGS}-xemacs"
elif [[ ${CTAGS} = etags ]]; then
# We are called as etags module, but no (X)Emacs is installed.
# Return an empty list in this case, because we don't want
# exuberant-ctags as default for etags (for ctags it's fine).
# Also, vi purists wouldn't want an etags symlink.
return
fi
# Exuberant ctags
[[ -f ${EROOT}/usr/bin/exuberant-ctags ]] && echo exuberant-ctags
}
remove_symlinks() {
# Remove existing symlinks to binary and man page
rm -f "${EROOT}/usr/bin/${CTAGS}" "${EROOT}"/usr/share/man/man1/${CTAGS}.1*
}
set_bin_symlinks() {
# Set symlink to binary
local target=${1}
ln -s "${target}" "${EROOT}/usr/bin/${CTAGS}" \
|| die "Couldn't set ${target} ${EROOT}/usr/bin/${CTAGS} symlink"
}
set_man_symlinks() {
# Set symlink to man page
local target=${1} extension i
for i in "${EROOT}"/usr/share/man/man1/${target}.1*; do
if [[ -f ${i} ]]; then
# target file exists; determine compress extension
extension=${i##*/${target}.1}
ln -s "${target}.1${extension}" \
"${EROOT}/usr/share/man/man1/${CTAGS}.1${extension}"
fi
done
}
set_symlinks() {
# Set symlinks to binary and man page
local target=$1 targets
# target may be specified by its name or its index
if is_number "${target}"; then
# numeric index, find the target's name
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: ${1}"
target=${targets[target-1]}
fi
# is the target valid, i.e. does a ctags binary with this name exist?
[[ -f ${EROOT}/usr/bin/${target} ]] \
|| die -q "Target \"$1\" doesn't appear to be valid!"
echo "Switching ${CTAGS} to ${target} ..."
remove_symlinks || die -q "Couldn't remove existing symlink"
set_bin_symlinks "${target}"
set_man_symlinks "${target}"
return 0
}
test_for_root() {
# checks if the user has rights to modify /usr/bin/
[[ -w ${EROOT}/usr/bin ]] || die -q "You need root privileges!"
}
### show action ###
describe_show() {
echo "Show the current target of the ${CTAGS} symlink"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
write_list_start "Current target of ${CTAGS} symlink:"
if [[ -L ${EROOT}/usr/bin/${CTAGS} && -e ${EROOT}/usr/bin/${CTAGS} ]]
then
write_kv_list_entry \
"$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")" ""
elif [[ -e ${EROOT}/usr/bin/${CTAGS} ]]; then
write_kv_list_entry \
"(not a symlink or target of symlink does not exist)" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available ${CTAGS} symlink targets"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local i targets
targets=( $(find_targets) )
for (( i = 0; i < ${#targets[@]}; i++ )); do
# Highlight the currently chosen version
[[ ${targets[i]} = \
"$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_list_start "Available ${CTAGS} symlink targets:"
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set a new ${CTAGS} symlink"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
test_for_root
if [[ -e ${EROOT}/usr/bin/${CTAGS} && ! -L ${EROOT}/usr/bin/${CTAGS} ]]
then
die -q "${EROOT}/usr/bin/${CTAGS} exists but is not a symlink"
fi
set_symlinks "$1" || die -q "Couldn't set a new symlink"
}
### update action ###
describe_update() {
echo "Automatically update the ${CTAGS} symlink"
}
describe_update_options() {
echo "ifunset : Do not override currently set version"
}
do_update() {
[[ -z $1 || $1 = ifunset || $1 = --if-unset ]] || die -q "Usage error"
[[ -z $2 || $2 = norecursion ]] || die -q "Usage error"
[[ $# -gt 2 ]] && die -q "Too many parameters"
test_for_root
if ! [[ $1 == *if*unset \
&& -L ${EROOT}/usr/bin/${CTAGS} && -e ${EROOT}/usr/bin/${CTAGS} ]]
then
local current=""
if [[ -L ${EROOT}/usr/bin/${CTAGS} ]]; then
current=$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")
if [[ ! -e ${EROOT}/usr/bin/${CTAGS} ]]; then
# clean up dead symlinks
remove_symlinks || die -q "Couldn't remove existing symlink"
fi
elif [[ -e ${EROOT}/usr/bin/${CTAGS} ]]; then
if ! [[ ${CTAGS} = ctags && $(uname) = FreeBSD ]]; then
die -q "${EROOT}/usr/bin/${CTAGS} exists but is not a symlink"
fi
# On FreeBSD ctags is a real file, installed by freebsd-ubin
current=nolink
fi
# For an "update" only the version should be changed, but not the
# provider (i.e. Emacs vs Exuberant). At the moment only (X)Emacs
# offers several concurrent versions.
local i target targets=( $(find_targets) )
if [[ ${#targets[@]} -gt 0 && ${current} != nolink ]]; then
target=${targets[0]}
[[ ${current} == ${CTAGS}-*emacs* ]] && current=${CTAGS}-*emacs*
for i in ${targets[@]}; do
[[ ${i} == ${current} ]] && target=${i}
done
set_symlinks "${target}" || die -q "Couldn't set a new symlink"
fi
fi
# Call "eselect etags update" from the ctags module and vice versa
[[ $2 = norecursion ]] && return
case ${CTAGS} in
ctags) CTAGS=etags do_update "$1" norecursion ;;
etags) CTAGS=ctags do_update "$1" norecursion ;;
esac
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
ctags apply_text_highlights "${right}" "${val}"
Manage /usr/bin/ctags implementations
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2009-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
EDITOR_VAR="EDITOR"
EDITOR_ENVFILE="/etc/env.d/99editor"
# list of most common cases only
EDITOR_LIST="/bin/nano
/bin/ed
/usr/bin/emacs
/usr/bin/ex
/usr/bin/vi
/usr/bin/xemacs"
inherit editor-variable
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# This library is for managing environment variables like EDITOR or PAGER.
# To use it, you must set the following variables:
#
# EDITOR_VAR is the name of the environment variable, e.g. "EDITOR".
# EDITOR_ENVFILE is the path to the config file where the variable should be
# stored, e.g. "/etc/env.d/99editor". Several modules may share the same file.
# EDITOR_LIST is a space-separated list of available programs (full pathnames)
# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi". Alternatively, items can be of
# the form "name:/path/to/binary".
# EDITOR_PATH (optional) is a colon-separated list of directories where to
# search for available programs. Default is "/bin:/usr/bin".
inherit config
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# find a list of valid targets
find_targets() {
local cur i
for i in ${EDITOR_LIST}; do
[[ -f ${EROOT}${i#*:} ]] && echo "${EPREFIX}${i%%:*}"
done
# also output the current value if it isn't in our list
cur=$(read_env_value)
[[ -n ${cur} && ${EDITOR_LIST} != *:* && -f ${ROOT}${cur} ]] \
&& ! has "${cur#${EPREFIX}}" ${EDITOR_LIST} \
&& echo "${cur}"
}
# read variable value from config file
read_env_value() {
load_config "${EROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}"
}
# write variable to config file
write_env_value() {
[[ -w ${EROOT}${EDITOR_ENVFILE%/*} ]] \
|| die -q "You need root privileges!"
store_config "${EROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}" "$1"
}
### show action ###
describe_show() {
echo "Show value of the ${EDITOR_VAR} variable in profile"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur=$(read_env_value)
write_list_start "${EDITOR_VAR} variable in profile:"
write_kv_list_entry "${cur:-(none)}"
}
### list action ###
describe_list() {
echo "List available targets for the ${EDITOR_VAR} variable"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur targets i
cur=$(read_env_value)
targets=( $(find_targets) )
write_list_start "Available targets for the ${EDITOR_VAR} variable:"
for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
targets[i]=${targets[i]%%:*}
# display a star to indicate the currently chosen version
[[ ${targets[i]} = "${cur}" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list "${targets[@]}"
if is_output_mode brief; then
:
elif [[ ${EDITOR_LIST} != *:* ]]; then
write_numbered_list_entry " " "(free form)"
elif [[ ${#targets[@]} -eq 0 ]]; then
write_kv_list_entry "(none found)" ""
fi
}
### set action ###
describe_set() {
echo "Set the ${EDITOR_VAR} variable in profile"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the variable to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
local target=$1 targets=() dir ifs_save=${IFS-$' \t\n'}
# target may be specified by its name or its index
if is_number "${target}"; then
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: $1"
target=${targets[target-1]%%:*}
fi
if [[ ${EDITOR_LIST} != *:* ]]; then
# is the target an absolute path? if not, try to find it
if [[ ${target} != /* ]]; then
IFS=:
for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
[[ -f ${EROOT}${dir}/${target} ]] || continue
target=${EPREFIX}${dir}/${target}
break
done
IFS=${ifs_save}
fi
# target is valid if it's a path to an existing binary
[[ ${target} == /* && -f ${ROOT}${target} ]] \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
else
# target is valid only if it's in our list
[[ ${#targets[@]} -gt 0 ]] || targets=( $(find_targets) )
has "${target}" "${targets[@]%%:*}" \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
fi
echo "Setting ${EDITOR_VAR} to ${target} ..."
write_env_value "${target}"
# update profile
do_action env update noldconfig
[[ ${ROOT:-/} = / ]] && echo \
"Run \". ${EROOT}/etc/profile\" to update the variable in your shell."
}
### update action ###
describe_update() {
echo "Update the ${EDITOR_VAR} variable if it is unset or invalid"
}
do_update() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur targets
cur=$(read_env_value)
[[ ${EDITOR_LIST} != *:* && ${cur} == /* && -f ${ROOT}${cur} ]] && return
targets=( $(find_targets) )
[[ ${#targets[@]} -gt 0 ]] \
|| die -q "No valid target for ${EDITOR_VAR} found"
has "${cur}" "${targets[@]%%:*}" && return
echo "Setting ${EDITOR_VAR} to ${targets[0]%%:*} ..."
write_env_value "${targets[0]%%:*}"
do_action env update noldconfig
}
DESCRIPTION="Manage the ${EDITOR_VAR} environment variable"
MAINTAINER="ulm@gentoo.org"
echo "${!key}"
apply_text_highlights "${left}" "${key}"
editor apply_text_highlights "${right}" "${val}"
Manage the EDITOR environment variable
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*-
# Copyright 2005-2012 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
#
# DOCUMENTATION
# Following actions possible
# * show do_show()
# * list do_list()
# * set do_set()
# * update do_update()
#
# Behaviour:
# do_show():
# Checks if /usr/bin/emacs is a link and if the target exists,
# if yes, it outputs the currently linked Emacs version.
# If it is no symlink, the user is told so, the same if there is
# no /usr/bin/emacs or the target does not exist.
# do_list(): List all available versions of GNU Emacs
# do_set(): Set a version to be target of the symlink.
# do_update(): Set the target to the highest version available
# (optionally: only if not set)
DESCRIPTION="Manage /usr/bin/emacs version"
MAINTAINER="emacs@gentoo.org"
VERSION="1.14"
# ctags and etags are handled in their own module
BINARYLIST="emacsclient b2m ebrowse rcs-checkin grep-changelog"
MANPAGELIST="emacs emacsclient b2m ebrowse rcs-checkin grep-changelog"
MANPAGELIST_OLD="gfdl"
find_targets() {
# Return the list of available Emacs binaries
local j
for j in "${EROOT}"/usr/bin/emacs-[0-9]*; do
[[ -f ${j} ]] && basename ${j}
done
}
remove_infopath() {
# When cleaning symlinks this takes care of the info documentation settings
rm -f "${EROOT}/etc/env.d/50emacs"
}
# Define INFOPATH environment variable in env file
set_infopath() {
[[ -d ${EROOT}/usr/share/info/$1 ]] || return 1
echo "INFOPATH=${EPREFIX}/usr/share/info/$1" >"${EROOT}/etc/env.d/50emacs"
}
remove_symlinks() {
# Remove existing symlinks to binaries, man pages,
# and the env file (own function)
local f
rm -f "${EROOT}/usr/bin/emacs"
for f in ${BINARYLIST}; do
rm -f "${EROOT}/usr/bin/${f}"
done
for f in ${MANPAGELIST} ${MANPAGELIST_OLD}; do
rm -f "${EROOT}"/usr/share/man/man1/${f}.1*
done
remove_infopath
}
set_bin_symlinks() {
# Set symlinks to binaries in /usr/bin/
local target=${1} f
for f in ${BINARYLIST}; do
# set symlink only if target binary actually exists
if [[ -f ${EROOT}/usr/bin/${f}-${target} ]]; then
ln -s "${f}-${target}" "${EROOT}/usr/bin/${f}" || die \
"Couldn't set ${f}-${target} ${EROOT}/usr/bin/${f} symlink"
fi
done
}
set_man_symlinks() {
# Set symlinks to man pages
local target=${1} extension f i
for f in ${MANPAGELIST}; do
for i in "${EROOT}"/usr/share/man/man1/${f}-${target}.1*; do
if [[ -f ${i} ]]; then
# target file exists; determine compress extension
extension=${i##*/${f}-${target}.1}
ln -s "${f}-${target}.1${extension}" \
"${EROOT}/usr/share/man/man1/${f}.1${extension}"
fi
done
done
}
set_symlinks() {
# Set symlinks to binaries and man pages, update info path
local target=$1 nomain=$2 targets
# target may be specified by its name or its index
if is_number "${target}"; then
# numeric index, find the target's name
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: ${1}"
target=${targets[target-1]}
fi
# is the target valid, i.e. does an Emacs binary with this name exist?
[[ -f ${EROOT}/usr/bin/${target} ]] \
|| die -q "Target \"${1}\" doesn't appear to be valid!"
echo "Switching emacs to ${target} ..."
remove_symlinks || die -q "Couldn't remove existing symlink"
# the main /usr/bin/emacs symlink is only set for Emacs binaries
# (but not for other providers of auxiliary programs, e.g., XEmacs)
if [[ -z ${nomain} ]]; then
ln -s "${target}" "${EROOT}/usr/bin/emacs" \
|| die "Couldn't set ${target} ${EROOT}/usr/bin/emacs symlink"
fi
set_bin_symlinks "${target}"
set_man_symlinks "${target}"
set_infopath "${target}"
# update /etc/profile.env from /etc/env.d files
do_action env update noldconfig
return 0
}
xemacs_info() {
# This is just informational to tell that XEmacs has been found,
# a wish from graaff
if [[ -e ${EROOT}/usr/bin/xemacs ]]; then
echo
write_list_start "XEmacs is also installed"
fi
}
vim_info() {
# Don't take this too serious
if [[ -e ${EROOT}/usr/bin/vi ]]; then
echo
write_list_start "Vi found, your system is in real trouble now! ;)"
fi
}
test_for_root() {
# checks if the user has rights to modify /usr/bin/
[[ -w ${EROOT}/usr/bin ]] || die -q "You need root privileges!"
}
### show action ###
describe_show() {
echo "Show the current target of the Emacs symlink"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
write_list_start "Current target of Emacs symlink:"
if [[ -L ${EROOT}/usr/bin/emacs && -e ${EROOT}/usr/bin/emacs ]]; then
write_kv_list_entry \
"$(basename "$(readlink "${EROOT}/usr/bin/emacs")")" ""
elif [[ -e ${EROOT}/usr/bin/emacs ]]; then
write_kv_list_entry \
"(not a symlink or target of symlink does not exist)" ""
else
write_kv_list_entry "(unset)" ""
fi
if ! is_output_mode brief; then
xemacs_info
#vim_info
fi
}
### list action ###
describe_list() {
echo "List available Emacs symlink targets"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local i targets
targets=( $(find_targets) )
for (( i = 0; i < ${#targets[@]}; i++ )); do
# Highlight the currently chosen version
[[ ${targets[i]} = \
"$(basename "$(readlink "${EROOT}/usr/bin/emacs")")" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_list_start "Available Emacs symlink targets:"
write_numbered_list -m "(none found)" "${targets[@]}"
if ! is_output_mode brief; then
xemacs_info
#vim_info
fi
}
### set action ###
describe_set() {
echo "Set a new Emacs symlink"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
test_for_root
if [[ -e ${EROOT}/usr/bin/emacs && ! -L ${EROOT}/usr/bin/emacs ]]; then
die -q "${EROOT}/usr/bin/emacs exists but is not a symlink"
fi
set_symlinks "${1}" || die -q "Couldn't set a new symlink"
# ctags symlinks are handled in an own module now
do_action ctags update
}
### update action ###
describe_update() {
echo "Automatically update the Emacs symlink"
}
describe_update_options() {
echo "ifunset : Do not override currently set version"
}
do_update() {
[[ -z $1 || $1 = ifunset || $1 = --if-unset ]] || die -q "Usage error"
[[ $# -gt 1 ]] && die -q "Too many parameters"
test_for_root
if [[ -L ${EROOT}/usr/bin/emacs ]]; then
if [[ $1 == *if*unset && -e ${EROOT}/usr/bin/emacs ]]; then
do_action ctags update ifunset
return
fi
# this is not redundant: "update" is called in pkg_postrm() of emacs
# and should clean up any dead symlinks if no valid target exists
remove_symlinks || die -q "Couldn't remove existing symlink"
elif [[ -e ${EROOT}/usr/bin/emacs ]]; then
die -q "${EROOT}/usr/bin/emacs exists but is not a symlink"
fi
local targets=( $(find_targets) )
if [[ ${#targets[@]} -gt 0 ]]; then
set_symlinks "${targets[${#targets[@]}-1]}" \
|| die -q "Couldn't set a new symlink"
elif [[ -f ${EROOT}/usr/bin/xemacs ]]; then
# no Emacs target found - link to XEmacs versions
set_symlinks xemacs nomain
fi
# ctags and etags symlinks are handled in an own module
do_action ctags update
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
emacs apply_text_highlights "${right}" "${val}"
Manage /usr/bin/emacs version
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit config multilib package-manager
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
ES_VALID_MULTILIB_DIRS="lib lib32 lib64 libx32"
# list_libdirs PUBLIC
# Returns a space separated list of libdirs available on this machine
list_libdirs() {
local dir
local -a libdirs
for dir in ${ES_VALID_MULTILIB_DIRS}; do
[[ -d ${EROOT}/${dir} ]] && libdirs[${#libdirs[@]}]=${dir}
done
echo "${libdirs[@]}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# package_manager PRIVATE
# Return the package manager we're going to use.
package_manager() {
local pm
case ${PACKAGE_MANAGER} in
portage) pm=portage ;;
pkgcore) pm=pkgcore ;;
paludis) pm=paludis ;;
esac
echo "${pm:-portage}"
}
# portageq
# Run portageq with safe filename as set by configure. Redirect stderr
portageq() {
/Users/tetsushi/Gentoo/usr/bin/portageq "$@" 2>/dev/null
}
# run_paludis PRIVATE
# Run CAVE (defaults to "cave"). Redirect stderr
run_paludis() {
${CAVE:-cave} "$@" 2>/dev/null
}
# arch
# Return the architecture we're running on...
arch() {
local ret=$(envvar sys-devel/gcc ARCH)
if [[ -n ${EPREFIX} && -n ${ret} && ${ret%-*} = "${ret}" ]]; then
# prefix/linux profiles lie about their ARCH
case $(envvar sys-devel/gcc KERNEL) in
linux) ret+="-linux" ;;
*)
write_warning_msg \
"Failed to determine \${ARCH}." \
"Please submit a bug report."
return 1
;;
esac
fi
# $arch will be null if there's no current make.profile symlink.
# We cannot get a list of valid profiles without it.
if [[ -z ${ret} ]]; then
if [[ -n ${ROOT} && ${ROOT} != "/" ]]; then
write_warning_msg \
"Failed to determine \${ARCH}." \
"Is your make.profile symlink valid?"
return 1
fi
# Try to determine arch from HOSTTYPE and OSTYPE, which are
# derived from the GNU triplet (at build time of bash)
case ${HOSTTYPE} in
alpha*) ret=alpha ;;
arm*) ret=arm ;;
hppa*) ret=hppa ;;
i?86) ret=x86 ;;
ia64) ret=ia64 ;;
m68k) ret=m68k ;;
mips*) ret=mips ;;
powerpc) ret=ppc ;;
powerpc64) ret=ppc64 ;;
s390*) ret=s390 ;;
sh*) ret=sh ;;
sparc) ret=sparc ;;
sparc64) ret=sparc64 ;;
x86_64) ret=amd64 ;;
*)
write_warning_msg \
"Unknown architecture \"${HOSTTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
if [[ -z ${EPREFIX} ]]; then
case ${OSTYPE} in
linux*) ;;
dragonfly*) ret+="-dfly" ;;
freebsd*) ret+="-fbsd" ;;
netbsd*) ret+="-nbsd" ;;
openbsd*) ret+="-obsd" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
else
# Prefix architectures
if [[ ${ret} = amd64 && ${OSTYPE} != linux* ]]; then
# amd64 is sometimes called x64 on Prefix
ret=x64
fi
case ${OSTYPE} in
aix*) ret+="-aix" ;;
cygwin*) ret+="-cygwin" ;;
darwin*) ret+="-macos" ;;
freebsd*) ret+="-freebsd" ;;
hpux*) ret+="-hpux" ;;
interix*) ret+="-interix" ;;
linux*) ret+="-linux" ;;
mint*) ret+="-mint" ;;
netbsd*) ret+="-netbsd" ;;
openbsd*) ret+="-openbsd" ;;
solaris*) ret+="-solaris" ;;
winnt*) ret+="-winnt" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
fi
fi
echo "${ret}"
}
# envvar
# Return the contents of environment variable $2 as seen by package manager
# for package $1.
envvar() {
[[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
case $(package_manager) in
# portage does not support per-package envvar lookup
portage) portageq envvar "$2" ;;
pkgcore) pinspect portageq envvar "$2" ;;
paludis) run_paludis print-id-environment-variable --best \
--variable-name "$2" --format '%v\n' "$1" ;;
esac
}
# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
[[ $# -eq 1 ]] || die "best_version expects exactly one argument"
case $(package_manager) in
portage) portageq best_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq best_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis print-best-version --format name-version "$1" ;;
esac
}
# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
[[ $# -eq 1 ]] || die "has_version expects exactly one argument"
case $(package_manager) in
portage) portageq has_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq has_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis has-version "$1" ;;
esac
}
# get_repositories
# return list of repositories known to the package manager
get_repositories() {
case $(package_manager) in
portage) portageq get_repos "${EROOT:-/}" ;;
pkgcore) pinspect portageq get_repositories ;;
paludis) run_paludis print-repositories ;;
esac
}
# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
[[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
local repo=$1
case $(package_manager) in
portage) echo "$(portageq get_repo_path \
"${EROOT:-/}" "${repo}")/metadata/news" ;;
pkgcore) pinspect portageq get_repo_news_path "${repo}" ;;
paludis) run_paludis print-repository-metadata ${repo} \
--raw-name newsdir --format '%v\n' ;;
esac
}
# env_update
# Run env-update command, if available with the package manager
# If $1 is non-zero: also run ldconfig to update /etc/ld.so.cache
env_update() {
local noldconfig
[[ $1 -ne 0 ]] || noldconfig=y
case $(package_manager) in
portage) "/Users/tetsushi/Gentoo/usr/sbin/env-update" ${noldconfig:+--no-ldconfig} ;;
pkgcore) pmaint env-update ${noldconfig:+--skip-ldconfig} ;;
paludis) return 127 ;;
esac
}
DESCRIPTION="Manage environment variables set in /etc/env.d/"
MAINTAINER="eselect@gentoo.org"
# Classes of env-vars
SPACE_CLASS="CONFIG_PROTECT
CONFIG_PROTECT_MASK"
PATH_CLASS="ADA_INCLUDE_PATH
ADA_OBJECTS_PATH
CLASSPATH
INFODIR
INFOPATH
KDEDIRS
LDPATH
MANPATH
PATH
PKG_CONFIG_PATH
PRELINK_PATH
PRELINK_PATH_MASK
PYTHONPATH
ROOTPATH"
# Recognized file formats:
MIME_WHITELIST="text/plain text/x-makefile"
# Configuration files
ENVPROFILE="${EROOT}/etc/profile.env"
LDCONFIG="${EROOT}/etc/ld.so.conf"
PRELINK="${EROOT}/etc/prelink.conf"
# Keep all stored LDPATHS
ESELECT_LDPATH=( )
# is_envd_file()
# Return successfuly when file can be sourced.
is_envfile() {
local mime envfile=${1}
# Make sure it is a file and no backup file
[[ -f ${envfile} ]] || return 1
[[ -n ${envfile##*~} ]] || return 1
[[ ${envfile##*.} != bak ]] || return 1
mime=$(POSIXLY_CORRECT=1 file -i "${envfile}" \
| cut -d ' ' -f 2 | sed -e 's/;$//')
if ! has ${mime} ${MIME_WHITELIST}; then
echo "Skipping non-text file ${envfile}."
return 1
fi
return 0
}
# update_envvar_classes()
# Update the contents of *_CLASS based on env,d files.
update_envvar_classes() {
local -a envfiles
local value
envfiles=( "${EROOT}"/etc/env.d/* )
for envfile in "${envfiles[@]}"; do
is_envfile "${envfile}" || continue
value=$(load_config "${envfile}" COLON_SEPARATED)
for x in ${value}; do
has ${x} ${PATH_CLASS} || PATH_CLASS="${PATH_CLASS} ${x}"
done
value=$(load_config "${envfile}" SPACE_SEPARATED)
for x in ${value}; do
has ${x} ${SPACE_CLASS} || SPACE_CLASS="${SPACE_CLASS} ${x}"
done
done
}
# create_profile_env()
# Create profile.env file
create_profile_env() {
local -a envfiles
local vars store items tmpprofile ifs_save
envfiles=( "${EROOT}"/etc/env.d/* )
# Blank the file first!
tmpprofile=$(mktemp "${ROOT}/tmp/profile.XXXXXX")
[[ $? -eq 0 ]] || die "Couldn't create temporary file!"
# Gather ye classes while ye may!
update_envvar_classes
# Parse all files in env.d
for envfile in "${envfiles[@]}"; do
is_envfile "${envfile}" || continue
# Which vars are to be loaded?
# TODO: Change to bash magic?
vars=$(LC_ALL=C sed \
-e 's/^\s*//' \
-e 's/^export\s\+//' \
-e '/^[[:alpha:]_]\w*=/!d' \
-e 's/=.*//' \
"${envfile}")
for var in ${vars}; do
if [[ ${var} = LDPATH ]]; then
# Don't store LDPATH in profile.env
continue
elif has ${var} ${PATH_CLASS}; then
# Colon separated
store=$(load_config "${tmpprofile}" ${var})
if [[ -z ${store} ]]; then
store=$(load_config "${envfile}" ${var})
else
items=$(load_config "${envfile}" ${var})
ifs_save=${IFS-$' \t\n'}
IFS=":"
for item in ${items}; do
has ${item} ${store} \
|| store="${store}${store:+:}${item}"
done
IFS=${ifs_save}
fi
elif has ${var} ${SPACE_CLASS}; then
# Space separated
store=$(load_config "${tmpprofile}" ${var})
if [[ -z ${store} ]]; then
store=$(load_config "${envfile}" ${var})
else
items=$(load_config "${envfile}" ${var})
for item in ${items}; do
has ${item} ${store} \
|| store="${store}${store:+ }${item}"
done
fi
else
# Ok, just a non-cumulative var.
store=$(load_config "${envfile}" ${var})
fi
store_config "${tmpprofile}" ${var} "${store}"
done
has LDPATH ${vars} || continue
# Store LDPATH for later processing
items=$(load_config "${envfile}" LDPATH)
ifs_save=${IFS-$' \t\n'}
IFS=":"
items=( ${items} )
IFS=${ifs_save}
for item in "${items[@]}"; do
has "${item}" "${ESELECT_LDPATH[@]}" \
|| ESELECT_LDPATH=( "${ESELECT_LDPATH[@]}" "${item}" )
done
done
# Move new file onto old one
chmod a+r "${tmpprofile}"
mv "${tmpprofile}" "$(canonicalise "${ENVPROFILE}")" \
|| die "Couldn't move ${tmpprofile} to ${ENVPROFILE}!\n
Original profile.env remains unchanged."
}
# create_ld_so_conf()
# Create ld.so.conf file based upon gathered LDPATHs
create_ld_so_conf() {
[[ -z ${ESELECT_LDPATH[@]} ]] \
&& die -q "No LDPATHs found in ${EROOT}/etc/env.d/*"
local str
str="# ld.so.conf autogenerated by eselect\n"
str="${str}# Make all changes to /etc/env.d files\n"
for x in "${ESELECT_LDPATH[@]}"; do
str="${str}${x}\n"
done
echo -n -e "${str}" >"$(canonicalise "${LDCONFIG}")"
}
# create_prelink_conf()
# Create prelink.conf file based upon existing profile.env
create_prelink_conf() {
[[ -z ${ESELECT_LDPATH[@]} ]] \
&& die -q "No LDPATHs found in ${EROOT}/etc/env.d/*"
local path prelink_path prelink_mask str x ifs_save
str="# prelink.conf autogenerated by eselect\n"
str="${str}# Make all changes to /etc/env.d files\n"
# Add default items
for x in /bin /sbin /usr/bin /usr/sbin; do
str="${str}-l ${EPREFIX}${x}\n"
done
for x in $(list_libdirs); do
[[ -e ${EROOT}/${x} ]] && str="${str}-l ${EPREFIX}/${x}\n"
[[ -e ${EROOT}/usr/${x} ]] && str="${str}-l ${EPREFIX}/usr/${x}\n"
done
path=$(load_config "${ENVPROFILE}" PATH)
prelink_path=$(load_config "${ENVPROFILE}" PRELINK_PATH)
prelink_mask=$(load_config "${ENVPROFILE}" PRELINK_PATH_MASK)
ifs_save=${IFS-$' \t\n'}
IFS=":"
for x in ${path} ${prelink_path} "${ESELECT_LDPATH[@]}"; do
has ${x} ${prelink_mask} && continue
[[ -z ${x##*/} ]] || x="${x}/"
str="${str}-h ${x}\n"
done
for x in ${prelink_mask}; do
str="${str}-b ${x}\n"
done
IFS=${ifs_save}
echo -n -e "${str}" >"$(canonicalise "${PRELINK}")"
}
# update_ldcache()
# Update ld.so.cache using ldconfig
update_ldcache() {
case $(uname -s) in
Linux | *GNU | *gnu)
echo "Regenerating ${ROOT}/etc/ld.so.cache..."
(
cd /
ldconfig -X ${1} -r "${ROOT:-/}"
)
;;
FreeBSD | DragonFly)
echo "Regenerating ${ROOT}/var/run/ld-elf.so.hints..."
(
cd /
ldconfig -elf -i -f "${ROOT:-/}var/run/ld-elf.so.hints" \
"${ROOT:-/}etc/ld.so.conf"
)
;;
esac
}
### update action
describe_update() {
echo "Collect environment variables from all scripts in /etc/env.d/"
}
describe_update_parameters() {
echo ""
}
describe_update_options() {
echo "noldconfig : Do not alter the ld.so cache or configuration."
}
do_update() {
local ldconfig=1
while [[ $# -gt 0 ]]; do
case ${1##--} in
makelinks)
# option is ignored, only for backwards compatibility
;;
noldconfig|no-ldconfig)
ldconfig=0
;;
*)
die -q "Unknown option '${1}'"
;;
esac
shift
done
# Test for sufficient permissions
if [[ -e ${ENVPROFILE} ]]; then
[[ -w ${ENVPROFILE} ]] || die -q "You need to be root!"
else
touch "${ENVPROFILE}" || die -q "You need to be root!"
fi
# Use the package manager's env-update command if available,
# otherwise (if 127 was returned) fall back to shell implementation
env_update ${ldconfig} && return
[[ $? -eq 127 ]] || die -q "env-update failed"
# Create configuration files
create_profile_env
if [[ ${ldconfig} -ne 0 ]]; then
create_ld_so_conf
[[ -e ${EROOT}/usr/sbin/prelink ]] && create_prelink_conf
update_ldcache
fi
# fix up ${ENVPROFILE}
cp "${ENVPROFILE}" "${ENVPROFILE/.env/.csh}"
sed -i -e "s/^\(.*\)=\"\(.*\)\"/export \1='\2'/" \
"$(canonicalise "${ENVPROFILE}")"
sed -i -e "s/^\(.*\)=\"\(.*\)\"/setenv \1 '\2'/" \
"$(canonicalise "${ENVPROFILE/.env/.csh}")"
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
env apply_text_highlights "${right}" "${val}"
Manage environment variables set in /etc/env.d/
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*-
# Copyright 2005-2012 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
#
# DOCUMENTATION
# Following actions possible
# * show do_show()
# * list do_list()
# * set do_set()
# * update do_update()
#
# Behaviour:
# do_show():
# Checks if /usr/bin/ctags is a link and if the target exists,
# if yes, it outputs the currently linked ctags implementation.
# If it is no symlink, the user is told so, the same if there is
# no /usr/bin/ctags or the target does not exist.
# do_list(): List all available ctags implementations.
# do_set(): Set a version to be target of the symlink.
# do_update(): Set the target to the "best" available version. See below.
# This module is used for ctags and etags.
# Determine our name from ESELECT_MODULE_NAME, with BASH_SOURCE as fallback.
#CTAGS=${ESELECT_MODULE_NAME:-$(basename "${BASH_SOURCE[0]%.*}")}
CTAGS=etags
DESCRIPTION="Manage /usr/bin/${CTAGS} implementations"
MAINTAINER="emacs@gentoo.org"
VERSION="1.14"
find_targets() {
# Return the list of available ctags implementations
# (X)Emacs: offer only one ctags implementation, namely for the
# currently active Emacs version (selected by emacs.eselect)
# The logic here is the same as in emacs.eselect, don't change it!
local emacs
if [[ -L ${EROOT}/usr/bin/emacs && -e ${EROOT}/usr/bin/emacs ]]; then
emacs=$(basename "$(readlink "${EROOT}/usr/bin/emacs")")
[[ -f ${EROOT}/usr/bin/${CTAGS}-${emacs} ]] && echo "${CTAGS}-${emacs}"
elif [[ -f ${EROOT}/usr/bin/xemacs ]]; then
[[ -f ${EROOT}/usr/bin/${CTAGS}-xemacs ]] && echo "${CTAGS}-xemacs"
elif [[ ${CTAGS} = etags ]]; then
# We are called as etags module, but no (X)Emacs is installed.
# Return an empty list in this case, because we don't want
# exuberant-ctags as default for etags (for ctags it's fine).
# Also, vi purists wouldn't want an etags symlink.
return
fi
# Exuberant ctags
[[ -f ${EROOT}/usr/bin/exuberant-ctags ]] && echo exuberant-ctags
}
remove_symlinks() {
# Remove existing symlinks to binary and man page
rm -f "${EROOT}/usr/bin/${CTAGS}" "${EROOT}"/usr/share/man/man1/${CTAGS}.1*
}
set_bin_symlinks() {
# Set symlink to binary
local target=${1}
ln -s "${target}" "${EROOT}/usr/bin/${CTAGS}" \
|| die "Couldn't set ${target} ${EROOT}/usr/bin/${CTAGS} symlink"
}
set_man_symlinks() {
# Set symlink to man page
local target=${1} extension i
for i in "${EROOT}"/usr/share/man/man1/${target}.1*; do
if [[ -f ${i} ]]; then
# target file exists; determine compress extension
extension=${i##*/${target}.1}
ln -s "${target}.1${extension}" \
"${EROOT}/usr/share/man/man1/${CTAGS}.1${extension}"
fi
done
}
set_symlinks() {
# Set symlinks to binary and man page
local target=$1 targets
# target may be specified by its name or its index
if is_number "${target}"; then
# numeric index, find the target's name
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: ${1}"
target=${targets[target-1]}
fi
# is the target valid, i.e. does a ctags binary with this name exist?
[[ -f ${EROOT}/usr/bin/${target} ]] \
|| die -q "Target \"$1\" doesn't appear to be valid!"
echo "Switching ${CTAGS} to ${target} ..."
remove_symlinks || die -q "Couldn't remove existing symlink"
set_bin_symlinks "${target}"
set_man_symlinks "${target}"
return 0
}
test_for_root() {
# checks if the user has rights to modify /usr/bin/
[[ -w ${EROOT}/usr/bin ]] || die -q "You need root privileges!"
}
### show action ###
describe_show() {
echo "Show the current target of the ${CTAGS} symlink"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
write_list_start "Current target of ${CTAGS} symlink:"
if [[ -L ${EROOT}/usr/bin/${CTAGS} && -e ${EROOT}/usr/bin/${CTAGS} ]]
then
write_kv_list_entry \
"$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")" ""
elif [[ -e ${EROOT}/usr/bin/${CTAGS} ]]; then
write_kv_list_entry \
"(not a symlink or target of symlink does not exist)" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available ${CTAGS} symlink targets"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local i targets
targets=( $(find_targets) )
for (( i = 0; i < ${#targets[@]}; i++ )); do
# Highlight the currently chosen version
[[ ${targets[i]} = \
"$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_list_start "Available ${CTAGS} symlink targets:"
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set a new ${CTAGS} symlink"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
test_for_root
if [[ -e ${EROOT}/usr/bin/${CTAGS} && ! -L ${EROOT}/usr/bin/${CTAGS} ]]
then
die -q "${EROOT}/usr/bin/${CTAGS} exists but is not a symlink"
fi
set_symlinks "$1" || die -q "Couldn't set a new symlink"
}
### update action ###
describe_update() {
echo "Automatically update the ${CTAGS} symlink"
}
describe_update_options() {
echo "ifunset : Do not override currently set version"
}
do_update() {
[[ -z $1 || $1 = ifunset || $1 = --if-unset ]] || die -q "Usage error"
[[ -z $2 || $2 = norecursion ]] || die -q "Usage error"
[[ $# -gt 2 ]] && die -q "Too many parameters"
test_for_root
if ! [[ $1 == *if*unset \
&& -L ${EROOT}/usr/bin/${CTAGS} && -e ${EROOT}/usr/bin/${CTAGS} ]]
then
local current=""
if [[ -L ${EROOT}/usr/bin/${CTAGS} ]]; then
current=$(basename "$(readlink "${EROOT}/usr/bin/${CTAGS}")")
if [[ ! -e ${EROOT}/usr/bin/${CTAGS} ]]; then
# clean up dead symlinks
remove_symlinks || die -q "Couldn't remove existing symlink"
fi
elif [[ -e ${EROOT}/usr/bin/${CTAGS} ]]; then
if ! [[ ${CTAGS} = ctags && $(uname) = FreeBSD ]]; then
die -q "${EROOT}/usr/bin/${CTAGS} exists but is not a symlink"
fi
# On FreeBSD ctags is a real file, installed by freebsd-ubin
current=nolink
fi
# For an "update" only the version should be changed, but not the
# provider (i.e. Emacs vs Exuberant). At the moment only (X)Emacs
# offers several concurrent versions.
local i target targets=( $(find_targets) )
if [[ ${#targets[@]} -gt 0 && ${current} != nolink ]]; then
target=${targets[0]}
[[ ${current} == ${CTAGS}-*emacs* ]] && current=${CTAGS}-*emacs*
for i in ${targets[@]}; do
[[ ${i} == ${current} ]] && target=${i}
done
set_symlinks "${target}" || die -q "Couldn't set a new symlink"
fi
fi
# Call "eselect etags update" from the ctags module and vice versa
[[ $2 = norecursion ]] && return
case ${CTAGS} in
ctags) CTAGS=etags do_update "$1" norecursion ;;
etags) CTAGS=ctags do_update "$1" norecursion ;;
esac
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
etags apply_text_highlights "${right}" "${val}"
Manage /usr/bin/etags implementations
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: fontconfig.eselect 728 2009-11-14 21:08:28Z dirtyepic $
DESCRIPTION="Manage fontconfig /etc/fonts/conf.d/ symlinks"
AUTHOR="cardoe@gentoo.org"
MAINTAINER="fonts@gentoo.org"
SVN_DATE='$Date: 2009-11-14 15:08:28 -0600 (Sat, 14 Nov 2009) $'
VERSION=$(svn_date_to_version "${SVN_DATE}")
svn_date_to_version "${SVN_DATE}"
find_targets() {
local targets bc x i=0
bcdirs[i]="${EROOT}/etc/fonts/conf.avail/*.conf"
if [[ -n "${ES_FONTCONFIG_DIRS}" ]] ; then
for x in ${ES_FONTCONFIG_DIRS} ; do
bcdirs[$((++i))]="${x}/*"
done
fi
for bc in ${bcdirs[@]} ; do
[[ -e ${bc} && ${bc} != *~ ]] && targets="${targets}\n$(basename ${bc})"
done
echo -ne ${targets} | sort -u
}
is_enabled() {
bcdir="${EROOT}/etc/fonts/conf.d"
[[ -e ${bcdir}/${1} ]] || return 1
return 0
}
### list action ###
describe_list() {
echo "List available fontconfig .conf files"
}
do_list() {
local n
targets=( $(find_targets) )
write_list_start \
"Available fontconfig .conf files ($(highlight '*') is enabled):"
for (( n = 0; n < ${#targets[@]}; ++n )); do
is_enabled ${targets[n]} \
&& targets[n]=$(highlight_marker "${targets[n]}")
done
write_numbered_list -m "(none found)" "${targets[@]}"
return 0
}
### enable action ###
describe_enable() {
echo "Enable specified fontconfig .conf file(s)"
}
describe_enable_parameters() {
echo ""
}
describe_enable_options() {
echo " : Target name or number (from 'list' action)"
}
do_enable() {
local bc bcdir="${EROOT}/etc/fonts/conf.d"
[[ -z ${1} ]] && die -q "You didn't specify any .conf files to enable"
# create directory if necessary
if [[ ! -d ${bcdir} && -w $(dirname ${bcdir}) ]] ; then
mkdir ${bcdir} || die -q "Failed to create ${bcdir}"
elif [[ ! -d ${bcdir} ]] ; then
die -q "You don't have permission to create ${bcdir}"
fi
# make sure we have proper permissions
[[ -w ${bcdir} ]] || \
die -q "You don't have permission to write to ${bcdir}"
targets=( $(find_targets) )
for bc in $@ ; do
local file target=${bc}
is_number "${target}" && \
target=${targets[$(( ${target} - 1 ))]}
[[ -z "${target}" ]] && \
die -q "Target \"${bc}\" doesn't appear to be valid!"
bc=${target}
# ignore any unrecognized options
[[ ${bc} == --* ]] && continue
# what form is the argument in?
case "${bc}" in
# absolute path
/*)
file="${EROOT}/${bc}"
;;
# relative path
*/*)
file="${EROOT}/${PWD}/${bc}"
;;
# no path
*)
# CWD
if [[ -f ${bc} ]] ; then
file="${EROOT}/${PWD}/${bc}"
# assume /etc/fonts/conf.avail
elif [[ -f ${EROOT}/etc/fonts/conf.avail/${bc} ]]
then
file="${EROOT}/etc/fonts/conf.avail/${bc}"
else
if [[ -n "${ES_FONTCONFIG_DIRS}" ]] ; then
for x in ${ES_FONTCONFIG_DIRS} ; do
[[ -f ${x}/${bc} ]] && file="${x}/${bc}"
done
fi
[[ -e ${file} ]] || \
file="${EROOT}/etc/fonts/conf.avail/${bc}"
fi
;;
esac
# does it exist?
if [[ ! -e ${file} ]] ; then
write_error_msg "${file} doesn't exist"
continue
fi
# already installed?
if [[ -e ${bcdir}/$(basename ${bc}) ]] ; then
write_error_msg "$(basename ${bc}) is already installed"
continue
fi
# finally, create the symlink
ln -s "${file}" "${bcdir}" || \
die -q "Failed to create symlink from '${file}' to '${bcdir}'"
done
}
### disable action ###
describe_disable() {
echo "Disable specified fontconfig .conf file(s)"
}
describe_disable_parameters() {
echo ""
}
describe_disable_options() {
echo " : Target name or number (from 'list' action)"
}
do_disable() {
local bc bcdir="${EROOT}/etc/fonts/conf.d"
[[ -z ${1} ]] && die -q "You didn't specify any .conf files to disable"
targets=( $(find_targets) )
for bc in $@ ; do
local file target=${bc}
is_number "${target}" && \
target=${targets[$(( ${target} - 1 ))]}
[[ -z "${target}" ]] && \
die -q "Target \"${bc}\" doesn't appear to be valid!"
bc=${target}
file="${bcdir}/${bc}"
# ignore any unrecognized options
[[ ${bc} == --* ]] && continue
# is in installed?
if [[ ! -e ${file} ]] ; then
write_error_msg "${bc} is not installed"
continue
fi
# remove it if we have permissions
if [[ -w $(dirname ${file}) ]] ; then
rm "${file}" || die -q "Failed to remove ${file}"
else
die -q "You don't have permission to remove ${file}"
fi
done
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
fontconfig apply_text_highlights "${right}" "${val}"
Manage fontconfig /etc/fonts/conf.d/ symlinks
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
DESCRIPTION="Manage the /usr/src/linux symlink"
MAINTAINER="eselect@gentoo.org"
# sort function for kernel versions, to be used in a pipe
sort_kernel_versions() {
local vsort="sort --version-sort"
# Test if our sort supports the --version-sort option
# (should be GNU sort, since the kernel module is GNU/Linux specific)
${vsort} /dev/null || vsort=sort
# We sort kernel versions as follows:
# 1. Run sed to prepend the version string by the numeric version
# and an additional rank indicator that is 0 for release candidates
# or 1 otherwise. After this step we have, for example:
# 2.6.29 1 linux-2.6.29
# 2.6.29 0 linux-2.6.29-rc8
# 2. sort --version-sort
# 3. Run sed again to remove the prepended keys from step 1.
sed -e 's/^\(linux-\)\?\([[:digit:].]\+\)[-_]rc/\2 0 &/' \
-e 't;s/^\(linux-\)\?\([[:digit:].]\+\)/\2 1 &/' \
| LC_ALL=C ${vsort} | sed 's/.* //'
}
# find a list of kernel symlink targets
find_targets() {
local f
for f in "${EROOT}"/usr/src/linux-[[:digit:]]*; do
[[ -d ${f} ]] && basename "${f}"
done | sort_kernel_versions
}
# remove the kernel symlink
remove_symlink() {
rm "${EROOT}/usr/src/linux"
}
# set the kernel symlink
set_symlink() {
local target=$1
if is_number "${target}"; then
local targets=( $(find_targets) )
target=${targets[target-1]}
fi
if [[ -z ${target} ]]; then
die -q "Target \"$1\" doesn't appear to be valid!"
elif [[ -d ${EROOT}/usr/src/${target} ]]; then
ln -s "${target}" "${EROOT}/usr/src/linux"
elif [[ -d ${EROOT}/usr/src/linux-${target} ]]; then
ln -s "linux-${target}" "${EROOT}/usr/src/linux"
else
die -q "Target \"$1\" doesn't appear to be valid!"
fi
}
### show action ###
describe_show() {
echo "Show the current kernel symlink"
}
do_show() {
write_list_start "Current kernel symlink:"
if [[ -L ${EROOT}/usr/src/linux ]]; then
local kernel=$(canonicalise "${EROOT}/usr/src/linux")
write_kv_list_entry "${kernel%/}" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available kernel symlink targets"
}
do_list() {
local i targets=( $(find_targets) )
write_list_start "Available kernel symlink targets:"
for (( i = 0; i < ${#targets[@]}; i++ )); do
[[ ${targets[i]} = \
$(basename "$(canonicalise "${EROOT}/usr/src/linux")") ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set a new kernel symlink target"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
if [[ -L ${EROOT}/usr/src/linux ]]; then
# existing symlink
remove_symlink || die -q "Couldn't remove existing symlink"
set_symlink "$1" || die -q "Couldn't set a new symlink"
elif [[ -e ${EROOT}/usr/src/linux ]]; then
# we have something strange
die -q "${EROOT}/usr/src/linux exists but is not a symlink"
else
set_symlink "$1" || die -q "Couldn't set a new symlink"
fi
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
kernel apply_text_highlights "${right}" "${val}"
Manage the /usr/src/linux symlink
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: lapack.eselect-0.1,v 1.1 2006/06/18 21:06:09 spyderous Exp $
inherit skel
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2006-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# To use this library, you must set MODULE and IFACE.
# MODULE is the name you use to refer to whatever it is that you're selecting
# in help text and so forth.
# IFACE is the subdirectory of /etc/env.d/ that eselect config files are stored
# in for these packages.
#
# There is a file installed at /etc/env.d/$IFACE/$libdir/config containing the
# CURRENT variable, which is set to the current eselect setting. Also, each
# implementation installs a single file at /etc/env.d/$IFACE/$libdir/$implem.
# This file contains a list of symlinks to be created in "source destination"
# format. You must use relative symlinks. In other words, "source" must be
# relative to "destination" but "destination" must be absolute. You may have
# comments in the symlink map file -- any line containing a '#' is considered
# a comment. One caveat about the symlink map -- instead of using "lib" or
# "lib64" etc, you must use @LIBDIR@.
inherit config multilib tests
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
ES_VALID_MULTILIB_DIRS="lib lib32 lib64 libx32"
# list_libdirs PUBLIC
# Returns a space separated list of libdirs available on this machine
list_libdirs() {
local dir
local -a libdirs
for dir in ${ES_VALID_MULTILIB_DIRS}; do
[[ -d ${EROOT}/${dir} ]] && libdirs[${#libdirs[@]}]=${dir}
done
echo "${libdirs[@]}"
}
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# has test list
# Return true if list contains test
has() {
local test=${1} item
shift
for item in "$@" ; do
[[ ${item} == ${test} ]] && return 0
done
return 1
}
# is_function function PUBLIC
# Test whether function exists
is_function() {
[[ $(type -t "${1}" ) == "function" ]]
}
# is_number PUBLIC
# Returns true if and only if $1 is a positive whole number
is_number() {
[[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
}
# find_implems $iface $libdir
# find all possible implems for $libdir
find_implems() {
local -a implems
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
iface=$1 libdir=$2
for file in "${confdir}"/* ; do
[[ -f ${file} ]] || continue
[[ "${file##*/}" != "config" ]] || continue
implems=(${implems[@]} "${file##*/}")
done
echo ${implems[@]}
}
# is_active $iface $libdir $implem
# returns true if $implem is currently used for the $iface/$libdir combination
is_active() {
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
current=$(load_config "${EROOT}/etc/env.d/${1}/${2}/config" CURRENT)
[[ ${current} == ${3} ]]
}
# switch_implem $iface $libdir $implem
# switches $iface/$libdir combination to $implem
switch_implem() {
# set us up
[[ $# -eq 3 ]] || die "Need exactly 3 arguments!"
local iface=${1}
local libdir=${2}
local implem=${3##*/}
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
local current=$(load_config "${confdir}/config" CURRENT)
local dest src
# Get rid of old symlinks, if we have a current config
if [[ -f ${confdir}/${current} ]]; then
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
dest=$2
rm -f "${ROOT}${dest}"
done < "${confdir}/${current}"
fi
# Set up new symlinks
while read line; do
# Skip comments
[[ "${line}" = *#* ]] && continue
line=${line//@LIBDIR@/${libdir}}
set ${line}
src=$1
dest=$2
ln -sf "${src}" "${ROOT}${dest}"
done < "${confdir}/${implem}"
store_config "${confdir}/config" CURRENT ${implem}
}
# iface_do_list $libdir
# Lists the available implementations for $libdir
iface_do_list() {
local -a implems
local libdir=$1 iface=$IFACE
implems=( $(find_implems $iface $libdir ) )
# None installed for $libdir
[[ -z ${implems[@]} ]] \
&& return
write_list_start "Installed $MODULE for library directory $(highlight ${libdir})"
for implem in ${implems[@]} ; do
(( i++ ))
is_active ${iface} ${libdir} ${implem##*/} \
&& implem=$(highlight_marker "${implem}")
write_numbered_list_entry $i "${implem}"
done
}
# iface_do_show $libdir
# Shows the current implementation for $libdir
iface_do_show() {
local iface=$IFACE libdir=$1 implem
local confdir=${EROOT}/etc/env.d/${iface}/${libdir}
[[ -e ${confdir}/config ]] || return
implem=$(load_config "${confdir}/config" CURRENT)
[[ -e ${confdir}/${implem} ]] \
|| die "File \"${confdir}/${implem}\" is missing!"
echo "${libdir}: ${implem}"
}
# get_libdirs
# Wraps list_libdirs() to ensure that output is sorted consistently
get_libdirs() {
list_libdirs | sort
}
### list action
describe_list() {
echo "List all installed $MODULE implementations"
}
do_list() {
local libdir
# Count for listing IFACE/libdir combinations
# We keep it here so it doesn't reset on every call to iface_do_list()
local i=0
for libdir in $(get_libdirs); do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_list $libdir
done
}
### set action
describe_set() {
echo "Activate one of the installed $MODULE implementations"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "implementation : implementation name or number (from 'list' action)"
}
do_set() {
[[ $# -eq 0 ]] && die -q "Please specify exactly 1 implementation!"
local fail=0 iface=$IFACE
local libdirs=$(get_libdirs)
local libdir implem libdir_ct i=0
local -a file implems new_implems mylibdirs myimplems
# Build up list of all valid implems
for libdir in ${libdirs}; do
new_implems=( $(find_implems ${iface} ${libdir}) )
implems=( ${implems[@]} ${new_implems[@]} )
libdir_ct[$i]=${#new_implems[@]}
(( i++ ))
done
# Parse passed parameters into valid libdirs. Other arguments are considered
# implementations (or numbers for them) and are validated later.
# If libdirs are specified, then switch for them. Otherwise, switch for all
# libdirs.
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
else
myimplems=(${myimplems[@]} ${param})
fi
done
set ${myimplems[@]}
# We can only change one implem at a time
[[ ${#myimplems[@]} -ne 1 ]] && \
die -q "Please specify exactly 1 implemention."
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
i=0
for libdir in ${libdirs}; do
# Only move on if we actually have implems here, otherwise we screw up
# $libdir_max and waste time executing pointless code
if [[ ${libdir_ct[$i]} -gt 0 ]]; then
for item in ${@} ; do
if is_number ${item} ; then
# On the first libdir, minimum must be 1. Maxes and later
# mins are incremented by the size of the previous libdir_ct
if [[ -n ${libdir_min} ]]; then
libdir_min=$(( ${libdir_min} + ${libdir_ct[$(( $i - 1 ))]} ))
else
libdir_min="1"
fi
libdir_max=$(( ${libdir_min} + ${libdir_ct[$i]} - 1 ))
if [[ ${item} -ge ${libdir_min} ]] && [[ ${item} -le ${libdir_max} ]] ; then
if ! switch_implem ${iface} ${libdir} ${implems[$(( ${item} -1 ))]}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
else
fail=1
echo "Item not in range ${libdir_min}-${libdir_max} for ${libdir}: ${item}"
continue
fi
else
# Only attempt to switch to an implementation if it's available
# for that libdir
if has ${item} $(find_implems ${iface} ${libdir}); then
if ! switch_implem ${iface} ${libdir} ${item}; then
fail=1
echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
continue
fi
fi
fi
done
fi
(( i++ ))
done
[[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
}
### show action
describe_show() {
echo "Print the currently active $MODULE implementation"
}
do_show() {
local libdir
local libdirs=$(get_libdirs)
for param in ${@} ; do
if has ${param} ${libdirs} ; then
mylibdirs=(${mylibdirs[@]} ${param})
fi
done
[[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
for libdir in ${libdirs}; do
[[ -d ${EROOT}/usr/${libdir} && ! -L ${EROOT}/usr/${libdir} ]] \
&& iface_do_show $libdir
done
}
### add action
describe_add() {
echo "Add a new $MODULE implementation"
}
describe_add_parameters() {
echo " "
}
describe_add_options() {
echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
echo "file : path to file containing symlink map"
echo "implementation : name of the $MODULE implementation"
}
do_add() {
[[ $# -eq 3 ]] \
|| die -q "Please specify 1 library directory, 1 file to install and 1 implementation!"
# If $D is set, we're adding from portage so we want to respect sandbox.
# Otherwise, respect the ROOT variable.
local prefix=${D:-${ROOT}}${EPREFIX}
# Create directory if necessary
if [[ ! -e ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
mkdir -p "${prefix}/etc/env.d/${IFACE}/${1}"
elif [[ ! -d ${prefix}/etc/env.d/${IFACE}/${1} ]]; then
die -q "${prefix}/etc/env.d/${IFACE}/${1} exists but isn't a directory!"
fi
if ! cp "${2}" "${prefix}/etc/env.d/${IFACE}/${1}/${3}"; then
die -q "Installing ${2} as ${prefix}/etc/env.d/${IFACE}/${1}/${3} failed!"
fi
}
MODULE="LAPACK"
IFACE="lapack"
DESCRIPTION="Manage installed $MODULE implementations"
MAINTAINER="spyderous@gentoo.org"
SVN_DATE='$Date: 2006/06/18 21:06:09 $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
svn_date_to_version "${SVN_DATE}"
# vim: set ft=eselect :
echo "${!key}"
apply_text_highlights "${left}" "${key}"
lapack apply_text_highlights "${right}" "${val}"
Manage installed LAPACK implementations
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit config
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
DESCRIPTION="Manage the LANG environment variable"
MAINTAINER="matsuu@gentoo.org"
# file name as documented in http://www.gentoo.org/doc/en/utf-8.xml
LOCALE_ENVFILE="/etc/env.d/02locale"
locale_list() {
"${EROOT}/usr/bin/locale" -a
}
validate_locale() {
local lang=$1
# exit status of locale is unreliable, check for output to stderr instead
[[ -z $(LC_ALL=${lang} "${EROOT}/usr/bin/locale" 2>&1 >/dev/null) ]]
}
# find a list of valid targets
find_targets() {
local list cur
list=$(locale_list)
echo ${list}
# also output the current value if it isn't in our list
cur=$(read_env_value)
[[ -n ${cur} ]] && ! has "${cur}" ${list} && echo "${cur}"
}
# read variable value from config file
read_env_value() {
load_config "${EROOT}${LOCALE_ENVFILE}" "LANG"
}
# write variable to config file
write_env_value() {
[[ -w ${EROOT}${LOCALE_ENVFILE%/*} ]] \
|| die -q "You need root privileges!"
store_config "${EROOT}${LOCALE_ENVFILE}" "LANG" "$1"
}
### show action ###
describe_show() {
echo "Show value of the LANG variable in profile"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur=$(read_env_value)
write_list_start "LANG variable in profile:"
write_kv_list_entry "${cur:-(none)}"
}
### list action ###
describe_list() {
echo "List available targets for the LANG variable"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur targets i
cur=$(read_env_value)
targets=( $(find_targets) )
write_list_start "Available targets for the LANG variable:"
for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
targets[i]="${targets[i]}"
# display a star to indicate the currently chosen version
[[ ${targets[i]} = "${cur}" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list "${targets[@]}"
if is_output_mode brief; then
:
elif [[ ${#targets[@]} -eq 0 ]]; then
write_kv_list_entry "(none found)" ""
else
write_numbered_list_entry " " "(free form)"
fi
}
### set action ###
describe_set() {
echo "Set the LANG variable in profile"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the variable to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
local target=$1 targets=()
# target may be specified by its name or its index
if is_number "${target}"; then
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: $1"
target=${targets[target-1]%%:*}
fi
validate_locale "${target}" \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
echo "Setting LANG to ${target} ..."
write_env_value "${target}"
# update profile
do_action env update noldconfig
[[ ${ROOT:-/} = / ]] && echo \
"Run \". ${EROOT}/etc/profile\" to update the variable in your shell."
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
locale apply_text_highlights "${right}" "${val}"
Manage the LANG environment variable
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2006-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit config
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
DESCRIPTION="Query eselect modules"
MAINTAINER="eselect@gentoo.org"
DEFAULT_ACTION="list"
### list action
describe_list() {
echo "List all available modules"
}
# List all installed modules
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local path file module name desc
local -a extra_modules
for path in "${ESELECT_MODULES_PATH[@]}" ; do
[[ -d ${path} ]] || continue
for file in "${path}"/*.eselect ; do
[[ -f ${file} ]] || continue
extra_modules=( "${extra_modules[@]}" "${file}" )
done
done
if is_output_mode brief; then
# This is mainly intended for bash completion
echo "help"
echo "usage"
echo "version"
for module in "${extra_modules[@]}" ; do
name=${module##*/}
echo "${name%%.eselect}"
done
else
write_list_start "Built-in modules:"
write_kv_list_entry "help" "Display a help message"
write_kv_list_entry "usage" "Display a usage message"
write_kv_list_entry "version" "Display version information"
if [[ ${#extra_modules[@]} -gt 0 ]] ; then
echo
write_list_start "Extra modules:"
for module in "${extra_modules[@]}" ; do
name=${module##*/}
name=${name%%.eselect}
desc=$(ESELECT_MODULE_NAME=${name} \
load_config "${module}" DESCRIPTION)
desc=${desc:-No description available}
write_kv_list_entry "${name}" "${desc}"
done
fi
fi
}
### has action
describe_has() {
echo "Return true if the module is installed, and false otherwise"
}
describe_has_parameters() {
echo ""
}
do_has() {
[[ -z $1 ]] && die -q "Required option (module name) missing"
[[ $# -gt 1 ]] && die -q "Too many parameters"
local modname=$1 modpath
for modpath in "${ESELECT_MODULES_PATH[@]}" ; do
[[ -f ${modpath}/${modname}.eselect ]] && return 0
done
return 1
}
### add action
# *** Commented out. Do we really want to have an eselect module that is
# *** installing other modules in a system directory? Also, this should
# *** go together with a "remove" action.
# describe_add() {
# echo "Install the given module file somewhere that eselect can find it."
# echo "By default, install to \$HOME/.eselect/modules/, unless running as "
# echo "root. Then, install to ${ESELECT_DATA_PATH}/modules/."
# }
# describe_add_parameters() {
# echo ""
# }
# do_add() {
# local local_path="${ROOT}${HOME}/.eselect/modules/" module_file
# local force_default=0
#
# if [[ $1 = "--force-default-location" ]] ; then
# force_default=1
# shift
# fi
# module_file=$1
#
# [[ -z ${module_file} ]] && die -q "Required option (module file) missing"
#
# # TODO: Don't install the module "somewhere", depending on write access.
# # Add an option to control if it goes to the user's or to the system dir.
# if ! cp "${module_file}" "${ESELECT_DEFAULT_MODULES_PATH}" &> /dev/null ; then
# [[ ${force_default} == 1 ]] \
# && die -q "Failed to install module file to default modules path"
#
# mkdir -p "${local_path}" \
# || die -q "Failed to create module install directory"
# cp "${module_file}" "${local_path}" \
# || die -q "Failed to install module file"
# fi
# }
echo "${!key}"
apply_text_highlights "${left}" "${key}"
modules apply_text_highlights "${right}" "${val}"
Query eselect modules
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit package-manager
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# package_manager PRIVATE
# Return the package manager we're going to use.
package_manager() {
local pm
case ${PACKAGE_MANAGER} in
portage) pm=portage ;;
pkgcore) pm=pkgcore ;;
paludis) pm=paludis ;;
esac
echo "${pm:-portage}"
}
# portageq
# Run portageq with safe filename as set by configure. Redirect stderr
portageq() {
/Users/tetsushi/Gentoo/usr/bin/portageq "$@" 2>/dev/null
}
# run_paludis PRIVATE
# Run CAVE (defaults to "cave"). Redirect stderr
run_paludis() {
${CAVE:-cave} "$@" 2>/dev/null
}
# arch
# Return the architecture we're running on...
arch() {
local ret=$(envvar sys-devel/gcc ARCH)
if [[ -n ${EPREFIX} && -n ${ret} && ${ret%-*} = "${ret}" ]]; then
# prefix/linux profiles lie about their ARCH
case $(envvar sys-devel/gcc KERNEL) in
linux) ret+="-linux" ;;
*)
write_warning_msg \
"Failed to determine \${ARCH}." \
"Please submit a bug report."
return 1
;;
esac
fi
# $arch will be null if there's no current make.profile symlink.
# We cannot get a list of valid profiles without it.
if [[ -z ${ret} ]]; then
if [[ -n ${ROOT} && ${ROOT} != "/" ]]; then
write_warning_msg \
"Failed to determine \${ARCH}." \
"Is your make.profile symlink valid?"
return 1
fi
# Try to determine arch from HOSTTYPE and OSTYPE, which are
# derived from the GNU triplet (at build time of bash)
case ${HOSTTYPE} in
alpha*) ret=alpha ;;
arm*) ret=arm ;;
hppa*) ret=hppa ;;
i?86) ret=x86 ;;
ia64) ret=ia64 ;;
m68k) ret=m68k ;;
mips*) ret=mips ;;
powerpc) ret=ppc ;;
powerpc64) ret=ppc64 ;;
s390*) ret=s390 ;;
sh*) ret=sh ;;
sparc) ret=sparc ;;
sparc64) ret=sparc64 ;;
x86_64) ret=amd64 ;;
*)
write_warning_msg \
"Unknown architecture \"${HOSTTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
if [[ -z ${EPREFIX} ]]; then
case ${OSTYPE} in
linux*) ;;
dragonfly*) ret+="-dfly" ;;
freebsd*) ret+="-fbsd" ;;
netbsd*) ret+="-nbsd" ;;
openbsd*) ret+="-obsd" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
else
# Prefix architectures
if [[ ${ret} = amd64 && ${OSTYPE} != linux* ]]; then
# amd64 is sometimes called x64 on Prefix
ret=x64
fi
case ${OSTYPE} in
aix*) ret+="-aix" ;;
cygwin*) ret+="-cygwin" ;;
darwin*) ret+="-macos" ;;
freebsd*) ret+="-freebsd" ;;
hpux*) ret+="-hpux" ;;
interix*) ret+="-interix" ;;
linux*) ret+="-linux" ;;
mint*) ret+="-mint" ;;
netbsd*) ret+="-netbsd" ;;
openbsd*) ret+="-openbsd" ;;
solaris*) ret+="-solaris" ;;
winnt*) ret+="-winnt" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
fi
fi
echo "${ret}"
}
# envvar
# Return the contents of environment variable $2 as seen by package manager
# for package $1.
envvar() {
[[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
case $(package_manager) in
# portage does not support per-package envvar lookup
portage) portageq envvar "$2" ;;
pkgcore) pinspect portageq envvar "$2" ;;
paludis) run_paludis print-id-environment-variable --best \
--variable-name "$2" --format '%v\n' "$1" ;;
esac
}
# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
[[ $# -eq 1 ]] || die "best_version expects exactly one argument"
case $(package_manager) in
portage) portageq best_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq best_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis print-best-version --format name-version "$1" ;;
esac
}
# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
[[ $# -eq 1 ]] || die "has_version expects exactly one argument"
case $(package_manager) in
portage) portageq has_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq has_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis has-version "$1" ;;
esac
}
# get_repositories
# return list of repositories known to the package manager
get_repositories() {
case $(package_manager) in
portage) portageq get_repos "${EROOT:-/}" ;;
pkgcore) pinspect portageq get_repositories ;;
paludis) run_paludis print-repositories ;;
esac
}
# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
[[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
local repo=$1
case $(package_manager) in
portage) echo "$(portageq get_repo_path \
"${EROOT:-/}" "${repo}")/metadata/news" ;;
pkgcore) pinspect portageq get_repo_news_path "${repo}" ;;
paludis) run_paludis print-repository-metadata ${repo} \
--raw-name newsdir --format '%v\n' ;;
esac
}
# env_update
# Run env-update command, if available with the package manager
# If $1 is non-zero: also run ldconfig to update /etc/ld.so.cache
env_update() {
local noldconfig
[[ $1 -ne 0 ]] || noldconfig=y
case $(package_manager) in
portage) "/Users/tetsushi/Gentoo/usr/sbin/env-update" ${noldconfig:+--no-ldconfig} ;;
pkgcore) pmaint env-update ${noldconfig:+--skip-ldconfig} ;;
paludis) return 127 ;;
esac
}
DESCRIPTION="Read Gentoo (\"GLEP 42\") news items"
MAINTAINER="ulm@gentoo.org"
NEWS_DIR="/var/lib/gentoo/news"
# read list of news items
# list of parameters may contain "unread" or "read"
# returns one item per line: status/repository/name
# sort order: by item name (i.e. effectively by date)
find_items() {
local stat repos=$(get_repositories) repo file item
for stat in "$@"; do
for repo in ${repos}; do
file="${EROOT}${NEWS_DIR}/news-${repo}.${stat}"
[[ -f ${file} ]] || continue
for item in $(<"${file}"); do
echo "${stat}/${repo}/${item}"
done
done
done | sort -t / -k 3
}
# write list of items to file
# first parameter is "unread" or "read"
# second parameter is the repository
# list of items is expected in global array "items"
write_item_list() {
local stat=$1 repo=$2 file item update
for item in "${items[@]}"; do
[[ ${item%%/*} = "${stat}" ]] || continue
item=${item#*/}
[[ ${item%%/*} = "${repo}" ]] && update="${update} ${item#*/}"
done
file="${EROOT}${NEWS_DIR}/news-${repo}.${stat}"
for item in ${update}; do
echo "${item}"
done >"${file}"
if [[ $? -ne 0 ]]; then
write_error_msg \
"Cannot update list of news items for repository \"${repo}\""
return 1
fi
# GLEP 42 says the file should be in the portage group and group writable
chgrp portage "${file}" 2>/dev/null && chmod 664 "${file}" 2>/dev/null
return 0
}
# read a given item
# first parameter is the directory
# second parameter is the item's name
# optional third parameter may be "header", "body", or "existsp"
read_item() {
local dir=$1 item=$2 what=$3 file lang command=""
for lang in $(accepted_languages); do
file="${dir}/${item}/${item}.${lang}.txt"
[[ -f "${file}" ]] || continue
case "${what}" in
header) command="/^$/Q" ;;
body) command="0,/^$/d" ;;
existsp) return 0 ;;
esac
sed -e "${command}" "${file}" || die "Error reading ${file}"
return
done
return 1
}
# find directory for a given repository (and cache it)
# affects variable "dir" and arrays "repos" and "dirs" by side effect
find_repo_dir() {
local repo=$1 i
for (( i = 0; i < ${#repos[@]}; i++ )); do
[[ ${repos[i]} = "${repo}" ]] && break
done
if [[ ${i} -eq ${#repos[@]} ]]; then
repos[i]=${repo}
dirs[i]=$(get_repo_news_dir "${repo}")
fi
dir=${dirs[i]}
}
# return list of accepted languages
accepted_languages() {
local lc=${LC_ALL:-${LANG}}
lc=${lc%%[^[:alpha:]]*}
[[ -n ${lc} && ${lc} != en ]] && echo ${lc}
echo en
}
# calculate day of week for given year ($1), month ($2), and day ($3)
# using Chr. Zeller's formula for the new calendar
day_of_week() {
local a=${1##*(0)} m=${2##*(0)} q=${3##*(0)}
local -a wd=( Sat Sun Mon Tue Wed Thu Fri )
[[ ${m} -le 2 ]] && (( a--, m += 12 ))
echo ${wd[(q + (m+1)*13/5 + a + a/4 - a/100 + a/400) % 7]}
}
# encode header as quoted-printable
rfc2047_encode() {
local s=$1 i c LC_ALL=C
echo -n "=?UTF-8?Q?"
for (( i=0; i<${#s}; i++ )); do
c=${s:i:1}
if [[ ${c} =~ [-A-Za-z0-9!*+/] ]]; then
echo -n "${c}"
elif [[ ${c} = ' ' ]]; then
echo -n '_'
else
printf '=%02X' "'${c}"
fi
done
echo "?="
}
# output message header in e-mail/mbox format
mail_header() {
local item=$1 author=$2 title=$3 posted=$4
local -a mname=( 0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
local year=0001 month=01 day=01 time="00:00:00" wd addr="unknown" name
# "date -d" is not portable, therefore we do manual processing
if [[ ${posted} == +([0-9])-+([0-9])-+([0-9]) ]]; then
year=${posted%%-*}
month=${posted#*-}; month=${month%%-*}
day=${posted##*-}
fi
wd=$(day_of_week "${year}" "${month}" "${day}")
if [[ ${author} == *([^\<\>])\<+([^\<\>])\> ]]; then
# GLEP 42 says this must look like "Real Name "
name=${author%%*( )<*}
addr=${author##*<}; addr=${addr%%>*}
elif [[ ${author} == +([^\<\>]) ]]; then
addr=${author}
fi
[[ ${name} != *([[:ascii:]]) || ${name} =~ [\]\[()\<\>\",.:\;@\\] ]] \
&& name=$(rfc2047_encode "${name}")
[[ ${title} != *([[:ascii:]]) ]] && title=$(rfc2047_encode "${title}")
echo "From ${addr} ${wd} ${mname[${month##*(0)}]} ${day} ${time} ${year}"
echo "From: ${name}${name+ }<${addr}>"
#echo "Reply-To: DO NOT REPLY "
echo "Subject: ${title}"
echo "Date: ${wd}, ${day} ${mname[${month##*(0)}]} ${year} ${time} +0000"
echo "Message-Id: "
echo "MIME-Version: 1.0"
echo "Content-Type: text/plain; charset=UTF-8"
echo "Content-Transfer-Encoding: 8bit"
}
### list action
describe_list() {
echo "List news items"
}
do_list() {
local item stat repo dir header line title posted i=1
local cols=${COLUMNS:-80}
local ifs_save=${IFS-$' \t\n'}
local -a repos dirs
set -- $(find_items unread read)
write_list_start "News items:"
for item in "$@"; do
stat=${item%%/*}; item=${item#*/}
repo=${item%%/*}; item=${item#*/}
find_repo_dir "${repo}"
title="(${item} - no title)"
posted=${item:0:10}
[[ ${posted} == +([0-9])-+([0-9])-+([0-9]) ]] || posted="(no date) "
header=$(read_item "${dir}" "${item}" header) \
|| title="(${item} - removed?)"
IFS=$'\n'
for line in ${header}; do
case "${line%%:*}" in
Title) title=${line##*([^:]):*([[:space:]])} ;;
Posted) posted=${line##*([^:]):*([[:space:]])} ;;
esac
done
IFS=${ifs_save}
[[ ${repo} != gentoo ]] && title="[${repo}] ${title}"
line="${posted}$(space $((10 - ${#posted}))) ${title}"
# truncate the line if it is too long
(( 11 + ${#line} >= cols && cols >= 72 )) \
&& line="${line:0:cols-15}..."
if [[ ${stat} = unread ]]; then
write_numbered_list_entry ${i} "$(highlight "N ${line}")"
else
write_numbered_list_entry ${i} " ${line}"
fi
(( i++ ))
done
[[ $# -eq 0 ]] && ! is_output_mode brief \
&& write_kv_list_entry "(none found)" ""
}
### count action
describe_count() {
echo "Display number of news items"
}
describe_count_options() {
echo "new : Count unread news items (default)"
echo "all : Count all news items"
}
do_count() {
local status
[[ $1 = all ]] && status="unread read" || status="unread"
set -- $(find_items ${status})
echo $#
}
### read action
describe_read() {
echo "Read news items"
}
describe_read_options() {
echo "--mbox : Output in mbox format"
echo "--quiet : Suppress output, only change status"
echo "--raw : Output in raw format"
echo "new : Read unread news items (default)"
echo "all : Read all news items"
echo "item : Number of item (from 'list' action)"
}
describe_read_parameters() {
echo "- ..."
}
do_read() {
local -a items=( $(find_items unread read) ) repos dirs
local n=${#items[@]} format=cooked ifs_save=${IFS-$' \t\n'}
local item repo stat dir header line i seq repos_upd author title posted
while [[ $# -gt 0 ]]; do
case ${1##--} in
mbox) format=mbox ;;
quiet|silent) format=null ;;
raw) format=raw ;;
*) break ;;
esac
shift
done
# expand special values "new" and "all"
if [[ $# -eq 0 || $1 = new || $1 = all ]]; then
for (( i = 1; i <= n; i++ )); do
[[ $1 = all || ${items[i-1]%%/*} = unread ]] || continue
seq="${seq} ${i}"
done
set -- ${seq}
[[ $# -eq 0 && ${format} = cooked ]] && ! is_output_mode brief \
&& echo "No news is good news."
fi
for i in "$@"; do
if ! is_number "${i}" || [[ ${i} -lt 1 || ${i} -gt ${#items[@]} ]]
then
write_warning_msg "Bad item number: ${i}"
continue
fi
item=${items[--i]}
stat=${item%%/*}; item=${item#*/}
repo=${item%%/*}; item=${item#*/}
find_repo_dir "${repo}"
case ${format} in
raw)
read_item "${dir}" "${item}"
;;
cooked)
write_list_start "${item}"
header=$(read_item "${dir}" "${item}" header)
IFS=$'\n'
for line in ${header}; do
case "${line%%:*}" in
Title)
write_kv_list_entry "${line%%:*}" \
"$(highlight "${line##*([^:]):*([[:space:]])}")"
;;
Author|Translator|Posted|Revision)
write_kv_list_entry "${line%%:*}" \
"${line##*([^:]):*([[:space:]])}"
;;
esac
done
IFS=${ifs_save}
echo
read_item "${dir}" "${item}" body
;;
mbox)
if header=$(read_item "${dir}" "${item}" header); then
author=""; title=""; posted=""
IFS=$'\n'
for line in ${header}; do
case "${line%%:*}" in
Author) : ${author:=${line##*([^:]):*([[:space:]])}} ;;
Title) : ${title:=${line##*([^:]):*([[:space:]])}} ;;
Posted) : ${posted:=${line##*([^:]):*([[:space:]])}} ;;
esac
done
mail_header "${item}" "${author}" "${title}" "${posted}"
echo
for line in ${header}; do
case "${line%%:*}" in
Title|Author|Translator|Posted|Revision)
echo "${line}" ;;
esac
done
IFS=${ifs_save}
echo
read_item "${dir}" "${item}" body | sed 's/^>*From />&/;$q'
else
false
fi
;;
null)
true
;;
esac
[[ $? -ne 0 ]] \
&& write_warning_msg "News item \"${item}\" no longer exists"
[[ ${format} != null ]] && echo
[[ ${stat} = unread ]] || continue
# move from "unread" to "read"
unset items[i]
items[n++]=read/${repo}/${item}
has ${repo} ${repos_upd} || repos_upd="${repos_upd} ${repo}"
done
# update lists of read/unread items
for repo in ${repos_upd}; do
write_item_list read ${repo} && write_item_list unread ${repo}
done
}
### unread action
describe_unread() {
echo "Mark read news items as unread again"
}
describe_unread_options() {
echo "all : Mark all news items as unread"
echo "item : Number of item (from 'list' action)"
}
describe_unread_parameters() {
echo "
- ..."
}
do_unread() {
local -a items=( $(find_items unread read) )
local n=${#items[@]} item repo stat i seq repos_upd
# expand special value "all"
if [[ $1 = all ]]; then
for (( i = 1; i <= n; i++ )); do
seq="${seq} ${i}"
done
set -- ${seq}
fi
for i in "$@"; do
if ! is_number "${i}" || [[ ${i} -lt 1 || ${i} -gt ${#items[@]} ]]
then
write_warning_msg "Bad item number: ${i}"
continue
fi
item=${items[--i]}
stat=${item%%/*}; item=${item#*/}
repo=${item%%/*}; item=${item#*/}
[[ ${stat} = read ]] || continue
# move from "read" to "unread"
unset items[i]
items[n++]=unread/${repo}/${item}
has ${repo} ${repos_upd} || repos_upd="${repos_upd} ${repo}"
done
# update lists of unread/read items
for repo in ${repos_upd}; do
write_item_list unread ${repo} && write_item_list read ${repo}
done
}
### purge action
describe_purge() {
echo "Purge read news"
}
do_purge() {
local -a items=( $(find_items read) )
local item i repos
# find repos with nonempty lists
for (( i = 0; i < ${#items[@]}; i++ )); do
item=${items[i]#*/}
has "${item%%/*}" ${repos} || repos="${repos} ${item%%/*}"
done
# purge list of read items
items=()
for repo in ${repos}; do
write_item_list read ${repo}
done
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
news apply_text_highlights "${right}" "${val}"
Read Gentoo ("GLEP 42") news items
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# DOCUMENTATION
# Following actions possible
# * show do_show()
# * list do_list()
# * set do_set()
#
# Behaviour:
# do_show(): show current target of nzmath sandbox
# do_list(): List all available nzmath sandbox
# do_set(): Set a repo to be target of the symlink.
DESCRIPTION="Manage nzmath sandboxes"
MAINTAINER="tetsushi@tnt.math.metro-u.ac.jp"
VERSION="1"
find_targets() {
# Return the list of available nzmath
local j
for j in "${ROOT}"/Users/tetsushi/Programs/nzmath/* ; do
[[ ! -L "${j}" && -d "${j}/.hg" ]] && basename ${j}
done
}
remove_symlinks() {
# Remove existing symlinks to the current sandbox
local f
rm -f "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox"
}
set_symlinks() {
# Set symlink
local target="${1}" targets
# target may be specified by its name or its index
if is_number "${target}"; then
# numeric index, find the target's name
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: ${1}"
target=${targets[$(( ${target} - 1 ))]}
fi
# set symlink only if target directory actually exists
if [[ -d "${ROOT}/Users/tetsushi/Programs/nzmath/${target}" ]]; then
echo "Switching nzmath sandbox to ${target} ...";
remove_symlinks || die -q "Couldn't remove existing symlink";
ln -s "${target}" "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox" ||\
die "Couldn't set ${target} ${ROOT}/Users/tetsushi/Programs/nzmath/sandbox symlink"
fi
return 0
}
### show action ###
describe_show() {
echo "Show the current target of the nzmath sandbox symlink"
}
do_show() {
[[ ${#@} -gt 0 ]] && die -q "Too many parameters"
write_list_start "Current target of nzmath sandbox symlink:"
if [[ -L "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox" && \
-e $(canonicalise "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox") ]]; then
write_kv_list_entry \
$(basename $(canonicalise "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox") ) ""
elif [[ -e "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox" ]]; then
write_kv_list_entry \
"(not a symlink or target of symlink does not exist)" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available nzmath sandbox symlink targets"
}
do_list() {
[[ ${#@} -gt 0 ]] && die -q "Too many parameters"
local i targets
targets=( $(find_targets) )
if [[ -n ${targets[@]} ]]; then
for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
# Display a star to indicate the currently chosen version
[[ ${targets[${i}]} = \
$(basename $(canonicalise "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox") ) ]] \
&& targets[${i}]="${targets[${i}]} $(highlight '*')"
done
write_list_start "Available nzmath sandbox symlink targets:"
write_numbered_list "${targets[@]}"
else
write_kv_list_entry "(none found)" ""
fi
}
### set action ###
describe_set() {
echo "Set a new nzmath sandbox symlink"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z "${1}" ]] && die -q "You didn't tell me what to set the symlink to"
[[ ${#@} -gt 1 ]] && die -q "Too many parameters"
if [[ -e "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox" && ! -L "${ROOT}/Users/tetsushi/Programs/nzmath/sandbox" ]]; then
die -q "Sorry, ${ROOT}/Users/tetsushi/Programs/nzmath/sandbox exists but is not a symlink"
fi
set_symlinks "${1}" || die -q "Couldn't set a new symlink"
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
nzmath apply_text_highlights "${right}" "${val}"
Manage nzmath sandboxes
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2009-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
EDITOR_VAR="PAGER"
EDITOR_ENVFILE="/etc/env.d/99pager"
EDITOR_LIST="/bin/more /usr/bin/less /usr/bin/most"
inherit editor-variable
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# This library is for managing environment variables like EDITOR or PAGER.
# To use it, you must set the following variables:
#
# EDITOR_VAR is the name of the environment variable, e.g. "EDITOR".
# EDITOR_ENVFILE is the path to the config file where the variable should be
# stored, e.g. "/etc/env.d/99editor". Several modules may share the same file.
# EDITOR_LIST is a space-separated list of available programs (full pathnames)
# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi". Alternatively, items can be of
# the form "name:/path/to/binary".
# EDITOR_PATH (optional) is a colon-separated list of directories where to
# search for available programs. Default is "/bin:/usr/bin".
inherit config
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
# find a list of valid targets
find_targets() {
local cur i
for i in ${EDITOR_LIST}; do
[[ -f ${EROOT}${i#*:} ]] && echo "${EPREFIX}${i%%:*}"
done
# also output the current value if it isn't in our list
cur=$(read_env_value)
[[ -n ${cur} && ${EDITOR_LIST} != *:* && -f ${ROOT}${cur} ]] \
&& ! has "${cur#${EPREFIX}}" ${EDITOR_LIST} \
&& echo "${cur}"
}
# read variable value from config file
read_env_value() {
load_config "${EROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}"
}
# write variable to config file
write_env_value() {
[[ -w ${EROOT}${EDITOR_ENVFILE%/*} ]] \
|| die -q "You need root privileges!"
store_config "${EROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}" "$1"
}
### show action ###
describe_show() {
echo "Show value of the ${EDITOR_VAR} variable in profile"
}
do_show() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur=$(read_env_value)
write_list_start "${EDITOR_VAR} variable in profile:"
write_kv_list_entry "${cur:-(none)}"
}
### list action ###
describe_list() {
echo "List available targets for the ${EDITOR_VAR} variable"
}
do_list() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur targets i
cur=$(read_env_value)
targets=( $(find_targets) )
write_list_start "Available targets for the ${EDITOR_VAR} variable:"
for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
targets[i]=${targets[i]%%:*}
# display a star to indicate the currently chosen version
[[ ${targets[i]} = "${cur}" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list "${targets[@]}"
if is_output_mode brief; then
:
elif [[ ${EDITOR_LIST} != *:* ]]; then
write_numbered_list_entry " " "(free form)"
elif [[ ${#targets[@]} -eq 0 ]]; then
write_kv_list_entry "(none found)" ""
fi
}
### set action ###
describe_set() {
echo "Set the ${EDITOR_VAR} variable in profile"
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
echo ""
}
do_set() {
[[ -z $1 ]] && die -q "You didn't tell me what to set the variable to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
local target=$1 targets=() dir ifs_save=${IFS-$' \t\n'}
# target may be specified by its name or its index
if is_number "${target}"; then
targets=( $(find_targets) )
[[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
|| die -q "Number out of range: $1"
target=${targets[target-1]%%:*}
fi
if [[ ${EDITOR_LIST} != *:* ]]; then
# is the target an absolute path? if not, try to find it
if [[ ${target} != /* ]]; then
IFS=:
for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
[[ -f ${EROOT}${dir}/${target} ]] || continue
target=${EPREFIX}${dir}/${target}
break
done
IFS=${ifs_save}
fi
# target is valid if it's a path to an existing binary
[[ ${target} == /* && -f ${ROOT}${target} ]] \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
else
# target is valid only if it's in our list
[[ ${#targets[@]} -gt 0 ]] || targets=( $(find_targets) )
has "${target}" "${targets[@]%%:*}" \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
fi
echo "Setting ${EDITOR_VAR} to ${target} ..."
write_env_value "${target}"
# update profile
do_action env update noldconfig
[[ ${ROOT:-/} = / ]] && echo \
"Run \". ${EROOT}/etc/profile\" to update the variable in your shell."
}
### update action ###
describe_update() {
echo "Update the ${EDITOR_VAR} variable if it is unset or invalid"
}
do_update() {
[[ $# -gt 0 ]] && die -q "Too many parameters"
local cur targets
cur=$(read_env_value)
[[ ${EDITOR_LIST} != *:* && ${cur} == /* && -f ${ROOT}${cur} ]] && return
targets=( $(find_targets) )
[[ ${#targets[@]} -gt 0 ]] \
|| die -q "No valid target for ${EDITOR_VAR} found"
has "${cur}" "${targets[@]%%:*}" && return
echo "Setting ${EDITOR_VAR} to ${targets[0]%%:*} ..."
write_env_value "${targets[0]%%:*}"
do_action env update noldconfig
}
DESCRIPTION="Manage the ${EDITOR_VAR} environment variable"
MAINTAINER="ulm@gentoo.org"
echo "${!key}"
apply_text_highlights "${left}" "${key}"
pager apply_text_highlights "${right}" "${val}"
Manage the PAGER environment variable
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: pinentry.eselect-0.4,v 1.4 2013/01/15 20:59:38 ssuominen Exp $
DESCRIPTION="Manage /usr/bin/pinentry implementation"
MAINTAINER="ssuominen@gentoo.org"
VERSION="0.4"
SYMLINK_PATH=/usr/bin/pinentry
SYMLINK_TARGETS=( pinentry-qt pinentry-gtk-2 pinentry-qt4 pinentry-curses )
SYMLINK_DESCRIPTION='pinentry binary'
inherit bin-symlink
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# This library is for managing a common binary symlink like /bin/sh
# or /usr/bin/pinentry. To use it, you need to set the following
# variables:
#
# SYMLINK_PATH is the name of symlink being created, e.g. "/bin/sh".
# The path should be absolute, without EPREFIX (it will be added).
#
# SYMLINK_TARGETS is the list (bash array) of targets being available.
# The paths should be relative to ${SYMLINK_PATH}. Only basenames
# of the targets will be displayed to user. Best (preferred) targets
# should go earlier on the list.
#
# SYMLINK_DESCRIPTION is the human-friendly name of the symlink, e.g.
# "POSIX shell". It will be used in the context of "implementation"
# or "symlink". Defaults to basename of ${SYMLINK_PATH}.
#
# SYMLINK_CRUCIAL should be set to a non-null value if existence of no
# targets should trigger a fatal error rather than silent symlink
# removal.
# Version: 0.1.1
# Maintainer: mgorny@gentoo.org
# Based on the work of:
# - Erik Hahn; bug #214817
# - Samuli Suominen ; eselect-pinentry
## Global variables ##
if [[ ! ${SYMLINK_PATH} ]]; then
die "SYMLINK_PATH needs to be set by eselect module."
fi
if [[ ! ${SYMLINK_TARGETS[@]} ]]; then
die "SYMLINK_TARGETS need to be set by eselect module."
fi
: ${SYMLINK_DESCRIPTION:-${SYMLINK_PATH##*/}}
## Functions ##
# find a list of symlink targets, best first
find_targets() {
local basedir=${SYMLINK_PATH%/*}
TARGETS=()
local t
for t in "${SYMLINK_TARGETS[@]}"; do
if [[ -x ${EROOT}${basedir}/${t} ]]; then
TARGETS+=( ${t} )
fi
done
}
# set the pinentry symlink
set_symlinks() {
local target="${1}" targets
local basedir=${SYMLINK_PATH%/*}
[[ ! -L ${EROOT}${SYMLINK_PATH} && -e ${EROOT}${SYMLINK_PATH} ]] && \
die -q "${EROOT}${SYMLINK_PATH} is not a symlink!"
if is_number "${target}" && [[ ${target} -ge 1 ]]; then
local TARGETS
find_targets
target=${TARGETS[target-1]}
elif [[ ! -x ${EROOT}${basedir}/${target} ]]; then
# try basename matching
local TARGETS t
find_targets
for t in "${TARGETS[@]}"; do
if [[ ${t##*/} == ${target} ]]; then
target=${t}
break
fi
done
fi
if [[ -x ${EROOT}${basedir}/${target} ]]; then
local tmpf=${EROOT}${SYMLINK_PATH}.new
# we could use 'ln -f' to directly replace the symlink
# but 'mv' is an atomic operation so it should be more fault-proof
ln -s "${target}" "${tmpf}" || \
die -q "Unable to create temporary symlink"
if ! mv "${tmpf}" "${EROOT}${SYMLINK_PATH}"; then
rm -f "${tmpf}" # cleanup
die -q "Unable to replace ${EROOT}${SYMLINK_PATH} symlink with ${target}"
fi
else
die -q "Target '${target}' doesn't appear to be valid!"
fi
}
### show action ###
describe_show() {
echo "Show the current ${SYMLINK_DESCRIPTION} implementation"
}
do_show() {
[[ ${@} ]] && die -q "Too many parameters"
write_list_start "Current ${SYMLINK_DESCRIPTION} implementation:"
if [[ -L ${EROOT}${SYMLINK_PATH} ]]; then
local t=$(readlink "${EROOT}${SYMLINK_PATH}")
write_kv_list_entry "${t##*/}" ""
elif [[ -e ${EROOT}${SYMLINK_PATH} ]]; then
write_kv_list_entry "(not a symlink)" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available ${SYMLINK_DESCRIPTION} implementations"
}
do_list() {
[[ ${@} ]] && die -q "Too many parameters"
local i TARGETS
find_targets
write_list_start "Available ${SYMLINK_DESCRIPTION} implementations:"
if [[ ${TARGETS[@]} ]]; then
local curr=$(readlink "${EROOT}${SYMLINK_PATH}")
for (( i = 0; i < ${#TARGETS[@]}; i++ )) ; do
[[ ${TARGETS[${i}]##*/} == ${curr##*/} ]] && \
TARGETS[${i}]+=" $(highlight '*')"
done
write_numbered_list "${TARGETS[@]##*/}"
else
write_kv_list_entry "(none found)" ""
fi
}
### set action ###
describe_set() {
echo "Set a new ${SYMLINK_DESCRIPTION} implementation"
}
describe_set_options() {
echo "target : Target name, number (from 'list' action) or path"
}
describe_set_parameters() {
echo ""
}
do_set() {
if [[ ${#} != 1 ]]; then
die -q "set takes exactly one parameter"
else
set_symlinks "${1}"
fi
}
### update action ###
describe_update() {
echo "Automatically update the ${SYMLINK_DESCRIPTION} implementation"
}
describe_update_options() {
echo "--if-unset : do not override existing implementation"
}
do_update() {
[[ ${1} == ifunset ]] && set -- --if-unset "${@:2}"
if [[ ( ${1} && ${1} != '--if-unset' ) || ${2} ]]
then
die -q "usage error"
fi
if [[ ${1} == '--if-unset' && -L ${EROOT}${SYMLINK_PATH} \
&& -x ${EROOT}${SYMLINK_PATH} ]]
then
return
fi
local TARGETS
find_targets
if [[ ! ${TARGETS[@]} ]]; then
if [[ ${SYMLINK_CRUCIAL} ]]; then
die "No targets for ${EROOT}${SYMLINK_PATH}, system likely broken."
else
rm -f "${EROOT}${SYMLINK_PATH}"
fi
else
set_symlinks "${TARGETS[0]}"
fi
}
# vim:ts=4:sts=4:sw=4
echo "${!key}"
apply_text_highlights "${left}" "${key}"
pinentry apply_text_highlights "${right}" "${val}"
Manage /usr/bin/pinentry implementation
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
# This is a portage-only module.
inherit package-manager
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# package_manager PRIVATE
# Return the package manager we're going to use.
package_manager() {
local pm
case ${PACKAGE_MANAGER} in
portage) pm=portage ;;
pkgcore) pm=pkgcore ;;
paludis) pm=paludis ;;
esac
echo "${pm:-portage}"
}
# portageq
# Run portageq with safe filename as set by configure. Redirect stderr
portageq() {
/Users/tetsushi/Gentoo/usr/bin/portageq "$@" 2>/dev/null
}
# run_paludis PRIVATE
# Run CAVE (defaults to "cave"). Redirect stderr
run_paludis() {
${CAVE:-cave} "$@" 2>/dev/null
}
# arch
# Return the architecture we're running on...
arch() {
local ret=$(envvar sys-devel/gcc ARCH)
if [[ -n ${EPREFIX} && -n ${ret} && ${ret%-*} = "${ret}" ]]; then
# prefix/linux profiles lie about their ARCH
case $(envvar sys-devel/gcc KERNEL) in
linux) ret+="-linux" ;;
*)
write_warning_msg \
"Failed to determine \${ARCH}." \
"Please submit a bug report."
return 1
;;
esac
fi
# $arch will be null if there's no current make.profile symlink.
# We cannot get a list of valid profiles without it.
if [[ -z ${ret} ]]; then
if [[ -n ${ROOT} && ${ROOT} != "/" ]]; then
write_warning_msg \
"Failed to determine \${ARCH}." \
"Is your make.profile symlink valid?"
return 1
fi
# Try to determine arch from HOSTTYPE and OSTYPE, which are
# derived from the GNU triplet (at build time of bash)
case ${HOSTTYPE} in
alpha*) ret=alpha ;;
arm*) ret=arm ;;
hppa*) ret=hppa ;;
i?86) ret=x86 ;;
ia64) ret=ia64 ;;
m68k) ret=m68k ;;
mips*) ret=mips ;;
powerpc) ret=ppc ;;
powerpc64) ret=ppc64 ;;
s390*) ret=s390 ;;
sh*) ret=sh ;;
sparc) ret=sparc ;;
sparc64) ret=sparc64 ;;
x86_64) ret=amd64 ;;
*)
write_warning_msg \
"Unknown architecture \"${HOSTTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
if [[ -z ${EPREFIX} ]]; then
case ${OSTYPE} in
linux*) ;;
dragonfly*) ret+="-dfly" ;;
freebsd*) ret+="-fbsd" ;;
netbsd*) ret+="-nbsd" ;;
openbsd*) ret+="-obsd" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
else
# Prefix architectures
if [[ ${ret} = amd64 && ${OSTYPE} != linux* ]]; then
# amd64 is sometimes called x64 on Prefix
ret=x64
fi
case ${OSTYPE} in
aix*) ret+="-aix" ;;
cygwin*) ret+="-cygwin" ;;
darwin*) ret+="-macos" ;;
freebsd*) ret+="-freebsd" ;;
hpux*) ret+="-hpux" ;;
interix*) ret+="-interix" ;;
linux*) ret+="-linux" ;;
mint*) ret+="-mint" ;;
netbsd*) ret+="-netbsd" ;;
openbsd*) ret+="-openbsd" ;;
solaris*) ret+="-solaris" ;;
winnt*) ret+="-winnt" ;;
*)
write_warning_msg \
"Unknown OS \"${OSTYPE}\"." \
"Please submit a bug report."
return 1
;;
esac
fi
fi
echo "${ret}"
}
# envvar
# Return the contents of environment variable $2 as seen by package manager
# for package $1.
envvar() {
[[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
case $(package_manager) in
# portage does not support per-package envvar lookup
portage) portageq envvar "$2" ;;
pkgcore) pinspect portageq envvar "$2" ;;
paludis) run_paludis print-id-environment-variable --best \
--variable-name "$2" --format '%v\n' "$1" ;;
esac
}
# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
[[ $# -eq 1 ]] || die "best_version expects exactly one argument"
case $(package_manager) in
portage) portageq best_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq best_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis print-best-version --format name-version "$1" ;;
esac
}
# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
[[ $# -eq 1 ]] || die "has_version expects exactly one argument"
case $(package_manager) in
portage) portageq has_version "${EROOT:-/}" "$1" ;;
pkgcore) pinspect portageq has_version "${ROOT:-/}" "$1" ;;
paludis) run_paludis has-version "$1" ;;
esac
}
# get_repositories
# return list of repositories known to the package manager
get_repositories() {
case $(package_manager) in
portage) portageq get_repos "${EROOT:-/}" ;;
pkgcore) pinspect portageq get_repositories ;;
paludis) run_paludis print-repositories ;;
esac
}
# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
[[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
local repo=$1
case $(package_manager) in
portage) echo "$(portageq get_repo_path \
"${EROOT:-/}" "${repo}")/metadata/news" ;;
pkgcore) pinspect portageq get_repo_news_path "${repo}" ;;
paludis) run_paludis print-repository-metadata ${repo} \
--raw-name newsdir --format '%v\n' ;;
esac
}
# env_update
# Run env-update command, if available with the package manager
# If $1 is non-zero: also run ldconfig to update /etc/ld.so.cache
env_update() {
local noldconfig
[[ $1 -ne 0 ]] || noldconfig=y
case $(package_manager) in
portage) "/Users/tetsushi/Gentoo/usr/sbin/env-update" ${noldconfig:+--no-ldconfig} ;;
pkgcore) pmaint env-update ${noldconfig:+--skip-ldconfig} ;;
paludis) return 127 ;;
esac
}
DESCRIPTION="Manage the make.profile symlink"
MAINTAINER="eselect@gentoo.org"
DEFAULT_REPO="gentoo"
# get location of make.profile symlink
get_symlink_location() {
local root=${PORTAGE_CONFIGROOT-${EROOT}}
local oldloc=${root%/}/etc/make.profile
local newloc=${root%/}/etc/portage/make.profile
MAKE_PROFILE=${newloc}
if [[ -e ${oldloc} ]]; then
if [[ -e ${newloc} ]]; then
write_warning_msg "Both ${oldloc} and ${newloc} exist."
write_warning_msg "Using ${MAKE_PROFILE}."
else
MAKE_PROFILE=${oldloc}
fi
fi
}
# get list of repositories
get_repos() {
# sort: DEFAULT_REPO first, then alphabetical order
portageq get_repos "${EROOT:-/}" \
| sed "s/[[:space:]]\+/\n/g;s/^${DEFAULT_REPO}\$/ &/gm" \
| LC_ALL=C sort
[[ -z ${PIPESTATUS[@]#0} ]]
}
# get paths for a given list of repositories
get_repo_path() {
portageq get_repo_path "${EROOT:-/}" "$@"
}
# get a list of valid profiles
# returns a line :::: for every profile
find_targets() {
local arch desc repos repo_paths i p
arch=$(arch)
[[ -z ${arch} ]] && die -q "Cannot determine architecture"
repos=( $(get_repos) ) || die -q "get_repos failed"
repo_paths=( $(get_repo_path "${repos[@]}") ) \
|| die -q "get_repo_path failed"
[[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
&& die -q "Cannot get list of repositories"
for (( i = 0; i < ${#repos[@]}; i++ )); do
desc=${repo_paths[i]}/profiles/profiles.desc
[[ -r ${desc} ]] || continue
# parse profiles.desc and find profiles suitable for arch
for p in $(sed -n -e \
"s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" "${desc}")
do
echo "${repos[i]}::${repo_paths[i]}::${p}"
done
done
}
# remove make.profile symlink
remove_symlink() {
rm "${MAKE_PROFILE}"
}
# set the make.profile symlink
set_symlink() {
local target=$1 force=$2 targets arch parch repo repopath
if is_number "${target}"; then
targets=( $(find_targets) )
[[ ${#targets[@]} -eq 0 ]] \
&& die -q "Failed to get a list of valid profiles"
target=${targets[target-1]}
repo=${target%%::*}; target=${target#*::}
repopath=${target%%::*}; target=${target#*::}
elif [[ -n ${target} ]]; then
# if the profile was explicitly specified (rather than a number)
# double check and make sure it's valid
arch=$(arch)
[[ -z ${arch} && -z ${force} ]] \
&& die -q "Cannot determine architecture"
repo=${target%%:*}
# assume default repo if not explicitly specified
[[ ${repo} == "${target}" || -z ${repo} ]] && repo=${DEFAULT_REPO}
target=${target#*:}
repopath=$(get_repo_path "${repo}") || die -q "get_repo_path failed"
# do a reverse lookup and find the arch associated with ${target}
parch=$(sed -n -e \
"s|^\([[:alnum:]_-]\+\)[[:space:]].*${target}[[:space:]].*$|\1|p" \
"${repopath}/profiles/profiles.desc")
[[ ${arch} != "${parch}" && -z ${force} ]] \
&& die -q "${target} is not a valid profile for ${arch}"
fi
[[ -z ${target} || -z ${repopath} ]] \
&& die -q "Target \"$1\" doesn't appear to be valid!"
[[ ! -d ${repopath}/profiles/${target} ]] \
&& die -q "No profile directory for target \"${target}\""
# we must call remove_symlink() here instead of calling it from
# do_set(), since if the link is removed, we cannot reliably
# determine ${arch} in find_targets()
if [[ -L ${MAKE_PROFILE} ]]; then
remove_symlink \
|| die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
fi
# set relative symlink
ln -s "$(relative_name \
"${repopath}" "${MAKE_PROFILE%/*}")/profiles/${target}" \
"${MAKE_PROFILE}" \
|| die -q "Couldn't set new ${MAKE_PROFILE} symlink"
# check if the resulting symlink is sane
[[ $(canonicalise "${MAKE_PROFILE}") != "$(canonicalise "${EROOT}")"/* ]] \
&& write_warning_msg "Strange path. Check ${MAKE_PROFILE} symlink"
return 0
}
### show action ###
describe_show() {
echo "Show the current make.profile symlink"
}
do_show() {
local link repos repo_paths dir i
get_symlink_location
write_list_start "Current ${MAKE_PROFILE} symlink:"
if [[ -L ${MAKE_PROFILE} ]]; then
link=$(canonicalise "${MAKE_PROFILE}")
repos=( $(get_repos) ) || die -q "get_repos failed"
repo_paths=( $(get_repo_path "${repos[@]}") ) \
|| die -q "get_repo_path failed"
[[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
&& die -q "Cannot get list of repositories"
# Unfortunately, it's not obvious where to split a given path
# in repository directory and profile. So loop over all
# repositories and compare the canonicalised paths.
for (( i = 0; i < ${#repos[@]}; i++ )); do
dir=$(canonicalise "${repo_paths[i]}/profiles")
if [[ ${link} == "${dir}"/* ]]; then
link=${link##"${dir}/"}
[[ ${repos[i]} != "${DEFAULT_REPO}" ]] \
&& link=${repos[i]}:${link}
break
fi
done
write_kv_list_entry "${link}" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available profile symlink targets"
}
do_list() {
local targets active i target repo repopath
targets=( $(find_targets) )
[[ ${#targets[@]} -eq 0 ]] \
&& die -q "Failed to get a list of valid profiles"
get_symlink_location
active=$(canonicalise "${MAKE_PROFILE}")
for (( i = 0; i < ${#targets[@]}; i++ )); do
target=${targets[i]}
repo=${target%%::*}; target=${target#*::}
repopath=${target%%::*}; target=${target#*::}
if [[ ${repo} == "${DEFAULT_REPO}" ]]; then
targets[i]=${target}
else
targets[i]=${repo}:${target}
fi
[[ $(canonicalise "${repopath}/profiles/${target}") == "${active}" ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_list_start "Available profile symlink targets:"
write_numbered_list "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set a new profile symlink target"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
echo "--force : Forcibly set the symlink"
}
do_set() {
local force
if [[ $1 == "--force" ]]; then
force=1
shift
fi
[[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
[[ $# -gt 1 ]] && die -q "Too many parameters"
get_symlink_location
if [[ -e ${MAKE_PROFILE} ]] && [[ ! -L ${MAKE_PROFILE} ]]; then
die -q "${MAKE_PROFILE} exists but is not a symlink"
else
set_symlink "$1" ${force} || die -q "Couldn't set a new symlink"
fi
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
profile apply_text_highlights "${right}" "${val}"
Manage the make.profile symlink
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: $
DESCRIPTION="Manage Python symlinks"
MAINTAINER="python@gentoo.org"
SVN_DATE='$Date: 2010-08-02 12:23:53 -0400 (Mon, 02 Aug 2010) $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
svn_date_to_version "${SVN_DATE}"
ENV_D_PATH="${EROOT%/}/etc/env.d"
INTERPRETER_PATH="${EROOT%/}/usr/bin/"
MAN_PATH="${EROOT%/}/usr/share/man/man1/"
PYTHON_INTERPRETERS_GROUP=""
# Find a list of Python versions
find_targets() {
local interpreter interpreters="python?.?"
if [[ "${PYTHON_INTERPRETERS_GROUP}" == "2" ]]; then
interpreters="python2.?"
elif [[ "${PYTHON_INTERPRETERS_GROUP}" == "3" ]]; then
interpreters="python3.?"
fi
# Think twice before adding jython to this list. /usr/bin/jython
# is a bash wrapper that calls java-config, which is a Python
# script, so you need a valid /usr/bin/python to start jython.
for interpreter in "${INTERPRETER_PATH}"${interpreters}; do
if [[ -f "${interpreter}" ]]; then
echo ${interpreter#${INTERPRETER_PATH}}
fi
done
}
set_python() {
local symlink="${INTERPRETER_PATH}python" target="${1}"
ln -s python-wrapper "${symlink}"
echo "${target}" > "${ENV_D_PATH}/python/config"
}
set_python_config() {
local script="${INTERPRETER_PATH}python-config" target="${1}"
cat << EOF > "${script}"
#!/usr/bin/env bash
# Gentoo python-config wrapper script
[[ "\${EPYTHON}" =~ (/|^python\$) ]] && EPYTHON="${target/-config-/}"
python_config="\${EPYTHON/python/python-config-}"
"\${0%/*}/\${python_config:-${target}}" "\$@"
EOF
chmod a+rx "${script}"
}
# Try to remove python and python.1 symlinks
remove_symlinks() {
local symlink symlink_target symlink_target_found
if [[ "${SET_MAIN_ACTIVE_PYTHON_INTERPRETER}" == "1" ]]; then
rm -f "${INTERPRETER_PATH}"{idle,pydoc,python,python-config,pythonw} &> /dev/null || return 1
rm -f "${MAN_PATH}"python.1{,.gz,.bz2,.lzma,.xz} &> /dev/null || return 1
fi
for symlink in "${INTERPRETER_PATH}python"?; do
[[ ! -L "${symlink}" ]] && continue
symlink_target_found=0
for symlink_target in "${symlink}".?; do
[[ -f "${symlink_target}" ]] && symlink_target_found=1
done
if [[ "${symlink_target_found}" -eq 0 ]]; then
rm -f "${symlink}"
fi
done
# Files of Mac OS X framework
rm -f "${INTERPRETER_PATH%/bin/}/lib/Python.framework}"/{Headers,Python,Resources}
}
# Set a man page symlink
set_man_symlink() {
local target="${1}" x extension
for x in ".1" ".1.bz2" ".1.gz" ".1.lzma" ".1.xz"; do
if [[ -e "${MAN_PATH}${target}${x}" ]]; then
extension="${x}"
break
fi
done
if [[ -z "${extension}" ]]; then
echo "Couldn't find a man page for ${target}; skipping." 1>&2
return 1
fi
pushd "${MAN_PATH}" 1> /dev/null
ln -nfs "${target}${extension}" "python${extension}"
popd 1> /dev/null
}
# Set python-config script and appropriate symlinks
set_scripts_and_symlinks() {
local target="${1}" targets=($(find_targets))
if is_number "${target}" && [[ ${target} -ge 1 ]]; then
target=${targets[$((${target} - 1))]}
fi
if ! has ${target} "${targets[@]}"; then
die -q "Invalid target ${target}"
fi
if [[ -f "${INTERPRETER_PATH}${target}" ]]; then
if ! remove_symlinks; then
die -q "Cannot remove symlinks"
fi
if [[ "${SET_MAIN_ACTIVE_PYTHON_INTERPRETER}" == "1" ]]; then
set_man_symlink "${target}"
fi
pushd "${INTERPRETER_PATH}" 1> /dev/null
ln -nfs "${target}" "${target%.*}"
if [[ "${SET_MAIN_ACTIVE_PYTHON_INTERPRETER}" == "1" ]]; then
set_python "${target}"
set_python_config "${target/python/python-config-}"
ln -nfs "${target/python/pydoc}" pydoc
# idle is optionally installed
if [[ -f "${target/python/idle}" ]]; then
ln -nfs "${target/python/idle}" idle
fi
# 2to3 for >=2.6
if [[ -f "${target/python/2to3-}" ]]; then
ln -nfs "${target/python/2to3-}" 2to3
fi
# Wrapper for graphical applications on Mac OS X
if [[ -f "${target/python/pythonw}" ]] ; then
ln -nfs "${target/python/pythonw}" pythonw
fi
# Files of Mac OS X framework
local framework_dir="${INTERPRETER_PATH%/bin/}/lib/Python.framework"
if [[ -d "${framework_dir}" ]]; then
local version="${target#python}"
pushd "${framework_dir}" 1> /dev/null
ln -nfs "Versions/${version}/Headers"
ln -nfs "Versions/${version}/Python"
ln -nfs "Versions/${version}/Resources"
popd 1> /dev/null
fi
fi
popd 1> /dev/null
else
die -q "Target \"${1}\" doesn't appear to be valid!"
fi
}
# Set the content of /etc/env.d/65python-docs
set_python_docs() {
local path target="${1#python}" variable
rm -f "${ENV_D_PATH}/65python-docs"
if [[ -f "${ENV_D_PATH}/60python-docs-${target}" ]]; then
variable="PYTHONDOCS_${target//./_}"
path="$(. "${ENV_D_PATH}/60python-docs-${target}"; echo -n "${!variable}")"
if [[ -d "${path}" ]]; then
echo "PYTHONDOCS=\"${path}\"" > "${ENV_D_PATH}/65python-docs"
fi
fi
}
### show action ###
describe_show() {
echo "Show main active Python interpreter"
}
describe_show_options() {
echo "--ABI : Show Python ABI in format of PYTHON_ABI variable"
echo "--python2 : Show active Python 2 interpreter"
echo "--python3 : Show active Python 3 interpreter"
}
do_show() {
local ABI="0" interpreter python2="0" python3="0"
while [[ $# > 0 ]]; do
case "$1" in
--ABI)
ABI="1"
;;
--python2)
python2="1"
;;
--python3)
python3="1"
;;
*)
die -q "Unrecognized argument '$1'"
;;
esac
shift
done
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
fi
if [[ "${python2}" == "1" ]]; then
interpreter="$(readlink "${INTERPRETER_PATH}python2")"
elif [[ "${python3}" == "1" ]]; then
interpreter="$(readlink "${INTERPRETER_PATH}python3")"
elif [[ -f "${ENV_D_PATH}/python/config" ]]; then
interpreter="$(<"${ENV_D_PATH}/python/config")"
fi
if [[ "${ABI}" == "1" ]]; then
echo -n "${interpreter#python}"
else
echo -n "${interpreter}"
fi
if [[ -n "${interpreter}" ]]; then
echo
fi
}
### list action ###
describe_list() {
echo "List installed Python interpreters"
}
describe_list_options() {
echo "--python2 : List installed Python 2 interpreters"
echo "--python3 : List installed Python 3 interpreters"
}
do_list() {
local active i python_descriptive_name="Python" python_version_option= python2="0" python3="0" targets=()
while [[ $# > 0 ]]; do
case "$1" in
--python2)
python2="1"
python_descriptive_name="Python 2"
python_version_option="--python2"
PYTHON_INTERPRETERS_GROUP="2"
;;
--python3)
python3="1"
python_descriptive_name="Python 3"
python_version_option="--python3"
PYTHON_INTERPRETERS_GROUP="3"
;;
*)
die -q "Unrecognized argument '$1'"
;;
esac
shift
done
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
fi
targets=($(find_targets))
write_list_start "Available ${python_descriptive_name} interpreters:"
active="$(do_show ${python_version_option})"
for ((i = 0; i < ${#targets[@]}; i++)); do
if [[ ${targets[${i}]} == ${active} ]]; then
targets[${i}]="$(highlight_marker "${targets[${i}]}")"
fi
done
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set main active Python interpreter"
}
describe_set_options() {
echo "--python2 : Set active Python 2 interpreter without setting of main active Python interpreter if it is not set to Python 2"
echo "--python3 : Set active Python 3 interpreter without setting of main active Python interpreter if it is not set to Python 3"
}
describe_set_parameters() {
echo ""
}
do_set() {
local main_active_python_interpreter python2="0" python3="0"
SET_MAIN_ACTIVE_PYTHON_INTERPRETER="1"
while [[ $# > 0 ]]; do
case "$1" in
--python2)
python2="1"
PYTHON_INTERPRETERS_GROUP="2"
;;
--python3)
python3="1"
PYTHON_INTERPRETERS_GROUP="3"
;;
*)
break
;;
esac
shift
done
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
fi
if [[ $# -lt 1 ]]; then
die -q "'eselect python set' requires Python interpreter filename"
elif [[ $# -gt 1 ]]; then
die -q "'eselect python set' requires 1 argument"
else
main_active_python_interpreter="$(do_show)"
if [[ "${python2}" == "1" && "${main_active_python_interpreter}" != "python2."* ]]; then
SET_MAIN_ACTIVE_PYTHON_INTERPRETER="0"
elif [[ "${python3}" == "1" && "${main_active_python_interpreter}" != "python3."* ]]; then
SET_MAIN_ACTIVE_PYTHON_INTERPRETER="0"
fi
if ! set_scripts_and_symlinks "${1}"; then
die -q "Can't set new provider"
fi
if [[ "${SET_MAIN_ACTIVE_PYTHON_INTERPRETER}" == "1" ]]; then
set_python_docs "${1}"
fi
fi
}
### update action ###
describe_update() {
echo "Switch to the most recent CPython interpreter"
}
describe_update_options() {
echo "--if-unset : Do not override existing implementation"
echo "--ignore SLOT : Ignore SLOT when setting symlinks"
echo "--python2 : Set active Python 2 interpreter without setting of main active Python interpreter if it is not set to Python 2"
echo "--python3 : Set active Python 3 interpreter without setting of main active Python interpreter if it is not set to Python 3"
}
do_update() {
local if_unset="0" ignored_slots=() interpreters="python?.?" python2="0" python3="0" python_version_option= slot= target targets=()
while [[ $# > 0 ]]; do
case "$1" in
--if-unset)
if_unset="1"
;;
--ignore)
ignored_slots+=("${2}")
shift;;
--python2)
python2="1"
python_version_option="--python2"
;;
--python3)
python3="1"
python_version_option="--python3"
;;
*)
die -q "Unrecognized argument '$1'"
;;
esac
shift
done
if [[ "${python2}" == "1" && "${python3}" == "1" ]]; then
die -q "'--python2' and '--python3' options cannot be specified simultaneously"
fi
if [[ "${if_unset}" == "1" && -f "${INTERPRETER_PATH}python" && -f "${ENV_D_PATH}/python/config" ]]; then
if [[ "${python2}" == "1" && -f "${INTERPRETER_PATH}python2" ]]; then
return
elif [[ "${python3}" == "1" && -f "${INTERPRETER_PATH}python3" ]]; then
return
elif [[ "${python2}" == "0" && "${python3}" == "0" ]]; then
return
fi
fi
if [[ "${python2}" == "1" ]]; then
interpreters="python2.?"
elif [[ "${python3}" == "1" ]]; then
interpreters="python3.?"
fi
targets=($(cd "${INTERPRETER_PATH}"; ls ${interpreters} 2> /dev/null | sort -r))
# Ignore slots
for slot in ${ignored_slots[@]}; do
targets=(${targets[@]/python${slot}/})
done
if [[ ${#targets[@]} -gt 0 ]]; then
target=${targets[0]}
echo "Switching to ${target}"
do_set ${python_version_option} ${target}
else
die -q "No Python interpreter available"
fi
}
# vim: set ft=eselect :
echo "${!key}"
apply_text_highlights "${left}" "${key}"
python apply_text_highlights "${right}" "${val}"
Manage Python symlinks
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2012 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
# $Id: qtgraphicssystem.eselect 859 2012-01-21 11:04:25Z wired $
DESCRIPTION="Manage the system-wide active Qt Graphics System"
MAINTAINER="qt@gentoo.org"
VERSION="1.1.1"
# this module sets the system-wide qt graphics system by creating an env file
# called 44qt4-graphicssystem that contains a QT_GRAPHICSSYSTEM variable with
# the active graphics system.
# get all the available qt graphics systems
find_targets() {
if [[ -d ${EROOT}/usr/share/qt4/graphicssystems/ ]]; then
echo $(ls ${EROOT}/usr/share/qt4/graphicssystems/)
fi
}
# get the state of one graphic system
# the state (if any) is stored in its file
get_target_state() {
cat ${EROOT}/usr/share/qt4/graphicssystems/$1
}
### show action ###
describe_show() {
echo "Show the active Qt Graphics System"
}
do_show() {
write_list_start "Active Qt Graphics System:"
# get the active graphics system by sourcing the env file
if [[ -e ${EROOT}/etc/env.d/44qt4-graphicssystem ]]; then
. ${EROOT}/etc/env.d/44qt4-graphicssystem
write_kv_list_entry "${QT_GRAPHICSSYSTEM}" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available Qt Graphics Systems"
}
do_list() {
local i targets=( $(find_targets) )
# get the active graphics system by sourcing the env file
local active=
if [[ -e ${EROOT}/etc/env.d/44qt4-graphicssystem ]]; then
. ${EROOT}/etc/env.d/44qt4-graphicssystem
active="${QT_GRAPHICSSYSTEM}"
fi
write_list_start "Available Qt Graphics Systems:"
for (( i = 0; i < ${#targets[@]}; i++ )); do
local name=${targets[i]}
local state=$(get_target_state ${targets[i]})
[[ -n ${state} ]] && targets[i]="${targets[i]} (${state})"
[[ ${name} = ${active} ]] &&
targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set the active Qt Graphics System"
}
describe_set_parameters() {
echo ""
}
describe_set_options() {
echo "target : Target name or number (from 'list' action)"
}
do_set() {
local use_old=0
[[ -z $1 ]] && die -q "You didn't tell me what Qt Graphics System to activate."
if [[ $# -eq 2 ]] && [[ $2 == "--use-old" ]]; then
use_old=1
else
[[ $# -gt 1 ]] && die -q "Too many parameters."
fi
# if --use-old and a graphics system is already set, don't do anything
if [[ -e ${EROOT}/etc/env.d/44qt4-graphicssystem ]] && (( $use_old )); then
. ${EROOT}/etc/env.d/44qt4-graphicssystem
if [[ -e ${EROOT}/usr/share/qt4/graphicssystems/${QT_GRAPHICSSYSTEM} ]]; then
echo "Qt Graphics System set to ${QT_GRAPHICSSYSTEM}."
return
fi
fi
local target=$1
if is_number "${target}"; then
local targets=( $(find_targets) )
target=${targets[target-1]}
fi
# check that the selected graphics system actually exists
if [[ -z ${target} ]] || [[ ! -e ${EROOT}/usr/share/qt4/graphicssystems/${target} ]]; then
die -q "You didn't select a valid Qt Graphics System"
fi
local state=$(get_target_state ${target})
[[ -n ${state} ]] && state=" (${state})"
echo -n "Setting ${target}${state} as your active Qt Graphics System... "
# get rid of the old setting
if [[ -e ${EROOT}/etc/env.d/44qt4-graphicssystem ]]; then
rm -f ${EROOT}/etc/env.d/44qt4-graphicssystem || die -q "Could not remove ${EROOT}/etc/env.d/44qt4-graphicssystem"
fi
# write a new env file containing QT_GRAPHICSSYSTEM
echo "QT_GRAPHICSSYSTEM=\"${target}\"" > ${EROOT}/etc/env.d/44qt4-graphicssystem ||
die -q "Could not install new ${EROOT}/etc/env.d/44qt4-graphicssystem"
do_action env update &> /dev/null
echo "done"
echo "Please logout for changes to take effect."
}
echo "${!key}"
apply_text_highlights "${left}" "${key}"
qtgraphicssystem apply_text_highlights "${right}" "${val}"
Manage the system-wide active Qt Graphics System
ESELECT_MODULE_NAME=${name} load_config "${module}" DESCRIPTION
unset ${key}
source ${configfile} 1>&2 > /dev/null || die "Failed to source ${configfile}."
# -*-eselect-*- vim: ft=eselect
# Copyright 2005-2013 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
inherit config
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2013 Gentoo Foundation
#
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see .
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
# we need at least "module" and "key"
[[ ${#@} -ge 2 ]] || die
local configfile=${1} key=${2} value content vars line="" changed=0
shift 2
value=${@}
if [[ ! -e ${configfile} ]] ; then
mkdir -p ${configfile%/*} \
|| die -q \
"Couldn't create directory ${configfile%/*}"
fi
store_config_header() {
echo "# Configuration file for eselect" \
> ${configfile}
echo "# This file has been automatically generated." \
>> ${configfile}
}
if [[ ! -f ${configfile} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
content=$(<${configfile})
if [[ -z ${content} ]] ; then
store_config_header
echo "${key}=\"${value}\"" \
>> ${configfile}
return
fi
(
# parse the names of all settings in the file
local ifs_save=${IFS-$' \t\n'}
IFS=$'\n'
for line in ${content} ; do
[[ ${line/=/} != ${line} ]] || continue
line=${line/=*/}
local ${line}=""
vars=(${vars[@]} ${line})
done
IFS=${ifs_save}
source ${configfile} 2>&1 > /dev/null \
|| die "Failed to source ${configfile}."
store_config_header
for var in ${vars[@]} ; do
if [[ ${var} == ${key} ]] ; then
echo "${var}=\"${value}\"" \
>> ${configfile}
changed=1
else
echo "${var}=\"${!var}\"" \
>> ${configfile}
fi
done
[[ ${changed} == 1 ]] \
|| echo "${key}=\"${value}\"" \
>> ${configfile}
)
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
[[ ${#@} -eq 2 ]] || die
local configfile key value
configfile=${1}
key=${2}
[[ ! -e ${configfile} ]] \
&& return 1
value=$(
unset ${key}
source ${configfile} 1>&2 > /dev/null \
|| die "Failed to source ${configfile}."
echo "${!key}"
)
echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
[[ ${#@} -gt 2 ]] || die
local configfile=${1} key=${2} item oldvalue newvalue
shift 2
item="$@"
oldvalue=$(load_config ${configfile} ${key})
if ! has ${item} ${oldvalue[@]} ; then
newvalue=( ${oldvalue[@]} ${item} )
store_config ${configfile} ${key} ${newvalue[@]}
fi
}
DESCRIPTION="Manage /etc/init.d scripts in runlevels"
MAINTAINER="eselect@gentoo.org"
# source_rc_functions PRIVATE
# API for OpenRC or baselayout-1
source_rc_functions() {
[[ ${RC_GOT_FUNCTIONS} = yes ]] && return
source "${EPREFIX}/etc/init.d/functions.sh" \
|| die "Failed to source functions.sh"
# baselayout-1 compatibility
if [[ -e ${svclib}/sh/rc-services.sh ]]; then
source "${svclib}/sh/rc-services.sh" \
|| die "Failed to source rc-services.sh"
fi
}
# get_runlevel PRIVATE
# determine the current runlevel
# this is only functional if source_rc_functions has been called before
get_runlevel() {
if type rc_runlevel &>/dev/null; then
rc_runlevel || die "rc_runlevel failed"
elif [[ -n ${SOFTLEVEL} ]]; then
echo "${SOFTLEVEL}"
else
die "Cannot determine runlevel"
fi
}
# list_runlevels PRIVATE
# list runlevels for file $1
list_runlevels() {
[[ $# -eq 1 ]] || return
local x runlevels
for x in "${EROOT}"/etc/runlevels/* ; do
[[ -d ${x} && -L ${x}/${1} ]] \
&& runlevels=(${runlevels[@]} "${x##*/}")
done
echo -ne "${runlevels[@]}"
}
# is_script PRIVATE
# check if file $1 is a valid init script
is_script() {
local file=${1}
[[ -n ${file} \
&& ${file%%.sh} = ${file} \
&& ${file%%\~} = ${file} \
&& -e ${file} ]] \
&& grep "^#\!/sbin/runscript" "${file}" &>/dev/null
}
# find_scripts PRIVATE
# browse directory $1 for init scripts and return a list
find_scripts() {
for file in ${1}/* ; do
is_script ${file} && echo "${file##*/}"
done
}
# find_unused_scripts PRIVATE
# find scripts in /etc/init.d not belonging to any runlevel
find_unused_scripts() {
local file x
for file in $(find_scripts "${EROOT}/etc/init.d"); do
for x in "${EROOT}"/etc/runlevels/*; do
[[ -d ${x} && -L ${x}/${file} ]] && continue 2
done
echo "${file##*/}"
done
}
# show_script_status PRIVATE
# output list entry for script $1 and show its status
show_script_status() {
local script=${1} status=unknown x
for x in stopping starting inactive started stopped; do
if service_${x} ${script}; then
status=${x}
break
fi
done
case ${status} in
stopped)
write_kv_list_entry ${script} [${x}]
;;
started)
write_kv_list_entry ${script} "$(highlight [${x}])"
;;
*)
write_kv_list_entry ${script} "$(highlight_warning [${x}])"
;;
esac
}
# run_runscript PRIVATE
# run RC_RUNSCRIPT with script $2- and command $1
run_runscript() {
local command=${1}
shift
for script in "$@"; do
is_script "${EROOT}/etc/init.d/${script}" \
&& /sbin/runscript "${EROOT}/etc/init.d/${script}" "${command}"
done
}
### add action
describe_add() {
echo "Add script to existing runlevel(s)"
}
describe_add_parameters() {
echo "