diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-04 14:09:31 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-04 14:09:31 -0400 |
commit | 9dd19a89b3f66257fe42b20f40a8f6ce59ed77f6 (patch) | |
tree | 5cb14d1dae7d757afafed4cd318b8162ada01328 /src/lib | |
parent | f5b650a06cddd447ad7a75330e9e9c6baf23ccc4 (diff) |
conf.sh: generalize {get,set}_conf_makepkg to {get,set}_var
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/conf.sh | 29 | ||||
-rw-r--r-- | src/lib/conf.sh.3.ronn | 34 |
2 files changed, 29 insertions, 34 deletions
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 <var_name> <default_value> +# Usage: get_var <slug> <var_name> <default_value> # 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 <slug> <var_name> <value> # 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 <SLUG>, and returns with a non-zero status. + * `get_var` <SLUG> <VAR> <DEFAULT>: + If <VAR> is set in the configuration for <SLUG>, print it's + value, considering environmental variables. If it is not set, + return <DEFAULT>. This does NOT work for array variables. + * `set_var` <SLUG> <VAR> <VALUE>: + Set the variable <VAR> equal to <VALUE> in the configuration file + for <SLUG> 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` <SLUG>: Lists (newline-separated) the configuration files that must be @@ -75,24 +85,6 @@ be useful for debugging. <PACKAGER> 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` <VAR> <DEFAULT>: - If <VAR> is set, return it's value, considering environmental - variables. If it is not set, return <DEFAULT>. The printed - value is then trailed by a newline. - * `set_conf_makepkg` <VAR> <VALUE>: - Set the variable <VAR> equal to <VALUE> 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. |