summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-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 f89788e..830eb01 100644
--- a/src/lib/conf.sh
+++ b/src/lib/conf.sh
@@ -10,47 +10,56 @@ fi
# Generic functions ############################################################
-get_files() {
+# Usage: list_files $slug
+# Lists the configuration files to be considered for $slug.
+# Later files should take precedence over earlier files.
+list_files() {
local slug=$1
case $slug in
- makepkg.conf)
- if [[ $MAKEPKG_CONF != /etc/$slug && -r $MAKEPKG_CONF ]]; then
+ makepkg)
+ if [[ $MAKEPKG_CONF != /etc/$slug.conf && -r $MAKEPKG_CONF ]]; then
echo "$MAKEPKG_CONF"
else
- echo /etc/$slug
- echo "$LIBREHOME/.$slug"
+ echo /etc/$slug.conf
+ echo "$LIBREHOME/.$slug.conf"
fi
;;
- libretools.conf)
- echo /etc/$slug
- echo "$XDG_CONFIG_HOME/libretools/$slug"
+ libretools)
+ echo /etc/$slug.conf
+ echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
;;
- *.conf)
- echo /etc/libretools.d/$slug
- echo "$XDG_CONFIG_HOME/libretools/$slug"
+ *)
+ echo /etc/libretools.d/$slug.conf
+ echo "$XDG_CONFIG_HOME/libretools/$slug.conf"
;;
esac
}
+# Usage: load_files $slug
+# Loads the configuration files for $slug in the proper order.
load_files() {
- for file in $(get_files $1.conf); do
+ for file in $(list_files $1); do
if [[ -r $file ]]; then
. "$file"
fi
done
}
+# Usage: check_vars $slug VAR1 VAR2...
+# 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() {
local slug=$1
shift
local ret=0
for VAR in "$@"; do
if [[ -z ${!VAR} ]]; then
- if [[ $(get_files $slug|wc -l) > 1 ]]; then
+ if [[ $(list_files $slug|wc -l) > 1 ]]; then
echo "Configure '$VAR' in one of:"
- get_files $slug | sed 's/./ -> &/'
+ list_files $slug | sed 's/./ -> &/'
else
- echo "Configure '$VAR' in $(get_files $slug)"
+ echo "Configure '$VAR' in $(list_files $slug)"
fi
ret=1
fi
@@ -68,6 +77,7 @@ load_conf_makepkg() {
load_files makepkg
}
+# Usage: get_conf_makepkg <var_name> <default_value>
get_conf_makepkg() (
set +euE
local setting=$1
@@ -79,7 +89,7 @@ get_conf_makepkg() (
set_conf_makepkg() {
local key=$1
local val=$2
- for file in `get_files makepkg.conf|tac`; do
+ for file in $(list_files makepkg.conf|tac); do
if [[ -w $file ]]; then
sed -i "/^\s*$key=/d" "$file"
echo "$key='$val'" >> "$file"
@@ -89,11 +99,10 @@ set_conf_makepkg() {
return 1
}
-
# libretools configuration #####################################################
check_conf_libretools() {
- check_vars libretools.conf \
+ check_vars libretools \
PARABOLAHOST LIBREDESTDIR BLACKLIST WORKDIR REPOS ARCHES \
ABSLIBREGIT DIFFTOOL FULLBUILDCMD SIGEXT SIGID
}
@@ -111,11 +120,11 @@ load_conf_libretools_chroot() {
# as stated above, we don't check for it.
:
else
- check_vars chroot.conf CHROOTDIR CHROOT
+ check_vars chroot CHROOTDIR CHROOT
fi
}
load_conf_libretools_librefetch() {
load_files librefetch
- check_vars librefetch.conf MIRROR DOWNLOADER
+ check_vars librefetch MIRROR DOWNLOADER
}