apt-key 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. set -e
  3. usage() {
  4. echo "Usage: apt-key [command] [arguments]"
  5. echo
  6. echo "Manage apt's list of trusted keys"
  7. echo
  8. echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)"
  9. echo " apt-key del <keyid> - remove the key <keyid>"
  10. echo " apt-key list - list keys"
  11. echo
  12. }
  13. command="$1"
  14. if [ -z "$command" ]; then
  15. usage
  16. exit 1
  17. fi
  18. shift
  19. if [ "$command" != "help" ] && ! which gpg >/dev/null 2>&1; then
  20. echo >&2 "Warning: gnupg does not seem to be installed."
  21. echo >&2 "Warning: apt-key requires gnupg for most operations."
  22. echo >&2
  23. fi
  24. # We don't use a secret keyring, of course, but gpg panics and
  25. # implodes if there isn't one available
  26. GPG="gpg --no-options --no-default-keyring --keyring /etc/apt/trusted.gpg --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
  27. case "$command" in
  28. add)
  29. $GPG --quiet --batch --import "$1"
  30. echo "OK"
  31. ;;
  32. del|rm|remove)
  33. $GPG --quiet --batch --delete-key --yes "$1"
  34. echo "OK"
  35. ;;
  36. list)
  37. $GPG --batch --list-keys
  38. ;;
  39. finger*)
  40. $GPG --batch --fingerprint
  41. ;;
  42. adv*)
  43. echo "Executing: $GPG $*"
  44. $GPG $*
  45. ;;
  46. help)
  47. usage
  48. ;;
  49. *)
  50. usage
  51. exit 1
  52. ;;
  53. esac