fix(env): Enhance environment variable tracking by adding current key presence check
Some checks failed
/ validate-docker-compose (push) Has been cancelled
Some checks failed
/ validate-docker-compose (push) Has been cancelled
This commit is contained in:
parent
73e40af91a
commit
1c5959cafb
@ -55,6 +55,7 @@ cp "$ENV_FILE" "$ENV_BACKUP"
|
|||||||
# Store current env values
|
# Store current env values
|
||||||
echo -e "${BLUE}Reading current environment values...${NC}"
|
echo -e "${BLUE}Reading current environment values...${NC}"
|
||||||
declare -A current_values
|
declare -A current_values
|
||||||
|
declare -A current_keys_present
|
||||||
while IFS='=' read -r key value; do
|
while IFS='=' read -r key value; do
|
||||||
# Skip comments and empty lines
|
# Skip comments and empty lines
|
||||||
if [[ ! "$key" =~ ^#.*$ ]] && [[ ! -z "$key" ]]; then
|
if [[ ! "$key" =~ ^#.*$ ]] && [[ ! -z "$key" ]]; then
|
||||||
@ -66,6 +67,8 @@ while IFS='=' read -r key value; do
|
|||||||
# Store in associative array if key is not empty
|
# Store in associative array if key is not empty
|
||||||
if [[ ! -z "$key" ]]; then
|
if [[ ! -z "$key" ]]; then
|
||||||
current_values["$key"]="$value"
|
current_values["$key"]="$value"
|
||||||
|
# Track that this key existed in original file, regardless of value
|
||||||
|
current_keys_present["$key"]=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done < "$ENV_FILE"
|
done < "$ENV_FILE"
|
||||||
@ -87,19 +90,20 @@ while IFS= read -r line; do
|
|||||||
key="${BASH_REMATCH[1]}"
|
key="${BASH_REMATCH[1]}"
|
||||||
default_value="${BASH_REMATCH[2]}"
|
default_value="${BASH_REMATCH[2]}"
|
||||||
|
|
||||||
# Check if this key exists in current values
|
# Mark the key as used if it exists in the original file
|
||||||
if [[ -n "${current_values[$key]}" ]]; then
|
if [[ -n "${current_keys_present[$key]}" ]]; then
|
||||||
# Replace the line with the current value
|
|
||||||
sed -i "s|^$key=.*$|$key=${current_values[$key]}|" "$ENV_FILE.new"
|
|
||||||
used_keys["$key"]=1
|
used_keys["$key"]=1
|
||||||
else
|
|
||||||
# Mark new keys that need attention (those without default values)
|
# Replace the line with the current value if one exists
|
||||||
if [[ -z "$default_value" ]] || [[ "$default_value" == '""' ]] || [[ "$default_value" == "''" ]]; then
|
if [[ -n "${current_values[$key]}" ]]; then
|
||||||
new_keys+=("$key")
|
sed -i "s|^$key=.*$|$key=${current_values[$key]}|" "$ENV_FILE.new"
|
||||||
fi
|
fi
|
||||||
|
# If key doesn't exist in original file and has empty/placeholder value
|
||||||
|
elif [[ -z "$default_value" ]] || [[ "$default_value" == '""' ]] || [[ "$default_value" == "''" ]]; then
|
||||||
|
new_keys+=("$key")
|
||||||
|
|
||||||
# Special attention for Authelia keys
|
# Special attention for Authelia keys
|
||||||
if [[ "$key" == AUTHELIA_* ]] && [[ -z "$default_value" ]]; then
|
if [[ "$key" == AUTHELIA_*_SECRET* ]] || [[ "$key" == AUTHELIA_*_KEY* ]]; then
|
||||||
special_keys+=("$key")
|
special_keys+=("$key")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user