summaryrefslogtreecommitdiff
path: root/localgpgcleankeyring
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2015-08-06 13:14:57 +0200
committerJonas Smedegaard <dr@jones.dk>2015-08-06 13:14:57 +0200
commite038a36b16ba7a10e1a591eb6e622f3bb75d73f7 (patch)
tree77a54831d43496c7616209e5e3ebd9205f145ca2 /localgpgcleankeyring
parent4885fc7dcf7ab4055dcb95045dc2c3dc2e75ecd2 (diff)
Add localgpgcleankeyring from <https://scruss.com/blog/2013/05/12/clean-up-your-gnupg-keyring/>.
Diffstat (limited to 'localgpgcleankeyring')
-rwxr-xr-xlocalgpgcleankeyring39
1 files changed, 39 insertions, 0 deletions
diff --git a/localgpgcleankeyring b/localgpgcleankeyring
new file mode 100755
index 0000000..0662135
--- /dev/null
+++ b/localgpgcleankeyring
@@ -0,0 +1,39 @@
+#!/bin/bash
+# clean_keyring.sh - clean up all the excess keys
+
+# origin: https://scruss.com/blog/2013/05/12/clean-up-your-gnupg-keyring/
+
+# my key should probably be the first secret key listed
+mykey=$(gpg --list-secret-keys | grep '^sec' | cut -c 13-20 | head -1)
+if
+ [ -z $mykey ]
+then
+ # exit if no key string
+ echo "Can't get user's key ID"
+ exit 1
+fi
+
+# all of the people who have signed my key
+mysigners=$(gpg --list-sigs $mykey | grep '^sig' | cut -c 14-21 | sort -u)
+
+# keep all of the signers, plus my key (if I haven't self-signed)
+keepers=$(echo $mykey $mysigners | tr ' ' '\012' | sort -u)
+
+# the keepers list in egrep syntax: ^(key|key|…)
+keepers_egrep=$(echo $keepers | sed 's/^/^(/; s/$/)/; s/ /|/g;')
+
+# show all the keepers as a comment so this script's output is shell-able
+echo '# Keepers: ' $keepers
+
+# everyone who isn't on the keepers list is deleted
+deleters=$(gpg --list-keys | grep '^pub'| cut -c 13-20 | egrep -v ${keepers_egrep})
+
+# echo the command if there are any to delete
+# command is interactive
+if
+ [ -z $deleters ]
+then
+ echo "# Nothing to delete!"
+else
+ echo 'gpg --delete-keys' $deleters
+fi