pacman/scripts/libmakepkg/util/config.sh.in
Eli Schwartz f4da297de2 libmakepkg: fix regression in sending plain() output to stderr
In commit 882e707e40 we changed message
output to go to stdout by default, unless it was an error. The plain()
function doesn't *look* like an error function, but in practice it was
-- it's used to continue multiline messages, and all in-tree uses were
for warning/error.

This is a problem both because we're sending output to the wrong place,
and because in some cases, we were performing error logging from a
function which would otherwise return a value to be captured in a
variable using command substution.

Fix this and straighten out the API by providing two functions: one for
continuing msg output, and one which wraps this by sending output to
stderr, for continuing error output.

Change all callers to use the second function.

(cherry picked from commit bf458cced7)
2020-06-18 02:06:46 -07:00

76 lines
2.5 KiB
Bash

#!/bin/bash
#
# config.sh - functions for handling makepkg config files
#
# Copyright (c) 2006-2020 Pacman Development Team <pacman-dev@archlinux.org>
# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
#
# This program 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.
#
# 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/>.
#
[[ -n "$LIBMAKEPKG_UTIL_CONFIG_SH" ]] && return
LIBMAKEPKG_UTIL_CONFIG_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/error.sh"
source "$LIBRARY/util/message.sh"
source "$LIBRARY/util/util.sh"
# correctly source makepkg.conf, respecting user precedence and the system conf
source_makepkg_config() {
# $1: override system config file
local MAKEPKG_CONF=${1:-${MAKEPKG_CONF:-@sysconfdir@/makepkg.conf}}
# Source the config file; fail if it is not found
if [[ -r $MAKEPKG_CONF ]]; then
source_safe "$MAKEPKG_CONF"
else
error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
plainerr "$(gettext "Aborting...")"
exit $E_CONFIG_ERROR
fi
# Source user-specific makepkg.conf overrides, but only if no override config
# file was specified
XDG_PACMAN_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/pacman"
if [[ $MAKEPKG_CONF = "@sysconfdir@/makepkg.conf" ]]; then
if [[ -r $XDG_PACMAN_DIR/makepkg.conf ]]; then
source_safe "$XDG_PACMAN_DIR/makepkg.conf"
elif [[ -r $HOME/.makepkg.conf ]]; then
source_safe "$HOME/.makepkg.conf"
fi
fi
}
# load makepkg.conf by sourcing the configuration files, and preserving
# existing environment settings
load_makepkg_config() {
# $1: override system config file
local MAKEPKG_CONF=${1:-${MAKEPKG_CONF:-@sysconfdir@/makepkg.conf}}
# preserve environment variables to override makepkg.conf
local restore_envvars=$(
for var in PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR PKGEXT SRCEXT GPGKEY PACKAGER CARCH; do
# the output of 'declare -p' results in locally scoped values when used within a function
[[ -v $var ]] && printf '%s=%s\n' "$var" "${!var@Q}"
done
)
source_makepkg_config "$MAKEPKG_CONF"
eval "$restore_envvars"
}