29 lines
911 B
Bash
29 lines
911 B
Bash
#!/usr/bin/env bash
|
|
# Writes collected ENV_VALUE_* variables to a .env file.
|
|
# Source this file; do not execute it directly.
|
|
# Requires colors.sh to be sourced first.
|
|
|
|
# write_env_file <output_file>
|
|
# Writes all populated ENV_VALUE_<NAME> entries to <output_file>.
|
|
write_env_file() {
|
|
local output_file="$1"
|
|
|
|
{
|
|
printf "# Generated by generate-env on %s\n" "$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
|
printf "\n"
|
|
|
|
local var_name
|
|
for var_name in "${ENV_VARS[@]}"; do
|
|
local desc_var="ENV_DESC_${var_name}"
|
|
local desc="${!desc_var}"
|
|
local value_var="ENV_VALUE_${var_name}"
|
|
local value="${!value_var}"
|
|
[[ -n "$desc" ]] && printf "# %s\n" "$desc"
|
|
printf "%s=%s\n" "$var_name" "$value"
|
|
printf "\n"
|
|
done
|
|
} > "$output_file"
|
|
|
|
printf "\n${GREEN}✓ Written to %s${NC}\n" "$output_file" >&2
|
|
}
|