Skip to content

Instantly share code, notes, and snippets.

@javatarz
Last active May 9, 2021 07:46
Show Gist options
  • Save javatarz/f1e33a666587f4ade051e725e196742e to your computer and use it in GitHub Desktop.
Save javatarz/f1e33a666587f4ade051e725e196742e to your computer and use it in GitHub Desktop.
Decrypts files encrypted with openssl
#!/bin/bash
set -e
if [ -z "$SECRET_KEY" ]; then
echo "Set a SECRET_KEY for \"$WORKSPACE_NAME\" decryption"
exit 1
fi
function decrypt_file() {
input_file=$1
target_file=${input_file%".enc"}
echo "Decrypting $input_file to $target_file"
openssl enc -aes-256-cbc -d -in $input_file -out $target_file -pass pass:$SECRET_KEY
rm -f $input_file
}
if [ -z $1 ]; then
echo "Usage:"
echo " ./scripts/decrypt.sh <filePathFromProjectRoot>"
echo " ./scripts/decrypt.sh all"
exit 2
elif [ "$1" == "all" ]; then
for input_file in config/$WORKSPACE_NAME/*.tfsecrets.enc
do
decrypt_file $input_file
done
else
decrypt_file $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment