feat: cleanup setup into sub-modules

This commit is contained in:
uprightbass360
2026-01-20 19:11:29 -05:00
parent f4e88abde8
commit 9d8a089b00
20 changed files with 2019 additions and 2075 deletions

View File

@@ -127,17 +127,23 @@ read_env() {
}
# Read value from .env.template file (used during setup)
# This is similar to read_env but specifically for template files
# This is similar to read_env but specifically for template files.
#
# Usage:
# get_template_value KEY [TEMPLATE_FILE]
# get_template_value KEY [TEMPLATE_FILE] [DEFAULT]
# value=$(get_template_value "MYSQL_PASSWORD")
# value=$(get_template_value "DOCKER_IMAGE_TAG" ".env.template" "latest")
#
get_template_value() {
local key="$1"
local template_file="${2:-${TEMPLATE_FILE:-${TEMPLATE_PATH:-.env.template}}}"
local fallback="${3:-}"
if [ ! -f "$template_file" ]; then
if [ -n "$fallback" ]; then
echo "$fallback"
return 0
fi
fatal "Template file not found: $template_file"
fi
@@ -147,8 +153,11 @@ get_template_value() {
raw_line=$(grep "^${key}=" "$template_file" 2>/dev/null | head -1)
if [ -z "$raw_line" ]; then
err "Key '$key' not found in template: $template_file"
return 1
if [ -n "$fallback" ]; then
echo "$fallback"
return 0
fi
fatal "Key '$key' not found in template: $template_file"
fi
value="${raw_line#*=}"
@@ -159,6 +168,10 @@ get_template_value() {
value="${BASH_REMATCH[1]}"
fi
if [ -z "$value" ] && [ -n "$fallback" ]; then
value="$fallback"
fi
echo "$value"
}