From 507b01b912d77f0cc5422e689623f1b19c208525 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 25 Sep 2011 15:24:53 -0400 Subject: pacman-key: allow get_from to return a default value Keep the non-zero return val to let the caller know that the key wasn't found. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- scripts/pacman-key.sh.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index cf63be87..212d0fe1 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -95,7 +95,8 @@ There is NO WARRANTY, to the extent permitted by law.\n")" # read the config file "$1" which has key=value pairs, and return the key which # matches "$2". the equals sign between pairs may be surrounded by any amount -# of whitespace. +# of whitespace. Optionally, "$3" can be specified which is the default value +# when no key is found. get_from() { while IFS='=' read -r key value; do [[ -z $key || ${key:0:1} = '#' ]] && continue @@ -105,6 +106,7 @@ get_from() { return 0 fi done < "$1" + printf '%s\n' "$3" return 1 } @@ -437,7 +439,7 @@ fi # if PACMAN_KEYRING_DIR isn't assigned, try to get it from the config # file, falling back on a hard default -PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" || echo "@sysconfdir@/pacman.d/gnupg")} +PACMAN_KEYRING_DIR=${PACMAN_KEYRING_DIR:-$(get_from "$CONFIG" "GPGDir" "@sysconfdir@/pacman.d/gnupg")} GPG_PACMAN=(gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning) if [[ -n ${KEYSERVER} ]]; then -- cgit v1.2.3-70-g09d2