Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bee/src/beelib.config.sh.in
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
416 lines (353 sloc)
12.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# config-lib - bash-function-library | |
# | |
# Copyright (C) 2009-2016 | |
# Marius Tolzmann <m@rius.berlin> | |
# Tobias Dreyer <dreyer@molgen.mpg.de> | |
# and other bee developers | |
# | |
# This file is part of bee. | |
# | |
# bee 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 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
: ${BEE_BINDIR:=@BINDIR@} | |
function config_init_colors() { | |
: ${BEE_COLOR:="yes"} | |
if [ ! -t 1 ] ; then | |
BEE_COLOR="no" | |
fi | |
if [ "${BEE_COLOR}" != "no" ] ; then | |
COLOR_NORMAL="\\033[0;39m\\033[0;22m" | |
COLOR_GREEN="\\033[0;32m" | |
COLOR_YELLOW="\\033[0;33m" | |
COLOR_RED="\\033[0;31m" | |
COLOR_CYAN="\\033[0;36m" | |
COLOR_BLUE="\\033[0;34m" | |
COLOR_PURPLE="\\033[0;35m" | |
COLOR_BRACKET=${COLOR_PURPLE} | |
COLOR_BRCONTENT=${COLOR_YELLOW} | |
COLOR_INFO=${COLOR_GREEN} | |
COLOR_ERROR=${COLOR_RED} | |
COLOR_WARN=${COLOR_YELLOW} | |
else | |
COLOR_NORMAL="" | |
COLOR_GREEN="" | |
COLOR_YELLOW="" | |
COLOR_RED="" | |
COLOR_CYAN="" | |
COLOR_BLUE="" | |
COLOR_PURPLE="" | |
COLOR_BRACKET="" | |
COLOR_BRCONTENT="" | |
COLOR_INFO="" | |
COLOR_ERROR="" | |
COLOR_WARN="" | |
fi | |
} | |
function print_msg() { | |
echo >&2 -e "${COLOR_BRACKET}[${COLOR_BRCONTENT}BEE${COLOR_BRACKET}] ${@}" | |
} | |
function print_info() { | |
print_msg "${COLOR_INFO}${@}${COLOR_NORMAL}" | |
} | |
function print_error() { | |
print_msg "${COLOR_ERROR}${@}${COLOR_NORMAL}" | |
} | |
function print_warning() { | |
print_msg "${COLOR_WARN}${@}${COLOR_NORMAL}" | |
} | |
function config_init_base_config() { | |
: ${BEE_ROOT_REPOSITORY_PREFIX:=/usr/src/bee} | |
: ${BEE_XDG_DATADIR:=${BEE_DATADIR}} | |
# XDG defaults defined in xdg base spec | |
: ${XDG_CONFIG_HOME:=${HOME}/.config} | |
: ${XDG_CONFIG_DIRS:=/etc/xdg} | |
: ${XDG_DATA_HOME:=${HOME}/.local/share} | |
: ${XDG_DATA_DIRS:=/usr/local/share:/usr/share} | |
: ${XDG_CACHE_HOME:=${HOME}/.cache} | |
# always append bee special dirs to XDG search path | |
XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS}:${BEE_SYSCONFDIR}/xdg:${BEE_SYSCONFDIR} | |
XDG_DATA_DIRS=${XDG_DATA_DIRS}:${BEE_XDG_DATADIR} | |
# append bee installed defaults to config search path | |
: ${BEE_CONFIG_DIR:=${BEE_DEFCONFDIR}} | |
XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS}:${BEE_CONFIG_DIR} | |
# remove dupes from pathes | |
XDG_CONFIG_DIRS=$(${BEE_BINDIR}/beeuniq -d : ${XDG_CONFIG_DIRS//:/ }) | |
XDG_DATA_DIRS=$(${BEE_BINDIR}/beeuniq -d : ${XDG_DATA_DIRS//:/ }) | |
} | |
function deprecated_mv() { | |
local what=${1} | |
local from=${2} | |
local to=${3} | |
if [ -e "${from}" -a ! -e "${to}" ] ; then | |
print_warning "WARNING: migrating deprecated config ${what}:" | |
print_warning "WARNING: moving ${from} -> ${to}" | |
mkdir -vp "${to%/*}" | |
mv -v "${from}" "${to}" | |
fi | |
} | |
function config_handle_deprecated_config() { | |
local exit_deprecated=0 | |
if [ ! -z "${DOTBEERC}" ] ; then | |
print_error "ERROR: deprecated variable DOTBEERC is set." | |
print_error "ERROR: please use BEE_USER_CONFIG_FILE=${DOTBEERC}" | |
exit_deprecated=1 | |
fi | |
if [ ! -z "${BEE_REPOSITORY_BUILDARCHIVEDIR}" ] ; then | |
print_error "ERROR: deprecated variable BEE_REPOSITORY_BUILDARCHIVEDIR is set." | |
print_error "ERROR: please use BEE_BUILDARCHIVEDIR=${BEE_REPOSITORY_BUILDARCHIVEDIR}" | |
exit_deprecated=1 | |
fi | |
if [ ! -z "${BEE_REPOSITORY_BEEDIR}" ] ; then | |
print_error "ERROR: deprecated variable BEE_REPOSITORY_BEEDIR is set." | |
print_error "ERROR: please use BEE_BEEDIR=${BEE_REPOSITORY_BEEDIR}" | |
exit_deprecated=1 | |
fi | |
if [ ! -z "${BEE_REPOSITORY_PKGDIR}" ] ; then | |
print_error "ERROR: deprecated variable BEE_REPOSITORY_PKGDIR is set." | |
print_error "ERROR: please use BEE_PKGDIR=${BEE_REPOSITORY_PKGDIR}" | |
exit_deprecated=1 | |
fi | |
if [ ! -z "${BEE_REPOSITORY_PKGPATH}" ] ; then | |
print_error "ERROR: deprecated variable BEE_REPOSITORY_PKGPATH is set." | |
print_error "ERROR: please use BEE_PKGPATH=${BEE_REPOSITORY_PKGPATH}" | |
exit_deprecated=1 | |
fi | |
if [ ${exit_deprecated} == 1 ] ; then | |
print_error "ERROR: please fix deprecated variable errors before continuing." | |
exit 1 | |
fi | |
deprecated_mv "DOTBEERC" "${HOME}/.beerc" "${XDG_CONFIG_HOME}/bee/beerc" | |
deprecated_mv "BEE_REPOSITORY_PREFIX" "${XDG_DATA_HOME}/beeroot" "${BEE_REPOSITORY_PREFIX}" | |
deprecated_mv "BEE_METADIR" "${XDG_DATA_HOME}/beemeta" "${BEE_METADIR}" | |
deprecated_mv "BEE_BEEDIR" "${BEE_REPOSITORY_PREFIX}/bees" "${BEE_BEEDIR}" | |
deprecated_mv "BEE_PKGDIR" "${BEE_REPOSITORY_PREFIX}/pkgs" "${BEE_PKGDIR}" | |
deprecated_mv "BEE_DOWNLOADDIR" "${BEE_REPOSITORY_PREFIX}/downloads" "${BEE_DOWNLOADDIR}" | |
deprecated_mv "BEE_TMP_BUILDROOT" "${BEE_TMP_TMPDIR}/beeroot-${USER}" "${BEE_TMP_BUILDROOT}" | |
} | |
function config_handle_deprecated_beefile() { | |
if [ -n "${EXCLUDE}" ] && [[ "$(declare -p EXCLUDE)" =~ 'EXCLUDE="' ]] ; then | |
print_warning "WARNING ${BEE##*/}: scalar usage of EXCLUDE is deprecated - converting it to an array.." | |
EXCLUDE=( ${EXCLUDE} ) | |
fi | |
} | |
# load config: (bee/beerc) | |
# | |
# merge: | |
# - $ENV (already set or not) | |
# - local config (current directory and up) | |
# - user config (BEE_USER_CONFIG_FILE) | |
# - system config (BEE_CONFIG_FILE) | |
# - built-in defaults (see below) | |
# | |
function config_load_local_config() { | |
local local_config | |
local mp | |
local mp_last | |
: ${BEE_LOCAL_CONFIG_FILENAME:=.beerc} | |
path=${PWD} | |
unset BEE_LOCAL_CONFIG_CONTINUE | |
# check for mtab sicne stat -printf "%m" depend on it | |
if [ -e /etc/mtab ] ; then | |
mp_last="" | |
else | |
mp_last="nomtab" | |
fi | |
while [ ! -z "${path}" ] ; do | |
# stop traversing path at mountpoint boundaries | |
if [ "${mp_last}" != "nomtab" ] ; then | |
mp=$(stat --printf="%m" "${path}") | |
if [ -n "${mp_last}" -a "${mp}" != "${mp_last}" ] ; then | |
break | |
fi | |
mp_last="${mp}" | |
fi | |
local_config="${path}/${BEE_LOCAL_CONFIG_FILENAME}" | |
if [ -r "${local_config}" ] ; then | |
. ${local_config} | |
BEE_LOCAL_CONFIG_FILE_=${BEE_LOCAL_CONFIG_FILE_}${BEE_LOCAL_CONFIG_FILE_:+:}${local_config} | |
if [ -z "${BEE_LOCAL_CONFIG_CONTINUE}" ] ; then | |
break; | |
fi | |
unset BEE_LOCAL_CONFIG_CONTINUE | |
fi | |
path=${path%/*} | |
done | |
} | |
function config_load_user_config() { | |
: ${BEE_USER_CONFIG_FILE:=${XDG_CONFIG_HOME}/bee/beerc} | |
unset BEE_USER_CONFIG_FILE_ | |
# load user config | |
if [ -r "${BEE_USER_CONFIG_FILE}" ] ; then | |
. ${BEE_USER_CONFIG_FILE} | |
BEE_USER_CONFIG_FILE_=${BEE_USER_CONFIG_FILE} | |
fi | |
} | |
function config_load_system_config() { | |
local IFS=":${IFS}" | |
unset BEE_CONFIG_FILE_ | |
if [ ! -z "${BEE_CONFIG_FILE}" -a -r "${BEE_CONFIG_FILE}" ] ; then | |
. ${BEE_CONFIG_FILE} | |
BEE_CONFIG_FILE_=${BEE_CONFIG_FILE} | |
return | |
fi | |
BEE_CONFIG_FILE="" | |
# system config - search and take *first* readable | |
for dir in ${XDG_CONFIG_DIRS} ; do | |
xdgbeerc="${dir}/bee/beerc" | |
if [ -r "${xdgbeerc}" ] ; then | |
: ${BEE_CONFIG_FILE:=${xdgbeerc}} | |
fi | |
done | |
if [ -r "${BEE_CONFIG_FILE}" ] ; then | |
. ${BEE_CONFIG_FILE} | |
BEE_CONFIG_FILE_=${BEE_CONFIG_FILE} | |
fi | |
} | |
function config_set_skiplist() { | |
local IFS=":${IFS}" | |
if [ ! -z "${BEE_SKIPLIST}" -a -r "${BEE_SKIPLIST}" ] ; then | |
return | |
fi | |
BEE_SKIPLIST="" | |
# skiplist - search in user and system config - take *first* readable | |
for dir in ${XDG_CONFIG_HOME} ${XDG_CONFIG_DIRS} ; do | |
xdgskiplist="${dir}/bee/skiplist" | |
if [ -r "${xdgskiplist}" ] ; then | |
: ${BEE_SKIPLIST:=${xdgskiplist}} | |
return | |
fi | |
done | |
} | |
function config_verify_builtin_config() { | |
# set built-in default values based on uid | |
# - root gets system defaults.. | |
# - other get XDG_*_HOME defaults.. | |
if [ ${UID} -eq 0 ] ; then # root | |
: ${BEE_REPOSITORY_PREFIX=/usr/src/bee} | |
: ${BEE_METADIR=${BEE_XDG_DATADIR}/bee} | |
: ${BEE_CACHEDIR=/var/cache/bee} | |
else # user | |
: ${BEE_REPOSITORY_PREFIX=${HOME}/.local/src/bee} | |
: ${BEE_METADIR=${XDG_DATA_HOME}/bee} | |
: ${BEE_CACHEDIR=${XDG_CACHE_HOME}/bee} | |
fi | |
user=${LOGNAME} | |
: ${user:=${USER}} | |
: ${user:=${USERNAME}} | |
: ${user:=$(logname)} | |
: ${BEE_TMP_TMPDIR:=/tmp} | |
: ${BEE_TMP_BUILDROOT:=${BEE_TMP_TMPDIR}/bee-${user}} | |
: ${BEE_BEEDIR:=${BEE_REPOSITORY_PREFIX}/bee-files} | |
: ${BEE_PKGDIR:=${BEE_REPOSITORY_PREFIX}/packages} | |
: ${BEE_BUILDARCHIVEDIR:=${BEE_REPOSITORY_PREFIX}/build-archives} | |
# XDG_DOWNLOAD_DIR defaults to: ${HOME}/Downloads | |
# but since i don't like it we don't set XDG_DOWNLOAD_DIR but respect it | |
# if set. | |
: ${BEE_DOWNLOADDIR:=${XDG_DOWNLOAD_DIR}} | |
: ${BEE_DOWNLOADDIR:=${BEE_REPOSITORY_PREFIX}/downloads} | |
} | |
function config_verify_builtin_prefixes() { | |
: ${PREFIX:=/usr} | |
: ${EPREFIX:='${PREFIX}'} | |
: ${BINDIR:='${EPREFIX}/bin'} | |
: ${SBINDIR:='${EPREFIX}/sbin'} | |
: ${LIBEXECDIR:='${EPREFIX}/libexec'} | |
: ${SYSCONFDIR:=DEFAULT} | |
: ${LOCALSTATEDIR:=DEFAULT} | |
: ${SHAREDSTATEDIR:='${LOCALSTATEDIR}'} | |
: ${LIBDIR:='${EPREFIX}/lib'} | |
: ${INCLUDEDIR:='${PREFIX}/include'} | |
: ${DATAROOTDIR:='${PREFIX}/share'} | |
: ${DATADIR:='${DATAROOTDIR}'} | |
: ${INFODIR:='${DATAROOTDIR}/info'} | |
: ${MANDIR:='${DATAROOTDIR}/man'} | |
: ${DOCDIR:='${DATAROOTDIR}/doc/${PKGNAME}'} | |
: ${LOCALEDIR:='${DATAROOTDIR}/locale'} | |
} | |
function expand_prefix_variables_defaults() { | |
if [ "${SYSCONFDIR}" = "DEFAULT" ] ; then | |
SYSCONFDIR="/etc" | |
if [ "${PREFIX}" != "/usr" -a "${PREFIX}" != "/usr/local" ] ; then | |
SYSCONFDIR="\${PREFIX}${SYSCONFDIR}" | |
fi | |
fi | |
if [ "${LOCALSTATEDIR}" = "DEFAULT" ] ; then | |
LOCALSTATEDIR="/var" | |
if [ "${PREFIX}" != "/usr" -a "${PREFIX}" != "/usr/local" ] ; then | |
LOCALSTATEDIR="\${PREFIX}${LOCALSTATEDIR}" | |
fi | |
fi | |
} | |
function expand_prefix_variables() { | |
expand_prefix_variables_defaults | |
BEE_AUTO_EXCLUDE="" | |
for var in PREFIX EPREFIX BINDIR SBINDIR LIBEXECDIR SYSCONFDIR \ | |
LOCALSTATEDIR SHAREDSTATEDIR LIBDIR INCLUDEDIR \ | |
DATAROOTDIR DATADIR INFODIR LOCALEDIR MANDIR DOCDIR ; do | |
eval eval ${var}=\${${var}} | |
eval 'BEE_AUTO_EXCLUDE=( "${BEE_AUTO_EXCLUDE[@]}" \${${var}} )' | |
done | |
eval "BEE_AUTO_EXCLUDE=( ${BEE_AUTO_EXCLUDE[@]} )" | |
BEE_AUTO_EXCLUDE=( $(${BEE_BINDIR}/beecut -d '/' -p '^' -a '$' -n "${BEE_AUTO_EXCLUDE[@]}" | sort -u) ) | |
} | |
function config_init() { | |
config_init_base_config | |
config_load_local_config | |
config_load_user_config | |
config_load_system_config | |
config_init_colors | |
config_verify_builtin_config | |
config_verify_builtin_prefixes | |
config_handle_deprecated_config | |
} | |
function config_export() { | |
export BEE_REPOSITORY_PREFIX | |
export BEE_BEEDIR | |
export BEE_PKGDIR | |
export BEE_BUILDARCHIVEDIR | |
export BEE_DOWNLOADDIR | |
export BEE_METADIR | |
export BEE_CACHEDIR | |
export BEE_TMP_TMPDIR | |
export BEE_TMP_BUILDROOT | |
export BEE_BINDIR | |
export BEE_SYSCONFDIR | |
export BEE_DATADIR | |
export BEE_LIBEXECDIR | |
export BEE_BEEDESTDIR | |
export BEE_VERSION | |
export XDG_CONFIG_HOME | |
export XDG_CONFIG_DIRS | |
export XDG_DATA_HOME | |
export XDG_DATA_DIRS | |
} | |
function config_export_prefix_variables() { | |
for v in PREFIX EPREFIX BINDIR SBINDIR LIBEXECDIR SYSCONFDIR LOCALSTATEDIR \ | |
SHAREDSTATEDIR LIBDIR INCLUDEDIR DATAROOTDIR DATADIR INFODIR \ | |
MANDIR DOCDIR LOCALEDIR ; do | |
export ${v} | |
done | |
} | |
function config_print() { | |
for v in ${!BEE_*} ${!XDG_*}; do | |
eval echo "${v}=\${${v}}" | |
done | sort | |
for v in PREFIX EPREFIX BINDIR SBINDIR LIBEXECDIR SYSCONFDIR LOCALSTATEDIR \ | |
SHAREDSTATEDIR LIBDIR INCLUDEDIR DATAROOTDIR DATADIR INFODIR \ | |
MANDIR DOCDIR LOCALEDIR ; do | |
eval echo "${v}=\${${v}}" | |
done | |
} |