Fix .env file parsing errors with better validation and error handling

This commit is contained in:
Andreas Dueren
2025-07-15 13:41:35 -06:00
parent 65cd9a73bb
commit 34ef0803d8
2 changed files with 44 additions and 4 deletions

View File

@@ -102,9 +102,19 @@ fi
# Load custom environment variables if they exist
if [ -f "/app/data/.env" ]; then
echo "=> Loading custom environment variables from /app/data/.env"
set -a # automatically export all variables
source /app/data/.env
set +a # stop automatically exporting
# Validate .env file format before sourcing
if grep -q "^[[:space:]]*[^#][^=]*=" /app/data/.env 2>/dev/null; then
set -a # automatically export all variables
if source /app/data/.env 2>/dev/null; then
echo "=> Custom .env file loaded successfully"
else
echo "=> Warning: Error loading .env file, using Cloudron defaults"
echo "=> Check /app/data/.env for syntax errors (values with spaces need quotes)"
fi
set +a # stop automatically exporting
else
echo "=> Warning: /app/data/.env appears to be empty or invalid, using Cloudron defaults"
fi
else
echo "=> No custom .env file found, using Cloudron defaults"
fi