[pacman-dev] [PATCH 1/4] pacman-key.sh.in: applied patch by Denis A. Altoé Falqueto
From: Ivan Kanakarakis <ivan.kanak@gmail.com> Denis' patch applied to master --- scripts/pacman-key.sh.in | 520 ++++++++++++++++++++++++--------------------- 1 files changed, 277 insertions(+), 243 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 89e52fc..0f6e3f5 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -27,223 +27,250 @@ export TEXTDOMAINDIR='@localedir@' myver="@PACKAGE_VERSION@" msg() { - local mesg=$1; shift - printf "==> ${mesg}\n" "$@" >&1 + local mesg=$1; shift + printf "==> ${mesg}\n" "$@" >&1 } msg2() { - (( QUIET )) && return - local mesg=$1; shift - printf " -> ${mesg}\n" "$@" >&1 + (( QUIET )) && return + local mesg=$1; shift + printf " -> ${mesg}\n" "$@" >&1 } warning() { - local mesg=$1; shift - printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 + local mesg=$1; shift + printf "==> $(gettext "WARNING:") ${mesg}\n" "$@" >&2 } error() { - local mesg=$1; shift - printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 + local mesg=$1; shift + printf "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2 } usage() { - printf "pacman-key (pacman) %s\n" ${myver} - echo - printf "$(gettext "Usage: %s [options] <command> [arguments]")\n" $(basename $0) - echo - echo "$(gettext "Manage pacman's list of trusted keys")" - echo - echo "$(gettext "Options must be placed before commands. The available options are:")" - printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$CONFIG" - echo "$(gettext " --gpgdir Set an alternate directory for gnupg")" - echo - echo "$(gettext "The available commands are:")" - echo "$(gettext " -a, --add [<file(s)>] Add the specified keys (empty for stdin)")" - echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")" - echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")" - echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")" - echo "$(gettext " -h, --help This help")" - echo "$(gettext " -l, --list List keys")" - echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" - echo "$(gettext " -t, --trust <keyid(s)> Set the trust level of the given keyids")" - echo "$(gettext " -u, --updatedb Update the trustdb of pacman")" - echo "$(gettext " -V, --version Show program version")" - echo "$(gettext " --adv <params> Use pacman's keyring with advanced gpg commands")" - printf "$(gettext " --reload Reload the default keys")" - echo + printf "pacman-key (pacman) %s\n" ${myver} + echo + printf "$(gettext "Usage: %s [options] <command> [arguments]")\n" $(basename $0) + echo + echo "$(gettext "Manage pacman's list of trusted keys")" + echo + echo "$(gettext "Options must be placed before commands. The available options are:")" + printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$CONFIG" + echo "$(gettext " --gpgdir Set an alternate directory for gnupg")" + echo + echo "$(gettext "The available commands are:")" + echo "$(gettext " -a, --add [<file(s)>] Add the specified keys (empty for stdin)")" + echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")" + echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")" + echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")" + echo "$(gettext " -h, --help This help")" + echo "$(gettext " -l, --list List keys")" + echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" + echo "$(gettext " -t | --edit-key <keyid> ... - edit trust properties for the given keys")" + echo "$(gettext " -u, --updatedb Update the trustdb of pacman")" + echo "$(gettext " -V, --version Show program version")" + echo "$(gettext " --adv <params> Use pacman's keyring with advanced gpg commands")" + printf "$(gettext " --reload Reload the default keys")" + echo } version() { - printf "pacman-key (pacman) %s\n" "${myver}" - printf "$(gettext "\ + printf "pacman-key (pacman) %s\n" "${myver}" + printf "$(gettext "\ Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>.\n\ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } find_config() { - # Prints on stdin the values of all the options from the configuration file that - # are associated with the first parameter of this function. - # The option names are stripped - grep -e "^[[:blank:]]*$1[[:blank:]]*=.*" "$CONFIG" | cut -d= -f 2- + # Prints on stdin the values of all the options from the configuration file that + # are associated with the first parameter of this function. + # The option names are stripped + grep -e "^[[:blank:]]*$1[[:blank:]]*=.*" "$CONFIG" | cut -d= -f 2- } reload_keyring() { - local PACMAN_SHARE_DIR='@prefix@/share/pacman' - local GPG_NOKEYRING="gpg --batch --quiet --ignore-time-conflict --no-options --no-default-keyring --homedir ${PACMAN_KEYRING_DIR}" - - # Variable used for iterating on keyrings - local key - local key_id - - # Keyring with keys to be added to the keyring - local ADDED_KEYS="${PACMAN_SHARE_DIR}/addedkeys.gpg" - - # Keyring with keys that were deprecated and will eventually be deleted - local DEPRECATED_KEYS="${PACMAN_SHARE_DIR}/deprecatedkeys.gpg" - - # List of keys removed from the keyring. This file is not a keyring, unlike the others. - # It is a textual list of values that gpg recogniezes as identifiers for keys. - local REMOVED_KEYS="${PACMAN_SHARE_DIR}/removedkeys" - - # Verify signatures of related files, if they exist - if [[ -r "${ADDED_KEYS}" ]]; then - msg "$(gettext "Verifying official keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${ADDED_KEYS}.sig" 1>/dev/null; then - error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}" - exit 1 - fi - fi - - if [[ -r "${DEPRECATED_KEYS}" ]]; then - msg "$(gettext "Verifying deprecated keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${DEPRECATED_KEYS}.sig" 1>/dev/null; then - error "$(gettext "The signature of file %s is not valid.")" "${DEPRECATED_KEYS}" - exit 1 - fi - fi - - if [[ -r "${REMOVED_KEYS}" ]]; then - msg "$(gettext "Verifying deleted keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${REMOVED_KEYS}.sig"; then - error "$(gettext "The signature of file %s is not valid.")" "${REMOVED_KEYS}" - exit 1 - fi - fi - - # Read the key ids to an array. The conversion from whatever is inside the file - # to key ids is important, because key ids are the only guarantee of identification - # for the keys. - local -A removed_ids - if [[ -r "${REMOVED_KEYS}" ]]; then - while read key; do - local key_values name - key_values=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5,10 --output-delimiter=' ') - if [[ -n $key_values ]]; then - # The first word is the key_id - key_id=${key_values%% *} - # the rest if the name of the owner - name=${key_values#* } - if [[ -n ${key_id} ]]; then - # Mark this key to be deleted - removed_ids[$key_id]="$name" - fi - fi - done < "${REMOVED_KEYS}" - fi - - # List of keys that must be kept installed, even if in the list of keys to be removed - local HOLD_KEYS=$(find_config "HoldKeys") - - # Remove the keys that must be kept from the set of keys that should be removed - if [[ -n ${HOLD_KEYS} ]]; then - for key in ${HOLD_KEYS}; do - key_id=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5) - if [[ -n "${removed_ids[$key_id]}" ]]; then - unset removed_ids[$key_id] - fi - done - fi - - # Add keys from the current set of keys from pacman-keyring package. The web of trust will - # be updated automatically. - if [[ -r "${ADDED_KEYS}" ]]; then - msg "$(gettext "Appending official keys...")" - local add_keys=$(${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5) - for key_id in ${add_keys}; do - # There is no point in adding a key that will be deleted right after - if [[ -z "${removed_ids[$key_id]}" ]]; then - ${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import - fi - done - fi - - if [[ -r "${DEPRECATED_KEYS}" ]]; then - msg "$(gettext "Appending deprecated keys...")" - local add_keys=$(${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5) - for key_id in ${add_keys}; do - # There is no point in adding a key that will be deleted right after - if [[ -z "${removed_ids[$key_id]}" ]]; then - ${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import - fi - done - fi - - # Remove the keys not marked to keep - if (( ${#removed_ids[@]} > 0 )); then - msg "$(gettext "Removing deleted keys from keyring...")" - for key_id in "${!removed_ids[@]}"; do - echo " removing key $key_id - ${removed_ids[$key_id]}" - ${GPG_PACMAN} --quiet --batch --yes --delete-key "${key_id}" - done - fi - - # Update trustdb, just to be sure - msg "$(gettext "Updating trust database...")" - ${GPG_PACMAN} --batch --check-trustdb + local PACMAN_SHARE_DIR='@prefix@/share/pacman' + local GPG_NOKEYRING="gpg --batch --quiet --ignore-time-conflict --no-options --no-default-keyring --homedir ${PACMAN_KEYRING_DIR}" + + # Variable used for iterating on keyrings + local key + local key_id + + # Keyring with keys to be added to the keyring + local ADDED_KEYS="${PACMAN_SHARE_DIR}/addedkeys.gpg" + + # Keyring with keys that were deprecated and will eventually be deleted + local DEPRECATED_KEYS="${PACMAN_SHARE_DIR}/deprecatedkeys.gpg" + + # List of keys removed from the keyring. This file is not a keyring, unlike the others. + # It is a textual list of values that gpg recogniezes as identifiers for keys. + local REMOVED_KEYS="${PACMAN_SHARE_DIR}/removedkeys" + + # Verify signatures of related files, if they exist + if [[ -r "${ADDED_KEYS}" ]]; then + msg "$(gettext "Verifying official keys file signature...")" + if ! ${GPG_PACMAN} --verify "${ADDED_KEYS}.sig" &>/dev/null; then + error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}" + exit 1 + fi + fi + + if [[ -r "${DEPRECATED_KEYS}" ]]; then + msg "$(gettext "Verifying deprecated keys file signature...")" + if ! ${GPG_PACMAN} --verify "${DEPRECATED_KEYS}.sig" &>/dev/null; then + error "$(gettext "The signature of file %s is not valid.")" "${DEPRECATED_KEYS}" + exit 1 + fi + fi + + if [[ -r "${REMOVED_KEYS}" ]]; then + msg "$(gettext "Verifying deleted keys file signature...")" + if ! ${GPG_PACMAN} --verify "${REMOVED_KEYS}.sig" &>/dev/null; then + error "$(gettext "The signature of file %s is not valid.")" "${REMOVED_KEYS}" + exit 1 + fi + fi + + # Read the key ids to an array. The conversion from whatever is inside the file + # to key ids is important, because key ids are the only guarantee of identification + # for the keys. + local -A removed_ids + if [[ -r "${REMOVED_KEYS}" ]]; then + while read key; do + local key_values name + key_values=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5,10 --output-delimiter=' ') + if [[ -n $key_values ]]; then + # The first word is the key_id + key_id=${key_values%% *} + # the rest if the name of the owner + name=${key_values#* } + if [[ -n ${key_id} ]]; then + # Mark this key to be deleted + removed_ids[$key_id]="$name" + fi + fi + done < "${REMOVED_KEYS}" + fi + + # List of keys that must be kept installed, even if in the list of keys to be removed + local HOLD_KEYS=$(find_config "HoldKeys") + + # Remove the keys that must be kept from the set of keys that should be removed + if [[ -n ${HOLD_KEYS} ]]; then + for key in ${HOLD_KEYS}; do + key_id=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5) + if [[ -n "${removed_ids[$key_id]}" ]]; then + unset removed_ids[$key_id] + fi + done + fi + + # Add keys from the current set of keys from pacman-keyring package. The web of trust will + # be updated automatically. + if [[ -r "${ADDED_KEYS}" ]]; then + msg "$(gettext "Appending official keys...")" + local add_keys=$(${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5) + for key_id in ${add_keys}; do + # There is no point in adding a key that will be deleted right after + if [[ -z "${removed_ids[$key_id]}" ]]; then + ${GPG_NOKEYRING} --keyring "${ADDED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import + fi + done + fi + + if [[ -r "${DEPRECATED_KEYS}" ]]; then + msg "$(gettext "Appending deprecated keys...")" + local add_keys=$(${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --with-colons --list-keys | grep ^pub | cut -d: -f5) + for key_id in ${add_keys}; do + # There is no point in adding a key that will be deleted right after + if [[ -z "${removed_ids[$key_id]}" ]]; then + ${GPG_NOKEYRING} --keyring "${DEPRECATED_KEYS}" --export "${key_id}" | ${GPG_PACMAN} --import + fi + done + fi + + # Remove the keys not marked to keep + if (( ${#removed_ids[@]} > 0 )); then + msg "$(gettext "Removing deleted keys from keyring...")" + for key_id in "${!removed_ids[@]}"; do + echo " removing key $key_id - ${removed_ids[$key_id]}" + ${GPG_PACMAN} --quiet --batch --yes --delete-key "${key_id}" + done + fi + + # Update trustdb, just to be sure + msg "$(gettext "Updating trust database...")" + ${GPG_PACMAN} --batch --check-trustdb } # PROGRAM START if ! type gettext &>/dev/null; then - gettext() { - echo "$@" - } + gettext() { + echo "$@" + } fi if [[ $1 != "--version" && $1 != "-V" && $1 != "--help" && $1 != "-h" && $1 != "" ]]; then - if type -p gpg >/dev/null 2>&1 = 1; then - error "$(gettext "gnupg does not seem to be installed.")" - msg2 "$(gettext "pacman-key requires gnupg for most operations.")" - exit 1 - elif (( EUID != 0 )); then - error "$(gettext "pacman-key needs to be run as root.")" - exit 1 - fi + if type -p gpg >/dev/null 2>&1 = 1; then + error "$(gettext "gnupg does not seem to be installed.")" + msg2 "$(gettext "pacman-key requires gnupg for most operations.")" + exit 1 + elif (( EUID != 0 )); then + error "$(gettext "pacman-key needs to be run as root.")" + exit 1 + fi fi -# Parse global options +# Iterate over the parameters to get --config and --gpgdir +# The other parameters will be filtered to another array, +# so --config and --gpgdir don't interfere with other options. CONFIG="@sysconfdir@/pacman.conf" -PACMAN_KEYRING_DIR="@sysconfdir@/pacman.d/gnupg" -while [[ $1 =~ ^--(config|gpgdir)$ ]]; do - case "$1" in - --config) shift; CONFIG="$1" ;; - --gpgdir) shift; PACMAN_KEYRING_DIR="$1" ;; - esac - shift +declare -a PARAMS +GPGDIR="" +isconfig=0 +isgpgdir=0 +for arg in "$@"; do + if (( isconfig )); then + isconfig=0 + CONFIG="$arg" + if [[ ! -f "$CONFIG" ]]; then + error "$(gettext "The configuration file is not a valid file.")" + usage + exit 1 + fi + continue + fi + if (( isgpgdir )); then + isgpgdir=0 + GPGDIR="$arg" + if [[ ! -d "$GPGDIR" ]]; then + error "$(gettext "The home directory for GnuPG is not valid.")" + usage + exit 1 + fi + continue + fi + case "$arg" in + --config) isconfig=1;; + --gpgdir) isgpgdir=1;; +*) PARAMS[${#PARAMS[@]}]="$arg" + esac done if [[ ! -r "${CONFIG}" ]]; then - error "$(gettext "%s not found.")" "$CONFIG" - exit 1 + error "$(gettext "%s not found.")" "$CONFIG" + exit 1 fi # Read GPGDIR from $CONFIG. -# The pattern is: any spaces or tabs, GPGDir, any spaces or tabs, equal sign -# and the rest of the line. The string is splitted after the first occurrence of = -if [[ GPGDIR=$(find_config "GPGDir") == 0 ]]; then - PACMAN_KEYRING_DIR="${GPGDIR}" -fi +# The precedence for GPGDIR is: +# 1st: command line +# 2nd: pacman.conf +# 3rd: default value +[[ -z "$GPGDIR" ]] && GPGDIR=$(find_config "GPGDir") +[[ -z "$GPGDIR" ]] && GPGDIR="@sysconfdir@/pacman.d/gnupg" +PACMAN_KEYRING_DIR="${GPGDIR}" GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning" # Try to create $PACMAN_KEYRING_DIR if non-existent @@ -252,74 +279,81 @@ GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning" [[ -e ${PACMAN_KEYRING_DIR} ]] || mkdir -p -m 755 "${PACMAN_KEYRING_DIR}" # Parse and execute command -command="$1" +command="${PARAMS[0]}" if [[ -z "${command}" ]]; then - usage - exit 1 + usage + exit 1 fi -shift +unset PARAMS[0] case "${command}" in - -a|--add) - # If there is no extra parameter, gpg will read stdin - ${GPG_PACMAN} --quiet --batch --import "$@" - ;; - -d|--del) - if (( $# == 0 )); then - error "$(gettext "You need to specify at least one key identifier")" - exit 1 - fi - ${GPG_PACMAN} --quiet --batch --delete-key --yes "$@" - ;; - -u|--updatedb) - ${GPG_PACMAN} --batch --check-trustdb - ;; - --reload) - reload_keyring - ;; - -l|--list) - ${GPG_PACMAN} --batch --list-sigs "$@" - ;; - -f|--finger) - ${GPG_PACMAN} --batch --fingerprint "$@" - ;; - -e|--export) - ${GPG_PACMAN} --armor --export "$@" - ;; - -r|--receive) - if (( $# < 2 )); then - error "$(gettext "You need to specify the keyserver and at least one key identifier")" - exit 1 - fi - keyserver="$1" - shift - ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "$@" - ;; - -t|--trust) - if (( $# == 0 )); then - error "$(gettext "You need to specify at least one key identifier")" - exit 1 - fi - while (( $# > 0 )); do - # Verify if the key exists in pacman's keyring - if ${GPG_PACMAN} --list-keys "$1" > /dev/null 2>&1; then - ${GPG_PACMAN} --edit-key "$1" - else - error "$(gettext "The key identified by %s doesn't exist")" "$1" - exit 1 - fi - shift - done - ;; - --adv) - msg "$(gettext "Executing: %s ")$*" "${GPG_PACMAN}" - ${GPG_PACMAN} "$@" || ret=$? - exit $ret - ;; - -h|--help) - usage; exit 0 ;; - -V|--version) - version; exit 0 ;; - *) - usage; exit 1 ;; + -a|--add) + # If there is no extra parameter, gpg will read stdin + ${GPG_PACMAN} --quiet --batch --import "${PARAMS[@]}" + ;; + -d|--del) + if (( ${#PARAMS[@]} == 0 )); then + error "$(gettext "You need to specify at least one key identifier")" + usage + exit 1 + fi + ;; + -u|--updatedb) + ${GPG_PACMAN} --batch --check-trustdb + ;; + --reload) + reload_keyring + ;; + -l|--list) + ${GPG_PACMAN} --list-sigs "${PARAMS[@]}" + ;; + -f|--finger) + ${GPG_PACMAN} --fingerprint "${PARAMS[@]}" + ;; + -e|--export) + ${GPG_PACMAN} --armor --export "${PARAMS[@]}" + ;; + -r|--receive) + if (( ${#PARAMS[@]} < 2 )); then + error "$(gettext "You need to specify the keyserver and at least one key identifier")" + exit 1 + fi + keyserver="${PARAMS[0]}" + unset PARAMS[0] + ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "${PARAMS[@]}" + ;; + -t|--edit-key) + if (( ${#PARAMS[@]} == 0 )); then + error "$(gettext "You need to specify at least one key identifier")" + exit 1 + fi + while (( ${#PARAMS[@]} > 0 )); do + # Verify if the key exists in pacman's keyring + if ${GPG_PACMAN} --list-keys "${PARAMS[0]}" &>/dev/null; then + ${GPG_PACMAN} --edit-key "${PARAMS[0]}" + else + error "$(gettext "The key identified by %s doesn't exist")" "${PARAMS[0]}" + exit 1 + fi + unset PARAMS[0] + done + ;; + --adv) + msg "$(gettext "Executing: %s ")$*" "${GPG_PACMAN}" + ${GPG_PACMAN} "$@" || ret=$? + exit $ret + ;; + -h|--help) + usage; + exit 0 + ;; + -V|--version) + version; + exit 0 + ;; + # Parameters already handled + --config) shift ;; + --gpgdir) shift ;; +*) + usage; exit 1 ;; esac -- 1.7.4.4
From: Ivan Kanakarakis <ivan.kanak@gmail.com> --- scripts/pacman-key.sh.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 0f6e3f5..5323f68 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -63,7 +63,7 @@ usage() { echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")" echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")" echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")" - echo "$(gettext " -h, --help This help")" + echo "$(gettext " -h, --help Display this help message")" echo "$(gettext " -l, --list List keys")" echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" echo "$(gettext " -t | --edit-key <keyid> ... - edit trust properties for the given keys")" -- 1.7.4.4
From: Ivan Kanakarakis <ivan.kanak@gmail.com>
--- In response to your other email- patches like this are fine, but
On Tue, Apr 19, 2011 at 3:19 PM, <ivan.kanak@gmail.com> wrote: please use full words as appropriate in your subject. E.g. "pacman-key: unify help message with other scripts" or something (I assume that is why you made the change?) -Dan
scripts/pacman-key.sh.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 0f6e3f5..5323f68 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -63,7 +63,7 @@ usage() { echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")" echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")" echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")" - echo "$(gettext " -h, --help This help")" + echo "$(gettext " -h, --help Display this help message")" echo "$(gettext " -l, --list List keys")" echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" echo "$(gettext " -t | --edit-key <keyid> ... - edit trust properties for the given keys")" -- 1.7.4.4
On 21 April 2011 04:16, Dan McGee <dpmcgee@gmail.com> wrote:
From: Ivan Kanakarakis <ivan.kanak@gmail.com>
--- In response to your other email- patches like this are fine, but
On Tue, Apr 19, 2011 at 3:19 PM, <ivan.kanak@gmail.com> wrote: please use full words as appropriate in your subject. E.g. "pacman-key: unify help message with other scripts" or something (I assume that is why you made the change?)
-Dan
Yes, that's the reason. Thanks.
scripts/pacman-key.sh.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 0f6e3f5..5323f68 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -63,7 +63,7 @@ usage() { echo "$(gettext " -d, --del <keyid(s)> Remove the specified keyids")" echo "$(gettext " -e, --export <keyid(s)> Export the specified keyids")" echo "$(gettext " -f, --finger [<keyid(s)>] List fingerprint for specified or all keyids")" - echo "$(gettext " -h, --help This help")" + echo "$(gettext " -h, --help Display this help message")" echo "$(gettext " -l, --list List keys")" echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" echo "$(gettext " -t | --edit-key <keyid> ... - edit trust properties for the given keys")" -- 1.7.4.4
-- Ivan c00kiemon5ter V Kanak http://c00kiemon5ter.github.com
From: Ivan Kanakarakis <ivan.kanak@gmail.com> now if the command is unkown we get a message like: $ ./scripts/pacman-key --foo Uknown command: --foo <..usage..> --- scripts/pacman-key.sh.in | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 5323f68..7261c89 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -344,16 +344,23 @@ case "${command}" in exit $ret ;; -h|--help) - usage; - exit 0 + usage + exit 0 ;; -V|--version) - version; - exit 0 + version + exit 0 + ;; + # Parameters already handled + --config) + shift + ;; + --gpgdir) + shift + ;; + *) + error "$(gettext "Unknown command: $command")" + usage + exit 1 ;; - # Parameters already handled - --config) shift ;; - --gpgdir) shift ;; -*) - usage; exit 1 ;; esac -- 1.7.4.4
From: Ivan Kanakarakis <ivan.kanak@gmail.com> reverted most changes back to my previous patch I also got rid of find_config() funciton and introduced get_from() function it can actually be used with any configuration file of the format described in the comments --- scripts/pacman-key.sh.in | 168 ++++++++++++++++++++++------------------------ 1 files changed, 80 insertions(+), 88 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 7261c89..d64702e 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -82,11 +82,17 @@ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } -find_config() { - # Prints on stdin the values of all the options from the configuration file that - # are associated with the first parameter of this function. - # The option names are stripped - grep -e "^[[:blank:]]*$1[[:blank:]]*=.*" "$CONFIG" | cut -d= -f 2- +# Read file and search for values matching the given key +# The file format expected is: key = value +# 'key', 'equal sign' and 'value' can be surrounded by random whitespace +# Usage: get_from "$file" "$key" # returns the value for the first matching key +get_from() { + while read key _ value; do + if [[ $key = $2 ]]; then + echo "$value" + break + fi + done < "$1" } reload_keyring() { @@ -142,9 +148,9 @@ reload_keyring() { key_values=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5,10 --output-delimiter=' ') if [[ -n $key_values ]]; then # The first word is the key_id - key_id=${key_values%% *} + key_id="${key_values%% *}" # the rest if the name of the owner - name=${key_values#* } + name="${key_values#* }" if [[ -n ${key_id} ]]; then # Mark this key to be deleted removed_ids[$key_id]="$name" @@ -154,12 +160,12 @@ reload_keyring() { fi # List of keys that must be kept installed, even if in the list of keys to be removed - local HOLD_KEYS=$(find_config "HoldKeys") + local HOLD_KEYS="$(get_from "$CONFIG" "HoldKeys" &>/dev/null)" # Remove the keys that must be kept from the set of keys that should be removed if [[ -n ${HOLD_KEYS} ]]; then for key in ${HOLD_KEYS}; do - key_id=$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5) + key_id="$(${GPG_PACMAN} --quiet --with-colons --list-key "${key}" | grep ^pub | cut -d: -f5)" if [[ -n "${removed_ids[$key_id]}" ]]; then unset removed_ids[$key_id] fi @@ -211,88 +217,75 @@ if ! type gettext &>/dev/null; then } fi -if [[ $1 != "--version" && $1 != "-V" && $1 != "--help" && $1 != "-h" && $1 != "" ]]; then - if type -p gpg >/dev/null 2>&1 = 1; then +# Set default values +CONFIG="@sysconfdir@/pacman.conf" +PACMAN_KEYRING_DIR="@sysconfdir@/pacman.d/gnupg" + +# Parse command line options +# override default values +while [[ $1 =~ ^--(config|gpgdir)$ ]]; do + case "$1" in + --config) + shift; cli_config="$1" + ;; + --gpgdir) + shift; PACMAN_KEYRING_DIR="$1" + ;; + esac + shift +done + +# Parse the command +command="$1" +if [[ -z "${command}" ]]; then + usage + exit 1 +fi +shift + +# If command is --help/-h or --version/-V then skip checks and execute those else +# check for: dependencies , permissions and state of needed directories and files +if [[ ! ${command} =~ ^(--help|-h|--version|-V)$ ]]; then + if ! type -p gpg &>/dev/null; then error "$(gettext "gnupg does not seem to be installed.")" msg2 "$(gettext "pacman-key requires gnupg for most operations.")" exit 1 - elif (( EUID != 0 )); then + fi + if (( EUID != 0 )); then error "$(gettext "pacman-key needs to be run as root.")" exit 1 fi -fi - -# Iterate over the parameters to get --config and --gpgdir -# The other parameters will be filtered to another array, -# so --config and --gpgdir don't interfere with other options. -CONFIG="@sysconfdir@/pacman.conf" -declare -a PARAMS -GPGDIR="" -isconfig=0 -isgpgdir=0 -for arg in "$@"; do - if (( isconfig )); then - isconfig=0 - CONFIG="$arg" - if [[ ! -f "$CONFIG" ]]; then - error "$(gettext "The configuration file is not a valid file.")" - usage - exit 1 - fi - continue + # Try to create $PACMAN_KEYRING_DIR if non-existent + # Check for simple existence rather than for a directory as someone may want + # to use a symlink here + if [[ ! -e ${PACMAN_KEYRING_DIR} ]]; then + mkdir -p -m 755 "${PACMAN_KEYRING_DIR}" fi - if (( isgpgdir )); then - isgpgdir=0 - GPGDIR="$arg" - if [[ ! -d "$GPGDIR" ]]; then - error "$(gettext "The home directory for GnuPG is not valid.")" - usage - exit 1 + # Check given configuration file. Failback to default configuration + # if the specified cannot be found or read. + if [[ ${cli_config} ]]; then + if [[ ! -r ${cli_config} ]]; then + error "$(gettext "Couldn't read configuration file: %s. Using default configuration.")" "$cli_config" + else + CONFIG="$cli_config" fi - continue + unset cli_config + fi + # Read GPGDIR from $CONFIG. + if [[ GPGDIR="$(get_from "${CONFIG}" "GPGDir" &>/dev/null)" ]]; then + PACMAN_KEYRING_DIR="${GPGDIR}" fi - case "$arg" in - --config) isconfig=1;; - --gpgdir) isgpgdir=1;; -*) PARAMS[${#PARAMS[@]}]="$arg" - esac -done - -if [[ ! -r "${CONFIG}" ]]; then - error "$(gettext "%s not found.")" "$CONFIG" - exit 1 fi -# Read GPGDIR from $CONFIG. -# The precedence for GPGDIR is: -# 1st: command line -# 2nd: pacman.conf -# 3rd: default value -[[ -z "$GPGDIR" ]] && GPGDIR=$(find_config "GPGDir") -[[ -z "$GPGDIR" ]] && GPGDIR="@sysconfdir@/pacman.d/gnupg" -PACMAN_KEYRING_DIR="${GPGDIR}" GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning" -# Try to create $PACMAN_KEYRING_DIR if non-existent -# 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}" - -# Parse and execute command -command="${PARAMS[0]}" -if [[ -z "${command}" ]]; then - usage - exit 1 -fi -unset PARAMS[0] - case "${command}" in -a|--add) # If there is no extra parameter, gpg will read stdin - ${GPG_PACMAN} --quiet --batch --import "${PARAMS[@]}" + ${GPG_PACMAN} --quiet --batch --import "$@" ;; -d|--del) - if (( ${#PARAMS[@]} == 0 )); then + if (( $# == 0 )); then error "$(gettext "You need to specify at least one key identifier")" usage exit 1 @@ -305,43 +298,42 @@ case "${command}" in reload_keyring ;; -l|--list) - ${GPG_PACMAN} --list-sigs "${PARAMS[@]}" + ${GPG_PACMAN} --list-sigs "$@" ;; -f|--finger) - ${GPG_PACMAN} --fingerprint "${PARAMS[@]}" + ${GPG_PACMAN} --fingerprint "$@" ;; -e|--export) - ${GPG_PACMAN} --armor --export "${PARAMS[@]}" + ${GPG_PACMAN} --armor --export "$@" ;; -r|--receive) - if (( ${#PARAMS[@]} < 2 )); then + if (( $# < 2 )); then error "$(gettext "You need to specify the keyserver and at least one key identifier")" exit 1 fi - keyserver="${PARAMS[0]}" - unset PARAMS[0] - ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "${PARAMS[@]}" + keyserver="$1" + shift + ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "$@" ;; -t|--edit-key) - if (( ${#PARAMS[@]} == 0 )); then + if (( $# == 0 )); then error "$(gettext "You need to specify at least one key identifier")" exit 1 fi - while (( ${#PARAMS[@]} > 0 )); do + while (( $# > 0 )); do # Verify if the key exists in pacman's keyring - if ${GPG_PACMAN} --list-keys "${PARAMS[0]}" &>/dev/null; then - ${GPG_PACMAN} --edit-key "${PARAMS[0]}" + if ${GPG_PACMAN} --list-keys "$1" &>/dev/null; then + ${GPG_PACMAN} --edit-key "$1" else - error "$(gettext "The key identified by %s doesn't exist")" "${PARAMS[0]}" + error "$(gettext "The key identified by %s doesn't exist")" "$1" exit 1 fi - unset PARAMS[0] + shift done ;; --adv) msg "$(gettext "Executing: %s ")$*" "${GPG_PACMAN}" - ${GPG_PACMAN} "$@" || ret=$? - exit $ret + ${GPG_PACMAN} "$@" || exit $? ;; -h|--help) usage -- 1.7.4.4
On Tue 19 April 2011 at 23:19 +0300, ivan.kanak@gmail.com wrote:
From: Ivan Kanakarakis <ivan.kanak@gmail.com>
Denis' patch applied to master
--- scripts/pacman-key.sh.in | 520 ++++++++++++++++++++++++--------------------- 1 files changed, 277 insertions(+), 243 deletions(-)
Hello, This patch seems to apply random whitespace changes over all the file. Could you resend it without the whitespace changes so that it is easier to see what has changed? Rémy.
On Wed, Apr 20, 2011 at 12:56 AM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On Tue 19 April 2011 at 23:19 +0300, ivan.kanak@gmail.com wrote:
From: Ivan Kanakarakis <ivan.kanak@gmail.com>
Denis' patch applied to master
--- scripts/pacman-key.sh.in | 520 ++++++++++++++++++++++++--------------------- 1 files changed, 277 insertions(+), 243 deletions(-)
Hello,
This patch seems to apply random whitespace changes over all the file. Could you resend it without the whitespace changes so that it is easier to see what has changed?
More to the point- this patch has an awful commit message, as do the others in the series, so I won't look at them until that is fixed. 1. I don't know what is even being done by this (see the subject), and the commit message helps less- it needs to be a paragraph summary of what you are trying to accomplish. 2. Please use sentences, paragraphs, capital letters, and punctuation around here. http://www.archlinux.org/pacman/submitting-patches.html -Dan
On 20 April 2011 16:01, Dan McGee <dpmcgee@gmail.com> wrote:
On Wed, Apr 20, 2011 at 12:56 AM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On Tue 19 April 2011 at 23:19 +0300, ivan.kanak@gmail.com wrote:
From: Ivan Kanakarakis <ivan.kanak@gmail.com>
Denis' patch applied to master
--- scripts/pacman-key.sh.in | 520 ++++++++++++++++++++++++--------------------- 1 files changed, 277 insertions(+), 243 deletions(-)
Hello,
This patch seems to apply random whitespace changes over all the file. Could you resend it without the whitespace changes so that it is easier to see what has changed?
More to the point- this patch has an awful commit message, as do the others in the series, so I won't look at them until that is fixed.
1. I don't know what is even being done by this (see the subject), and the commit message helps less- it needs to be a paragraph summary of what you are trying to accomplish. 2. Please use sentences, paragraphs, capital letters, and punctuation around here.
http://www.archlinux.org/pacman/submitting-patches.html
-Dan
Alright, I'll try again then. Sorry for the fuss. Just a question, commits like the 2nd one in this series, that change just a line in a function but are not directly related to the problem one is trying to solve, should they be separate or is it better to be rebased/merged with some other bigger commit ? -- Ivan c00kiemon5ter V Kanak http://c00kiemon5ter.github.com
From: Ivan Kanakarakis <ivan.kanak@gmail.com> Using -b to ignore whitespace this time Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com> --- scripts/pacman-key.sh.in | 110 ++++++++++++++++++++++++++++++---------------- 1 files changed, 72 insertions(+), 38 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 89e52fc..0f6e3f5 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -66,7 +66,7 @@ usage() { echo "$(gettext " -h, --help This help")" echo "$(gettext " -l, --list List keys")" echo "$(gettext " -r, --receive <keyserver> <keyid(s)> Fetch the specified keyids")" - echo "$(gettext " -t, --trust <keyid(s)> Set the trust level of the given keyids")" + echo "$(gettext " -t | --edit-key <keyid> ... - edit trust properties for the given keys")" echo "$(gettext " -u, --updatedb Update the trustdb of pacman")" echo "$(gettext " -V, --version Show program version")" echo "$(gettext " --adv <params> Use pacman's keyring with advanced gpg commands")" @@ -110,7 +110,7 @@ reload_keyring() { # Verify signatures of related files, if they exist if [[ -r "${ADDED_KEYS}" ]]; then msg "$(gettext "Verifying official keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${ADDED_KEYS}.sig" 1>/dev/null; then + if ! ${GPG_PACMAN} --verify "${ADDED_KEYS}.sig" &>/dev/null; then error "$(gettext "The signature of file %s is not valid.")" "${ADDED_KEYS}" exit 1 fi @@ -118,7 +118,7 @@ reload_keyring() { if [[ -r "${DEPRECATED_KEYS}" ]]; then msg "$(gettext "Verifying deprecated keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${DEPRECATED_KEYS}.sig" 1>/dev/null; then + if ! ${GPG_PACMAN} --verify "${DEPRECATED_KEYS}.sig" &>/dev/null; then error "$(gettext "The signature of file %s is not valid.")" "${DEPRECATED_KEYS}" exit 1 fi @@ -126,7 +126,7 @@ reload_keyring() { if [[ -r "${REMOVED_KEYS}" ]]; then msg "$(gettext "Verifying deleted keys file signature...")" - if ! ${GPG_PACMAN} --quiet --batch --verify "${REMOVED_KEYS}.sig"; then + if ! ${GPG_PACMAN} --verify "${REMOVED_KEYS}.sig" &>/dev/null; then error "$(gettext "The signature of file %s is not valid.")" "${REMOVED_KEYS}" exit 1 fi @@ -222,15 +222,40 @@ if [[ $1 != "--version" && $1 != "-V" && $1 != "--help" && $1 != "-h" && $1 != " fi fi -# Parse global options +# Iterate over the parameters to get --config and --gpgdir +# The other parameters will be filtered to another array, +# so --config and --gpgdir don't interfere with other options. CONFIG="@sysconfdir@/pacman.conf" -PACMAN_KEYRING_DIR="@sysconfdir@/pacman.d/gnupg" -while [[ $1 =~ ^--(config|gpgdir)$ ]]; do - case "$1" in - --config) shift; CONFIG="$1" ;; - --gpgdir) shift; PACMAN_KEYRING_DIR="$1" ;; +declare -a PARAMS +GPGDIR="" +isconfig=0 +isgpgdir=0 +for arg in "$@"; do + if (( isconfig )); then + isconfig=0 + CONFIG="$arg" + if [[ ! -f "$CONFIG" ]]; then + error "$(gettext "The configuration file is not a valid file.")" + usage + exit 1 + fi + continue + fi + if (( isgpgdir )); then + isgpgdir=0 + GPGDIR="$arg" + if [[ ! -d "$GPGDIR" ]]; then + error "$(gettext "The home directory for GnuPG is not valid.")" + usage + exit 1 + fi + continue + fi + case "$arg" in + --config) isconfig=1;; + --gpgdir) isgpgdir=1;; +*) PARAMS[${#PARAMS[@]}]="$arg" esac - shift done if [[ ! -r "${CONFIG}" ]]; then @@ -239,11 +264,13 @@ if [[ ! -r "${CONFIG}" ]]; then fi # Read GPGDIR from $CONFIG. -# The pattern is: any spaces or tabs, GPGDir, any spaces or tabs, equal sign -# and the rest of the line. The string is splitted after the first occurrence of = -if [[ GPGDIR=$(find_config "GPGDir") == 0 ]]; then - PACMAN_KEYRING_DIR="${GPGDIR}" -fi +# The precedence for GPGDIR is: +# 1st: command line +# 2nd: pacman.conf +# 3rd: default value +[[ -z "$GPGDIR" ]] && GPGDIR=$(find_config "GPGDir") +[[ -z "$GPGDIR" ]] && GPGDIR="@sysconfdir@/pacman.d/gnupg" +PACMAN_KEYRING_DIR="${GPGDIR}" GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning" # Try to create $PACMAN_KEYRING_DIR if non-existent @@ -252,24 +279,24 @@ GPG_PACMAN="gpg --homedir ${PACMAN_KEYRING_DIR} --no-permission-warning" [[ -e ${PACMAN_KEYRING_DIR} ]] || mkdir -p -m 755 "${PACMAN_KEYRING_DIR}" # Parse and execute command -command="$1" +command="${PARAMS[0]}" if [[ -z "${command}" ]]; then usage exit 1 fi -shift +unset PARAMS[0] case "${command}" in -a|--add) # If there is no extra parameter, gpg will read stdin - ${GPG_PACMAN} --quiet --batch --import "$@" + ${GPG_PACMAN} --quiet --batch --import "${PARAMS[@]}" ;; -d|--del) - if (( $# == 0 )); then + if (( ${#PARAMS[@]} == 0 )); then error "$(gettext "You need to specify at least one key identifier")" + usage exit 1 fi - ${GPG_PACMAN} --quiet --batch --delete-key --yes "$@" ;; -u|--updatedb) ${GPG_PACMAN} --batch --check-trustdb @@ -278,37 +305,37 @@ case "${command}" in reload_keyring ;; -l|--list) - ${GPG_PACMAN} --batch --list-sigs "$@" + ${GPG_PACMAN} --list-sigs "${PARAMS[@]}" ;; -f|--finger) - ${GPG_PACMAN} --batch --fingerprint "$@" + ${GPG_PACMAN} --fingerprint "${PARAMS[@]}" ;; -e|--export) - ${GPG_PACMAN} --armor --export "$@" + ${GPG_PACMAN} --armor --export "${PARAMS[@]}" ;; -r|--receive) - if (( $# < 2 )); then + if (( ${#PARAMS[@]} < 2 )); then error "$(gettext "You need to specify the keyserver and at least one key identifier")" exit 1 fi - keyserver="$1" - shift - ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "$@" + keyserver="${PARAMS[0]}" + unset PARAMS[0] + ${GPG_PACMAN} --keyserver "${keyserver}" --recv-keys "${PARAMS[@]}" ;; - -t|--trust) - if (( $# == 0 )); then + -t|--edit-key) + if (( ${#PARAMS[@]} == 0 )); then error "$(gettext "You need to specify at least one key identifier")" exit 1 fi - while (( $# > 0 )); do + while (( ${#PARAMS[@]} > 0 )); do # Verify if the key exists in pacman's keyring - if ${GPG_PACMAN} --list-keys "$1" > /dev/null 2>&1; then - ${GPG_PACMAN} --edit-key "$1" + if ${GPG_PACMAN} --list-keys "${PARAMS[0]}" &>/dev/null; then + ${GPG_PACMAN} --edit-key "${PARAMS[0]}" else - error "$(gettext "The key identified by %s doesn't exist")" "$1" + error "$(gettext "The key identified by %s doesn't exist")" "${PARAMS[0]}" exit 1 fi - shift + unset PARAMS[0] done ;; --adv) @@ -317,9 +344,16 @@ case "${command}" in exit $ret ;; -h|--help) - usage; exit 0 ;; + usage; + exit 0 + ;; -V|--version) - version; exit 0 ;; - *) + version; + exit 0 + ;; + # Parameters already handled + --config) shift ;; + --gpgdir) shift ;; +*) usage; exit 1 ;; esac -- 1.7.4.4
participants (4)
-
Dan McGee
-
Ivan Kanak
-
ivan.kanak@gmail.com
-
Rémy Oudompheng