From 9dd19a89b3f66257fe42b20f40a8f6ce59ed77f6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 4 Oct 2013 14:09:31 -0400 Subject: conf.sh: generalize {get,set}_conf_makepkg to {get,set}_var --- src/chroot-tools/libremakepkg | 12 ++++++------ src/lib/conf.sh | 29 ++++++++++++++++------------- src/lib/conf.sh.3.ronn | 34 +++++++++++++--------------------- 3 files changed, 35 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index f808070..fc6418c 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -219,12 +219,12 @@ main() { # Load makepkg configuration ########################################### # Note that all of these are globals - SRCDEST="$(get_conf_makepkg SRCDEST "$PWD")" - PKGDEST="$(get_conf_makepkg PKGDEST "$PWD")" - LOGDEST="$(get_conf_makepkg LOGDEST "$PWD")" + SRCDEST="$(get_var makepkg SRCDEST "$PWD")" + PKGDEST="$(get_var makepkg PKGDEST "$PWD")" + LOGDEST="$(get_var makepkg LOGDEST "$PWD")" mkdir -p "$SRCDEST" "$PKGDEST" "$LOGDEST" - MAKEFLAGS="$(get_conf_makepkg MAKEFLAGS '')" - PACKAGER="$(get_conf_makepkg PACKAGER '')" + MAKEFLAGS="$(get_var makepkg MAKEFLAGS '')" + PACKAGER="$(get_var makepkg PACKAGER '')" librechroot_flags=( -r "$PWD:/startdir_host" @@ -249,7 +249,7 @@ main() { # Set target CARCH # note that we waited until after locking/creating the chroot to do this - export CARCH="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_conf_makepkg CARCH)" + export CARCH="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_var makepkg CARCH)" # Pre-build msg 'Starting pre-build activities...' diff --git a/src/lib/conf.sh b/src/lib/conf.sh index c2904de..47a93c7 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -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. @@ -77,6 +77,8 @@ list_envvars() { esac } +# High-level generic functions ################################################# + # Usage: load_files $slug # Loads the configuration files for $slug in the proper order. load_files() { @@ -130,24 +132,25 @@ check_vars() { fi } -# makepkg configuration ######################################################## - -# Usage: get_conf_makepkg +# Usage: get_var # Does not work with arrays -get_conf_makepkg() ( +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}}" ) +# Usage: set_var # Does not work with arrays -set_conf_makepkg() { - local key=$1 - local val=$2 +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" diff --git a/src/lib/conf.sh.3.ronn b/src/lib/conf.sh.3.ronn index a2bc862..82f6eed 100644 --- a/src/lib/conf.sh.3.ronn +++ b/src/lib/conf.sh.3.ronn @@ -59,10 +59,20 @@ The routines you will likely actually use are: aren't, it prints a message to configure them in the configuration files for , and returns with a non-zero status. + * `get_var` : + If is set in the configuration for , print it's + value, considering environmental variables. If it is not set, + return . This does NOT work for array variables. + * `set_var` : + Set the variable equal to in the configuration file + for of highest precedence that already exists, and is + writable. If no files fit this description, the routine does + nothing and returns a non-zero exit status. This does NOT work + for array variables. -There are also two more routines that are used internally by -the above. You are unlikely to use them directly, but they might -be useful for debugging. +There are two more routines the above routines use internally that are +used internally by . You are unlikely to use them directly, but they +might be useful for debugging, or at least describing behavior. * `list_files` : Lists (newline-separated) the configuration files that must be @@ -75,24 +85,6 @@ be useful for debugging. environmental variable is set, the value in the configuration file is ignored. -### MAKEPKG.CONF ROUTINES - -These two routines exist to get and set individual variables in -`makepkg.conf`(). See the output of `list_files makepkg` for exactly -what set of files that refers to. - -These routines do NOT work with array settings. - - * `get_conf_makepkg` : - If is set, return it's value, considering environmental - variables. If it is not set, return . The printed - value is then trailed by a newline. - * `set_conf_makepkg` : - Set the variable equal to in the configuration file - of highest precedence that already exists, and is writable. If - no files fit this description, the routine does nothing and - returns a non-zero exit status. - ### PKGBUILD ROUTINES These two routines deal with loading `PKGBUILD`(5) files. -- cgit v1.2.3-54-g00ecf