feat: implement .env
(secrets) loader
This commit is contained in:
parent
f587a7f011
commit
f5a7422f3a
23
load_secrets.sh
Normal file
23
load_secrets.sh
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Get all config files
|
||||||
|
# FILES=$(find . -type f \ # Only files
|
||||||
|
# -wholename "./*/*" \ # Only in subdir
|
||||||
|
# -not -wholename "./.git*" \ # Not in .git/
|
||||||
|
# -not -name "_*.sh" \ # Not _install.sh or _deploy.sh
|
||||||
|
# -not -name "README.md") # Not README.md
|
||||||
|
|
||||||
|
FILES=$(find . -type f -wholename "./*/*" -not -wholename "./.git*" -not -name "_*.sh" -not -name "README.md")
|
||||||
|
|
||||||
|
cat .env | grep ".=." > .env.tmp # Clean .env entries
|
||||||
|
readarray -t SECRETS < .env.tmp # Get all .env entries
|
||||||
|
rm .env.tmp # Clean tmp file
|
||||||
|
|
||||||
|
for file in $FILES
|
||||||
|
do
|
||||||
|
for secret in "${SECRETS[@]}"
|
||||||
|
do
|
||||||
|
KEY=$(echo $secret | grep -o "\w\+")
|
||||||
|
VALUE=$(echo $secret | grep -oP '\w+\s*=\s*\K.*' | tr -d "\r")
|
||||||
|
|
||||||
|
sed -r "s/\{\{\s*$KEY\s*\}\}/$VALUE/g" $file
|
||||||
|
done
|
||||||
|
done
|
Loading…
Reference in a new issue