Skip to content

Commit 775a247

Browse files
committed
Safeguard: never remove key that signed last git commit
1 parent ea1cbc2 commit 775a247

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

keys/keys.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env bash
22

33
current_keys="$(gpg --list-keys --with-colons | grep '^pub' | cut -d: -f5)"
4+
last_commit_key_id="$(git log --show-signature | grep "Primary key fingerprint" | head -n 1 | tail -c 20 | tr -d ' ')"
45

56
new_keylist="$(mktemp)"
67
for keyfile in keys/*.asc; do gpg --with-colons "$keyfile" 2>/dev/null | grep '^pub' | cut -d: -f5; done > "$new_keylist"
7-
# Remove keys that are no longer present
8+
# Remove keys that are no longer present.
9+
# But, as a safeguard, never allow removal of key that signed last commit.
810
for key in $current_keys; do
9-
if ! grep -qs "$key" "$new_keylist"; then
11+
if ! grep -qs "$key" "$new_keylist" && [[ "$key" != "$last_commit_key_id" ]]; then
1012
echo "Removing key $key..."
1113
gpg --batch --yes --delete-keys "$key"
1214
fi

0 commit comments

Comments
 (0)