[pacman-dev] [PATCH 2/2] pacman-key: have --init add more options to default gpg.conf
Dan McGee
dan at archlinux.org
Thu Aug 25 13:59:27 EDT 2011
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 at archlinux.org>
---
scripts/pacman-key.sh.in | 27 ++++++++++++++++++++++-----
1 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index 5b4320d..8e074ff 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -99,7 +99,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}"
@@ -112,11 +127,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() {
--
1.7.6.1
More information about the pacman-dev
mailing list