From 12a6c77fdd0c465761f4f9518eff0eeeda668d20 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 25 Aug 2011 12:59:27 -0500 Subject: pacman-key: have --init add more options to default gpg.conf This adds a add_gpg_conf_option() helper function which tries to be intelligent and only add not found options, and those which have not been explicitly commented out. The new options added are 'no-greeting', 'no-permission-warning', and a default 'keyserver'. Signed-off-by: Dan McGee --- scripts/pacman-key.sh.in | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 1c93314c..fb42f938 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -100,7 +100,22 @@ get_from() { return 1 } +# Adds the given gpg.conf option if it is not present in the file. +# Note that if we find it commented out, we won't add the option. +# args: $1 conffile, $2 option-name, $3 (optional) option-value +add_gpg_conf_option() { + local confline + # looking for the option 'bare', only leading spaces or # chars allowed, + # followed by at least one space and any other text or the end of line. + if ! grep -q "^[[:space:]#]*$2\([[:space:]].*\)*$" "$1" &>/dev/null; then + confline="$2" + [[ -n $3 ]] && confline="$2 $3" + echo "$confline" >> "$1" + fi +} + initialize() { + local conffile # Check for simple existence rather than for a directory as someone # may want to use a symlink here [[ -e ${PACMAN_KEYRING_DIR} ]] || mkdir -p -m 755 "${PACMAN_KEYRING_DIR}" @@ -113,11 +128,13 @@ initialize() { chmod 600 ${PACMAN_KEYRING_DIR}/secring.gpg # gpg.conf - [[ -f ${PACMAN_KEYRING_DIR}/gpg.conf ]] || touch ${PACMAN_KEYRING_DIR}/gpg.conf - chmod 644 ${PACMAN_KEYRING_DIR}/gpg.conf - if ! grep -w -q "lock-never" ${PACMAN_KEYRING_DIR}/gpg.conf &>/dev/null; then - echo "lock-never" >> ${PACMAN_KEYRING_DIR}/gpg.conf - fi + conffile="${PACMAN_KEYRING_DIR}/gpg.conf" + [[ -f $conffile ]] || touch "$conffile" + chmod 644 "$conffile" + add_gpg_conf_option "$conffile" 'no-greeting' + add_gpg_conf_option "$conffile" 'no-permission-warning' + add_gpg_conf_option "$conffile" 'lock-never' + add_gpg_conf_option "$conffile" 'keyserver' 'hkp://keys.gnupg.net' } check_keyring() { -- cgit v1.2.3-70-g09d2