From 24ca6ce1f969a6f5d3ef9277f6d20efcd76330ec Mon Sep 17 00:00:00 2001 From: canyonknight Date: Mon, 16 Jan 2012 19:09:56 -0500 Subject: Turn gpg commands into functions in pacman-key Adds functions for every gpg command. By pulling out the gpg commands from the "program start" section, additional commands can be run before or after a specific gpg command without adding additional clutter to the function call section. Adds an explicit exit status of 0 to prevent arithmetic expansions from returning non-zero, thereby falsely causing pacman-key to have a non-zero exit status. This change creates the framework for additional error messages and better exit statuses being added to every pacman-key gpg call. Signed-off-by: canyonknight Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/pacman-key.sh.in | 74 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index f358c487..02df8c50 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -338,6 +338,14 @@ populate_keyring() { fi } +add_keys() { + "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" +} + +delete_keys() { + "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" +} + edit_keys() { local errors=0; for key in "${KEYIDS[@]}"; do @@ -354,6 +362,14 @@ edit_keys() { done } +export_keys() { + "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" +} + +finger_keys() { + "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" +} + import_trustdb() { local importdir @@ -375,6 +391,35 @@ import() { done } +list_keys() { + "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" +} + +list_sigs() { + "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" +} + +lsign_keys() { + printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null +} + +receive_keys() { + "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" +} + +refresh_keys() { + "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" +} + +verify_sig() { + "${GPG_PACMAN[@]}" --verify $SIGNATURE +} + +updatedb() { + msg "$(gettext "Updating trust database...")" + "${GPG_PACMAN[@]}" --batch --check-trustdb +} + # PROGRAM START if ! type gettext &>/dev/null; then gettext() { @@ -476,27 +521,24 @@ esac (( ! INIT )) && check_keyring -(( ADD )) && "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" -(( DELETE )) && "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" +(( ADD )) && add_keys +(( DELETE )) && delete_keys (( EDITKEY )) && edit_keys -(( EXPORT )) && "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" -(( FINGER )) && "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" +(( EXPORT )) && export_keys +(( FINGER )) && finger_keys (( IMPORT )) && import (( IMPORT_TRUSTDB)) && import_trustdb (( INIT )) && initialize -(( LISTKEYS )) && "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" -(( LISTSIGS )) && "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" -if (( LSIGNKEY )); then - printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null -fi +(( LISTKEYS )) && list_keys +(( LISTSIGS )) && list_sigs +(( LSIGNKEY )) && lsign_keys (( POPULATE )) && populate_keyring -(( RECEIVE )) && "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" -(( REFRESH )) && "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" -(( VERIFY )) && "${GPG_PACMAN[@]}" --verify "$SIGNATURE" +(( RECEIVE )) && receive_keys +(( REFRESH )) && refresh_keys +(( VERIFY )) && verify_sig -if (( UPDATEDB )); then - msg "$(gettext "Updating trust database...")" - "${GPG_PACMAN[@]}" --batch --check-trustdb -fi +(( UPDATEDB )) && updatedb + +exit 0 # vim: set ts=2 sw=2 noet: -- cgit v1.2.3-70-g09d2