X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/0cfec3ab589c6309bf284438d2148c7742cdaf10..5404685b66b92f93da7ded5f8fe44fbabea38ba4:/cmdline/apt-key.in diff --git a/cmdline/apt-key.in b/cmdline/apt-key.in index ede6be4c3..0f9118492 100644 --- a/cmdline/apt-key.in +++ b/cmdline/apt-key.in @@ -23,6 +23,7 @@ requires_root() { } command_available() { + if [ -x "$1" ]; then return 0; fi # command -v "$1" >/dev/null 2>&1 # not required by policy, see #747320 # which "$1" >/dev/null 2>&1 # is in debianutils (essential) but not on non-debian systems local OLDIFS="$IFS" @@ -155,6 +156,13 @@ net_update() { } update() { + if [ -z "$APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE" ]; then + echo >&2 "Warning: 'apt-key update' is deprecated and should not be used anymore!" + if [ -z "$ARCHIVE_KEYRING" ]; then + echo >&2 "Note: In your distribution this command is a no-op and can therefore be removed safely." + exit 0 + fi + fi if [ ! -f "$ARCHIVE_KEYRING" ]; then echo >&2 "ERROR: Can't find the archive-keyring" echo >&2 "Is the &keyring-package; package installed?" @@ -472,6 +480,14 @@ if [ -z "$command" ]; then fi shift +cleanup_gpg_home() { + if [ -z "$GPGHOMEDIR" ]; then return; fi + if command_available 'gpgconf'; then + GNUPGHOME="${GPGHOMEDIR}" gpgconf --kill gpg-agent >/dev/null 2>&1 || true + fi + rm -rf "$GPGHOMEDIR" +} + create_gpg_home() { # gpg needs (in different versions more or less) files to function correctly, # so we give it its own homedir and generate some valid content for it later on @@ -483,8 +499,12 @@ create_gpg_home() { fi fi GPGHOMEDIR="$(mktemp -d)" - CURRENTTRAP="${CURRENTTRAP} rm -rf '$(escape_shell "${GPGHOMEDIR}")';" + CURRENTTRAP="${CURRENTTRAP} cleanup_gpg_home;" trap "${CURRENTTRAP}" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM + if [ -z "$GPGHOMEDIR" ]; then + echo "ERROR: Could not create temporary gpg home directory in apt-key ($TMPDIR)" + exit 28 + fi chmod 700 "$GPGHOMEDIR" } @@ -493,7 +513,7 @@ prepare_gpg_home() { # package depends on gnupg or not. We accept recommends here as # well as the script hopefully uses apt-key optionally then like e.g. # debian-archive-keyring for (upgrade) cleanup did - if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then + if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] && [ -z "$APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE" ]; then if ! dpkg-query --show --showformat '${Pre-Depends}${Depends}${Recommends}\n' "$DPKG_MAINTSCRIPT_PACKAGE" 2>/dev/null | grep -q gnupg; then cat >&2 <&2 "Warning: apt-key should not be used in scripts (called from $DPKG_MAINTSCRIPT_NAME maintainerscript of the package ${DPKG_MAINTSCRIPT_PACKAGE})" + elif [ ! -t 1 ]; then + echo >&2 "Warning: apt-key output should not be parsed (stdout is not a terminal)" + fi +} + if [ "$command" != 'help' ] && [ "$command" != 'verify' ]; then prepare_gpg_home fi case "$command" in add) + warn_on_script_usage requires_root setup_merged_keyring aptkey_execute "$GPG" --quiet --batch --import "$@" @@ -566,11 +599,13 @@ case "$command" in aptkey_echo "OK" ;; del|rm|remove) + # no script warning here as removing 'add' usage needs 'del' for cleanup requires_root foreach_keyring_do 'remove_key_from_keyring' "$@" aptkey_echo "OK" ;; update) + warn_on_script_usage requires_root setup_merged_keyring update @@ -582,17 +617,17 @@ case "$command" in net_update merge_back_changes ;; - list) - foreach_keyring_do 'run_cmd_on_keyring' --list-keys "$@" - ;; - finger*) + list|finger*) + warn_on_script_usage foreach_keyring_do 'run_cmd_on_keyring' --fingerprint "$@" ;; export|exportall) + warn_on_script_usage merge_all_trusted_keyrings_into_pubring aptkey_execute "$GPG_SH" --keyring "${GPGHOMEDIR}/pubring.gpg" --armor --export "$@" ;; adv*) + warn_on_script_usage setup_merged_keyring aptkey_echo "Executing: $GPG $*" aptkey_execute "$GPG" "$@"