From f7eaae4a402f338cb55096d334d37ca7ca4fcf49 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 1 Jun 2013 23:18:52 -0600 Subject: conf.sh: add a mechanism to save environmental variables This mimics the behavior of makepkg. --- src/lib/conf.sh | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src') 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... -- cgit v1.2.3-54-g00ecf