Skip to content

Commit

Permalink
Trusted key adding / removal via updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsk committed Oct 20, 2024
1 parent 5d850dc commit ea1cbc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ exit_code=0
# defined in the caller script
rootdir="$SYSUPDATES_ROOTDIR"

# keys
printf "######## keys\n" 1>&2
cd "$rootdir"
./keys/keys.sh || exit 1

# base os
printf "######## base os\n" 1>&2
cd "$rootdir"
Expand Down
24 changes: 24 additions & 0 deletions keys/keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

current_keys="$(gpg --list-keys --with-colons | grep '^pub' | cut -d: -f5)"

new_keylist="$(mktemp)"
for keyfile in keys/*.asc; do gpg --with-colons "$keyfile" 2>/dev/null | grep '^pub' | cut -d: -f5; done > "$new_keylist"
# Remove keys that are no longer present
for key in $current_keys; do
if ! grep -qs "$key" "$new_keylist"; then
echo "Removing key $key..."
gpg --batch --yes --delete-keys "$key"
fi
done
rm "$new_keylist"

# Import new keys
for keyfile in keys/*.asc; do
keyid="$(gpg --with-colons "$keyfile" 2>/dev/null | grep '^pub' | cut -d: -f5)"
if ! grep -qs "$keyid" <<< "$current_keys"; then
echo "Importing key $keyid from $keyfile..."
gpg --import "$keyfile"
echo -e "trust\n5\ny\n" | gpg --batch --no-tty --command-fd 0 --expert --edit-key "$keyid"
fi
done

0 comments on commit ea1cbc2

Please sign in to comment.