summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-01 23:18:52 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 20:01:06 -0600
commitf7eaae4a402f338cb55096d334d37ca7ca4fcf49 (patch)
tree81a89d19211d9a0fce66d7a6df6ddf263d4c7976 /src
parentbe3fe84afee53fe8fdef9c3f4980c75c1cddb183 (diff)
conf.sh: add a mechanism to save environmental variables
This mimics the behavior of makepkg.
Diffstat (limited to 'src')
-rw-r--r--src/lib/conf.sh34
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...