added automatic Key Generation for Empty .env Keys

This commit is contained in:
2025-12-03 20:38:40 +01:00
parent 61d94a264f
commit 14b3eb4559
9 changed files with 106 additions and 329 deletions

View File

@@ -1,5 +1,7 @@
#!/bin/bash
SETUP_DIR=$PWD
# check if FAST_PATH is set, if not exit with a message
if [ -z "$FAST_PATH" ]; then
echo "FAST_PATH is not set."
@@ -15,7 +17,7 @@ cd $FAST_PATH
ENV_FILE=".env"
# Define the keywords to look for (case-insensitive search for the value part)
KEYWORDS="(key|user|password|email)"
KEYWORDS="(KEY|USER|PASSWORD|EMAIL)"
# Define the secure placeholder value for non-interactive mode
SECURE_PLACEHOLDER="REPLACED_BY_SCRIPT"
@@ -63,7 +65,7 @@ while IFS= read -r line; do
VAR_VALUE_LOWER=$(echo "$VAR_VALUE_CLEANED" | tr '[:upper:]' '[:lower:]')
# 3. Check if the value contains a sensitive keyword
if [[ "$VAR_VALUE_LOWER" =~ $KEYWORDS ]]; then
if [[ "$VAR_NAME" =~ $KEYWORDS ]]; then
echo -e "\n⚠ Sensitive variable found: **$VAR_NAME**"
echo "Current value: $VAR_VALUE_RAW"
@@ -77,8 +79,15 @@ while IFS= read -r line; do
# if user entered an empty value, use the original value
if [ -z "$NEW_VALUE" ]; then
NEW_VALUE="$VAR_VALUE_CLEANED"
echo "No input provided. Keeping original value."
if [ -z "$VAR_VALUE_CLEANED" ]; then
echo "Original value is empty. Generating a new secure key using bin/create_key..."
NEW_VALUE=$($SETUP_DIR/bin/create_key.sh)
echo "Generated Key: $NEW_VALUE"
else
NEW_VALUE="$VAR_VALUE_CLEANED"
echo "No input provided. Keeping original value."
fi
fi
# Add quotes if value contains spaces