Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #117 from savar/fix_encrypt_helper
Browse files Browse the repository at this point in the history
Fix encrypt helper
  • Loading branch information
mateuszzawisza authored May 21, 2019
2 parents 6abe3db + 9b265bc commit 59c415e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,23 @@ is_help() {
}

encrypt_helper() {
local dir=$(dirname "$1")
local yml=$(basename "$1")
cd "$dir"
[[ -e "$yml" ]] || { echo "File does not exist: $dir/$yml"; exit 1; }
local yml=$1
[[ -e "$yml" ]] || { echo "File does not exist: $yml"; exit 1; }
local ymldec=$(sed -e "s/\\.yaml$/${DEC_SUFFIX}/" <<<"$yml")
[[ -e $ymldec ]] || ymldec="$yml"

if [[ $(grep -C10000 'sops:' "$ymldec" | grep -c 'version:') -gt 0 ]]
then
echo "Already encrypted: $ymldec"
return
echo "Already encrypted: $ymldec"
return
fi
if [[ $yml == $ymldec ]]
then
sops --encrypt --input-type yaml --output-type yaml --in-place "$yml"
echo "Encrypted $yml"
sops --encrypt --input-type yaml --output-type yaml --in-place "$yml"
echo "Encrypted $yml"
else
sops --encrypt --input-type yaml --output-type yaml "$ymldec" > "$yml"
echo "Encrypted $ymldec to $yml"
sops --encrypt --input-type yaml --output-type yaml "$ymldec" > "$yml"
echo "Encrypted $ymldec to $yml"
fi
}

Expand Down

0 comments on commit 59c415e

Please sign in to comment.