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