diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2018-08-30 15:50:55 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-08-31 21:26:07 -0400 |
commit | faa6c3a09e96c672ce2abd44981e2d720bdf9465 (patch) | |
tree | 57428548ec5b002f77058d819f4c2249dc8e7815 | |
parent | e6dc013139779a380f4712df23b29d4bf0974fb8 (diff) |
db-import-pkg: Rewrite arg parsing
- Be stricter about the values of V=
- Don't validate the upstream name against a hard-coded UPSTREAMS list,
check if the appropriate .conf exists
- Don't set extra=() globally, just set a global $arg_verbose
- Rename $UPSTREAM → $arg_upstream
-rwxr-xr-x | db-import-pkg | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/db-import-pkg b/db-import-pkg index aa9ab8c..dd00a9d 100755 --- a/db-import-pkg +++ b/db-import-pkg @@ -9,7 +9,8 @@ source "$(librelib messages)" source "$(librelib conf)" setup_traps -readonly -a UPSTREAMS=(packages community archlinux{32,arm}) +dbscripts_dir="$(dirname -- "$(readlink -e "$0")")" +readonly dbscripts_dir # usage: expac_file <file.db> <expac_args> # @@ -42,6 +43,11 @@ expac_file() { # TODO: we could be doing without things other than what is in # ${ARCHTAGS[@]} fetch_dbs() { + local extra=() + if [[ $arg_verbose = true ]]; then + extra+=(-v) + fi + rsync "${extra[@]}" --no-motd -mrtLH --no-p \ --include="*/" \ --include="*.db" \ @@ -110,6 +116,11 @@ filter_duplicates() { sync_pool() { local -r _from=$1 _whitelist=$2 _into=$3 + local extra=() + if [[ $arg_verbose = true ]]; then + extra+=(-v) + fi + mkdir -p -- "$_into" msg2 "Retrieving %d packages from %s pool" \ "$(wc -l < "$_whitelist")" \ @@ -238,21 +249,24 @@ main() { ############################################################## # Run as `V=true db-import-pkg` to get verbose output - readonly VERBOSE=${V} - extra=() - ${VERBOSE} && extra+=(-v) - readonly extra - readonly UPSTREAM=$1 + declare -r arg_verbose="$V" + declare -r arg_upstream="$1" # Print usage message - if [[ $# -ne 1 ]] || ! in_array "$UPSTREAM" "${UPSTREAMS[@]}" ; then - IFS='|' - msg 'usage: [V=true] %s {%s}' "${0##*/}" "${UPSTREAMS[*]}" + 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" exit $EXIT_INVALIDARGUMENT fi - load_conf "$(dirname "$(readlink -e "$0")")/config" PKGEXTS DBEXT FILESEXT FTP_BASE - load_conf "$(dirname "$(readlink -e "$0")")/db-import-${UPSTREAM}.conf" \ + 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 + + 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 |