diff options
Diffstat (limited to 'src/lib/conf.sh')
-rw-r--r-- | src/lib/conf.sh | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/conf.sh b/src/lib/conf.sh index e68c9b8..3ec8a8d 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -61,14 +61,46 @@ list_files() { esac } +# Usage: list_envvars $slug +# Lists the environmental variables that take precidence over the configuration +# files for $slug. +list_envvars() { + local slug=$1 + case $slug in + makepkg) + printf '%s\n' \ + PKGDEST SRCDEST SRCPKGDEST LOGDEST \ + BUILDDIR \ + PKGEXT SRCEXT \ + GPGKEY PACKAGER + ;; + *) :;; + esac +} + # Usage: load_files $slug # Loads the configuration files for $slug in the proper order. load_files() { - for file in $(list_files $1); do + local slug=$1 + local var + local file + + # Save the existing versions at _VARNAME + for var in $(list_envvars $slug); do + [[ -n ${!var:-} ]] && eval "_$var=\${$var}" + done + + # Load the files + for file in $(list_files $slug); do if [[ -r $file ]]; then . "$file" fi done + + # Restore the _SAVED versions + for var in $(list_envvars $slug); do + eval "$var=\${_$var:-\${$var:-}}" + done } # Usage: check_vars $slug VAR1 VAR2... |