diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2018-09-02 17:42:15 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-09-02 18:04:37 -0400 |
commit | bc4832364050a05976dce33f28bba9ed3193010d (patch) | |
tree | 7a2301e87ca1e621aac215f4c1383e53f3d32482 /db-import-pkg | |
parent | 6d4dcdb3957f46e06d7446fdfae775c5b557d8dc (diff) |
db-import-pkg: Merge the config in to the main DBSCRIPTS_CONFIG system
I know, I'm a hypocrite for violating
# Please try to refrain from adding new variables to this file.
# Instead, create separate ${toolname}.conf files. Only add a
# variable here if multiple tools start needing the option.
When db-import-pkg moves to use db-{move,update,remove} internally, it will
also need to load an upstream-specific config.local.${UPSTREAM} file (the
systemd service already sets Environment=DBSCRIPTS_CONFIG=… appropriately,
in anticipation of this.
This means that the upstream must be specified *twice* when invoking
db-import-pkg; once in the environment, and once in an arg. Right now it
(essentially) disregards the environment setting, but that won't always be
true. To put a point on that, the test suite currently *doesn't* set the
environment differently for each upstream; once it actually uses the
environment, the test suite will "break".
So, I'd like to unify these, so that the upstream only needs to be
specified once.
If we do this as an argument, it will have to get very kludgey with
overriding DBSCRIPTS_CONFIG internally, so don't do that. That leaves
setting the upstream via DBSCRIPTS_CONFIG= as the only sane option.
At that point, it becomes silly to have a tertiary config file
(db-import-${UPSTREAM}.conf) that is referred to by the secondary config
file (config.local.${UPSTREAM}).
Diffstat (limited to 'db-import-pkg')
-rwxr-xr-x | db-import-pkg | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/db-import-pkg b/db-import-pkg index c6a3caf..02344ae 100755 --- a/db-import-pkg +++ b/db-import-pkg @@ -6,12 +6,8 @@ set -eE shopt -s extglob globstar nullglob source "$(librelib messages)" -source "$(librelib conf)" setup_traps -dbscripts_dir="$(dirname -- "$(readlink -e "$0")")" -readonly dbscripts_dir - # usage: expac_file <file.db> <expac_args> # # Uses the ${WORKDIR} global @@ -271,34 +267,51 @@ main() { # Run as `V=true db-import-pkg` to get verbose output declare -r arg_verbose="$V" - declare -r arg_upstream="$1" # Print usage message - if [[ $# -ne 1 ]]; then - msg 'usage: [V=true] %s <upstream-name>' "${0##*/}" - print '<upstream-name> refers to a %q/db-import-<upstream-name>.conf file.' "$dbscripts_dir" + if [[ $# -ne 0 ]] || [[ -z "$DBSCRIPTS_CONFIG" ]] || ! grep -q ARCHMIRROR -- "$DBSCRIPTS_CONFIG"; then + msg 'usage: [V=true] DBSCRIPTS_CONFIG=/path/to/file %s' "${0##*/}" exit $EXIT_INVALIDARGUMENT fi - if ! [[ -f "${dbscripts_dir}/db-import-${arg_upstream}.conf" && - -r "${dbscripts_dir}/db-import-${arg_upstream}.conf" ]]; then - print 'Not a valid upstream name: %q' "$arg_upstream" >&2 - exit $EXIT_INVALID_ARGUMENT - fi + local config_file + config_file="$(dirname "$(readlink -e "$0")")/config" + source "$config_file" + + local ret=0 varname varref + for varname in PKGEXTS DBEXT FILESEXT FTP_BASE; do + if [[ -z ${!varname:-} ]] || is_array "$varname"; then + print "Configure '%s' as a non-empty string in %q (or %q):" "$varname" "$config_file" "$LOCAL_CONFIG" + ret=$EXIT_NOTCONFIGURED + fi + done + for varname in ARCHMIRROR ARCHPATH OURPKGPOOL; do # optional: OURSRCPOOL ARCH{PKG,SRC}POOL + if [[ -z ${!varname:-} ]] || is_array "$varname"; then + print "Configure '%s' as a non-empty string in DBSCRIPTS_CONFIG=%q (did you set DBSCRIPTS_CONFIG correctly?):" "$varname" "$LOCAL_CONFIG" + ret=$EXIT_NOTCONFIGURED + fi + done + for varname in ARCHTAGS; do # optional: INHERIT + declare -n varref="$varname" + if (( ${#varref[*]} == 0 )) || ! is_array "$var"; then + print "Configure '%s' as a non-empty array in DBSCRIPTS_CONFIG=%q (did you set DBSCRIPTS_CONFIG correctly?):" "$varname" "$LOCAL_CONFIG" + fi + done - load_conf "${dbscripts_dir}/config" PKGEXTS DBEXT FILESEXT FTP_BASE - load_conf "${dbscripts_dir}/db-import-${arg_upstream}.conf" \ - ARCHMIRROR ARCHTAGS ARCHPATH OURPKGPOOL # optional: OURSRCPOOL ARCH{PKG,SRC}POOL INHERIT if [[ -n ${ARCHSRCPOOL:-} && -z ${OURSRCPOOL:-} ]]; then print 'If you set %s, then you must set %s' {ARCH,OUR}SRCPOOL - exit $EXIT_NOTCONFIGURED + ret=$EXIT_NOTCONFIGURED elif [[ -n ${OURSRCPOOL:-} && -z ${ARCHSRCPOOL:-} ]]; then print 'If you set %s, then you must set %s' {OUR,ARCH}SRCPOOL - exit $EXIT_NOTCONFIGURED + ret=$EXIT_NOTCONFIGURED fi if [[ -n ${ARCHSRCPOOL:-} && -z ${ARCHPKGPOOL:-} ]]; then print '%s requires that %s is also set' ARCH{SRC,PKG}POOL - exit $EXIT_NOTCONFIGURED + ret=$EXIT_NOTCONFIGURED + fi + + if (( ret != 0 )); then + exit $ret fi WORKDIR=$(mktemp -dt "${0##*/}.XXXXXXXXXX") |