1
0
Fork 0
mirror of https://github.com/Mic92/sops-nix.git synced 2024-12-14 11:57:52 +00:00
sops-nix/pkgs/sops-pgp-hook/sops-pgp-hook.bash

33 lines
825 B
Bash
Raw Normal View History

2020-07-06 06:30:09 +00:00
_sopsAddKey() {
@gpg@ --quiet --import "$key"
local fpr
# only add the first fingerprint, this way we ignore subkeys
2020-07-06 06:30:09 +00:00
fpr=$(@gpg@ --with-fingerprint --with-colons --show-key "$key" \
| awk -F: '$1 == "fpr" { print $10; exit }')
2020-07-14 10:20:35 +00:00
if [[ $fpr != "" ]]; then
export SOPS_PGP_FP=''${SOPS_PGP_FP-}''${SOPS_PGP_FP:+','}$fpr
2020-07-14 10:20:35 +00:00
fi
2020-07-06 06:30:09 +00:00
}
2020-07-13 08:51:53 +00:00
sopsPGPHook() {
2020-07-06 06:30:09 +00:00
local key dir
for key in ${sopsPGPKeys-}; do
2020-07-14 10:20:35 +00:00
if [[ -f "$key" ]]; then
_sopsAddKey "$key"
else
echo "$key does not exists" >&2
fi
2020-07-06 06:30:09 +00:00
done
for dir in ${sopsPGPKeyDirs-}; do
2020-07-06 06:30:09 +00:00
while IFS= read -r -d '' key; do
_sopsAddKey "$key"
2020-07-14 10:20:35 +00:00
done < <(find -L "$dir" -type f \( -name '*.gpg' -o -name '*.asc' \) -print0)
2020-07-06 06:30:09 +00:00
done
}
if [ -z "${shellHook-}" ]; then
2020-07-13 08:51:53 +00:00
shellHook=sopsPGPHook
else
shellHook="sopsPGPHook;${shellHook}"
2020-07-06 06:30:09 +00:00
fi