]> git.saurik.com Git - apt.git/blame - cmdline/apt-key
add missing changelog entry
[apt.git] / cmdline / apt-key
CommitLineData
b3d44315
MV
1#!/bin/sh
2
3set -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
9129f2af 8GPG_CMD="gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg"
4a242c5b
MV
9GPG="$GPG_CMD --keyring /etc/apt/trusted.gpg"
10
11
7ef96224
MV
12ARCHIVE_KEYRING=/usr/share/keyrings/debian-archive-keyring.gpg
13REMOVED_KEYS=/usr/share/keyrings/debian-archive-removed-keys.gpg
4a242c5b
MV
14
15
16update() {
17 if [ ! -f $ARCHIVE_KEYRING ]; then
18 echo >&2 "ERROR: Can't find the archive-keyring"
5fdd72f2 19 echo >&2 "Is the debian-archive-keyring package installed?"
4a242c5b
MV
20 exit 1
21 fi
22
23 # add new keys
9129f2af 24 $GPG_CMD --quiet --batch --keyring $ARCHIVE_KEYRING --export | $GPG --import
4a242c5b
MV
25
26 # remove no-longer used keys
3036f1e4 27 keys=`$GPG_CMD --keyring $REMOVED_KEYS --with-colons --list-keys | grep ^pub | cut -d: -f5`
4a242c5b 28 for key in $keys; do
3036f1e4 29 if $GPG --list-keys --with-colons | grep ^pub | cut -d: -f5 | grep -q $key; then
32133629 30 $GPG --quiet --batch --delete-key --yes ${key}
4a242c5b
MV
31 fi
32 done
33}
34
b3d44315
MV
35usage() {
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>"
bf6d5b42
OS
42 echo " apt-key export <keyid> - output the key <keyid>"
43 echo " apt-key exportall - output all trusted keys"
4a242c5b 44 echo " apt-key update - update keys using the keyring package"
b3d44315
MV
45 echo " apt-key list - list keys"
46 echo
47}
48
49command="$1"
50if [ -z "$command" ]; then
51 usage
52 exit 1
53fi
54shift
55
56if [ "$command" != "help" ] && ! which gpg >/dev/null 2>&1; then
57 echo >&2 "Warning: gnupg does not seem to be installed."
58 echo >&2 "Warning: apt-key requires gnupg for most operations."
59 echo >&2
60fi
61
b3d44315
MV
62case "$command" in
63 add)
64 $GPG --quiet --batch --import "$1"
65 echo "OK"
66 ;;
67 del|rm|remove)
68 $GPG --quiet --batch --delete-key --yes "$1"
69 echo "OK"
70 ;;
4a242c5b
MV
71 update)
72 update
73 ;;
b3d44315
MV
74 list)
75 $GPG --batch --list-keys
76 ;;
77 finger*)
78 $GPG --batch --fingerprint
79 ;;
bf6d5b42
OS
80 export)
81 $GPG --armor --export "$1"
82 ;;
83 exportall)
84 $GPG --armor --export
85 ;;
b3d44315
MV
86 adv*)
87 echo "Executing: $GPG $*"
88 $GPG $*
89 ;;
90 help)
91 usage
92 ;;
93 *)
94 usage
95 exit 1
96 ;;
97esac