2020-07-06 06:30:09 +00:00
|
|
|
_sopsAddKey() {
|
|
|
|
@gpg@ --quiet --import "$key"
|
|
|
|
local fpr
|
2020-07-22 14:07:51 +00:00
|
|
|
# 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" \
|
2020-07-22 14:07:51 +00:00
|
|
|
| awk -F: '$1 == "fpr" { print $10; exit }')
|
2020-07-14 10:20:35 +00:00
|
|
|
if [[ $fpr != "" ]]; then
|
2021-02-08 20:49:30 +00:00
|
|
|
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
|
2021-02-08 20:49:30 +00:00
|
|
|
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
|
2021-02-08 20:49:30 +00:00
|
|
|
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
|
2021-01-07 14:09:26 +00:00
|
|
|
else
|
|
|
|
shellHook="sopsPGPHook;${shellHook}"
|
2020-07-06 06:30:09 +00:00
|
|
|
fi
|