]>
Commit | Line | Data |
---|---|---|
b3d44315 MV |
1 | #!/bin/sh |
2 | ||
3 | set -e | |
4 | ||
4a242c5b MV |
5 | # We don't use a secret keyring, of course, but gpg panics and |
6 | # implodes if there isn't one available | |
7 | ||
8 | GPG_CMD="gpg --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg" | |
9 | GPG="$GPG_CMD --keyring /etc/apt/trusted.gpg" | |
10 | ||
11 | ||
e004867d MV |
12 | ARCHIVE_KEYRING=/usr/share/keyrings/debian-archive-keyring.gpg |
13 | REMOVED_KEYS=/usr/share/keyrings/debian-archive-removed-keys.gpg | |
4a242c5b MV |
14 | |
15 | ||
16 | update() { | |
17 | if [ ! -f $ARCHIVE_KEYRING ]; then | |
18 | echo >&2 "ERROR: Can't find the archive-keyring" | |
e004867d | 19 | echo >&2 "Is the debian-keyring package installed?" |
4a242c5b MV |
20 | exit 1 |
21 | fi | |
22 | ||
23 | # add new keys | |
1d85c6f4 | 24 | $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --ignore-time-conflict --import |
4a242c5b MV |
25 | |
26 | # remove no-longer used keys | |
32133629 | 27 | keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys|awk '/^pub/{FS=":";print $5}'` |
4a242c5b | 28 | for key in $keys; do |
32133629 MV |
29 | if $GPG --list-keys --with-colons | awk '/^pub/{FS=":";print $5}'|grep -q $key; then |
30 | $GPG --quiet --batch --delete-key --yes ${key} | |
4a242c5b MV |
31 | fi |
32 | done | |
33 | } | |
34 | ||
b3d44315 MV |
35 | usage() { |
36 | echo "Usage: apt-key [command] [arguments]" | |
37 | echo | |
38 | echo "Manage apt's list of trusted keys" | |
39 | echo | |
40 | echo " apt-key add <file> - add the key contained in <file> ('-' for stdin)" | |
41 | echo " apt-key del <keyid> - remove the key <keyid>" | |
4a242c5b | 42 | echo " apt-key update - update keys using the keyring package" |
b3d44315 MV |
43 | echo " apt-key list - list keys" |
44 | echo | |
45 | } | |
46 | ||
47 | command="$1" | |
48 | if [ -z "$command" ]; then | |
49 | usage | |
50 | exit 1 | |
51 | fi | |
52 | shift | |
53 | ||
54 | if [ "$command" != "help" ] && ! which gpg >/dev/null 2>&1; then | |
55 | echo >&2 "Warning: gnupg does not seem to be installed." | |
56 | echo >&2 "Warning: apt-key requires gnupg for most operations." | |
57 | echo >&2 | |
58 | fi | |
59 | ||
b3d44315 MV |
60 | case "$command" in |
61 | add) | |
62 | $GPG --quiet --batch --import "$1" | |
63 | echo "OK" | |
64 | ;; | |
65 | del|rm|remove) | |
66 | $GPG --quiet --batch --delete-key --yes "$1" | |
67 | echo "OK" | |
68 | ;; | |
4a242c5b MV |
69 | update) |
70 | update | |
71 | ;; | |
b3d44315 MV |
72 | list) |
73 | $GPG --batch --list-keys | |
74 | ;; | |
75 | finger*) | |
76 | $GPG --batch --fingerprint | |
77 | ;; | |
78 | adv*) | |
79 | echo "Executing: $GPG $*" | |
80 | $GPG $* | |
81 | ;; | |
82 | help) | |
83 | usage | |
84 | ;; | |
85 | *) | |
86 | usage | |
87 | exit 1 | |
88 | ;; | |
89 | esac |