1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-03-01 01:41:52 -05:00

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 <canyonknight@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
canyonknight 2012-01-16 19:09:56 -05:00 committed by Dan McGee
parent 430b0df779
commit 24ca6ce1f9

View File

@ -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: