Fix gpg importer

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-27 18:50:36 +00:00
parent a5f9e6b59a
commit 69578a83fc

View File

@@ -1,12 +1,10 @@
install -d -m 700 "$GNUPGHOME"
for dir in "$HOME"/.config/sops-nix/secrets/gpg/*; do
keyfile="$dir/key"
passfile="$dir/pass"
KEYS="$HOME/.config/sops-nix/secrets/gpg"
if [[ ! -f "$keyfile" ]]; then
continue
fi
import_key() {
local keyfile="$1/key"
local passfile="$1/pass"
if [[ -f "$passfile" ]]; then
gpg2 --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile"
@@ -14,10 +12,20 @@ for dir in "$HOME"/.config/sops-nix/secrets/gpg/*; do
gpg2 --batch --yes --import "$keyfile"
fi
gpg2 --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r key_id; do
echo "$key_id:6:" >> "$GNUPGHOME"/otrust.txt
done
gpg2 --with-colons --import-options show-only --import "$keyfile" \
| grep '^fpr' \
| cut -d: -f10 \
| while read -r key_id; do
echo "$key_id:6:" >> "$GNUPGHOME/otrust.txt"
done
}
if [[ -f "$KEYS/key" ]]; then import_key "$KEYS"; fi
for dir in "$KEYS"/*; do
if [[ ! -d "$dir" ]]; then continue; fi
if [[ -f "$dir/key" ]]; then import_key "$dir"; fi
done
gpg2 --import-ownertrust "$GNUPGHOME"/otrust.txt
rm "$GNUPGHOME"/otrust.txt
gpg2 --import-ownertrust "$GNUPGHOME/otrust.txt"
rm "$GNUPGHOME/otrust.txt"