summaryrefslogtreecommitdiff
path: root/src/lib/conf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/conf.sh')
-rw-r--r--src/lib/conf.sh49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/lib/conf.sh b/src/lib/conf.sh
index f96af26..ee52f6f 100644
--- a/src/lib/conf.sh
+++ b/src/lib/conf.sh
@@ -1,7 +1,7 @@
#!/bin/bash # non-executable, but put this there as a hint to text editors
# This may be included with or without `set -euE`
-# Copyright (c) 2012-2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2012-2014 by Luke Shumaker <lukeshu@sbcglobal.net>
#
# 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
@@ -29,7 +29,7 @@ if [[ -z ${XDG_CACHE_HOME:-} ]]; then
export XDG_CACHE_HOME="${LIBREHOME}/.cache"
fi
-# Generic functions ############################################################
+# Low-level generic functions ##################################################
# Usage: list_files $slug
# Lists the configuration files to be considered for $slug.
@@ -61,7 +61,7 @@ list_files() {
}
# Usage: list_envvars $slug
-# Lists the environmental variables that take precidence over the configuration
+# Lists the environmental variables that take precedence over the configuration
# files for $slug.
list_envvars() {
local slug=$1
@@ -73,10 +73,16 @@ list_envvars() {
PKGEXT SRCEXT \
GPGKEY PACKAGER
;;
+ libretools)
+ printf '%s\n' \
+ DIFFPROG
+ ;;
*) :;;
esac
}
+# High-level generic functions #################################################
+
# Usage: load_files $slug
# Loads the configuration files for $slug in the proper order.
load_files() {
@@ -106,7 +112,7 @@ load_files() {
# Check whether the variables listed are properly set.
# If not, it prints a message saying to set them in the configuration file(s)
# for $slug.
-check_vars() {
+check_vars() (
local slug=$1; shift
local ret=0
@@ -116,10 +122,10 @@ check_vars() {
if [[ -z ${!VAR:-} ]]; then
type print &>/dev/null || . libremessages
if [[ $(list_files $slug|wc -l) -gt 1 ]]; then
- print "Configure '%s' in one of:" "$VAR"
+ _l print "Configure '%s' in one of:" "$VAR"
list_files $slug | sed 's/./ -> &/'
else
- print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)"
+ _l print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)"
fi
ret=1
fi
@@ -128,24 +134,27 @@ check_vars() {
if [[ $ret != 0 ]]; then
return 1
fi
-}
-
-# makepkg configuration ########################################################
+)
-# Usage: get_conf_makepkg <var_name> <default_value>
-get_conf_makepkg() (
+# Usage: get_var <slug> <var_name> <default_value>
+# Does not work with arrays
+get_var() (
set +euE
- local setting=$1
- local default=$2
- load_files makepkg
- printf '%s\n' "${!setting:-${default}}"
+ local slug=$1
+ local setting=$2
+ local default=$3
+ load_files "$slug"
+ printf '%s' "${!setting:-${default}}"
)
-set_conf_makepkg() {
- local key=$1
- local val=$2
+# Usage: set_var <slug> <var_name> <value>
+# Does not work with arrays
+set_var() {
+ local slug=$1
+ local key=$2
+ local val=$3
local file
- for file in $(list_files makepkg|tac); do
+ for file in $(list_files "$slug"|tac); do
if [[ -w $file ]]; then
sed -i "/^\s*$key=/d" "$file"
printf '%s=%q\n' "$key" "$val" >> "$file"
@@ -185,6 +194,6 @@ unset_PKGBUILD() {
load_PKGBUILD() {
local file=${1:-./PKGBUILD}
unset_PKGBUILD
- CARCH="$(get_conf_makepkg CARCH "`uname -m`")"
+ CARCH="$(get_var makepkg CARCH "`uname -m`")"
. "$file"
}