summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-25 12:59:27 -0500
committerAllan McRae <allan@archlinux.org>2011-08-29 11:55:23 +1000
commit12a6c77fdd0c465761f4f9518eff0eeeda668d20 (patch)
tree6f13058c7119c3d68f5bfc0cab6ea1278030cd04
parent7ceeebf1505dba655b43e095f5392367a3a0f9b8 (diff)
downloadpacman-12a6c77fdd0c465761f4f9518eff0eeeda668d20.tar.xz
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 <dan@archlinux.org>
-rw-r--r--scripts/pacman-key.sh.in27
1 files 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() {