final commit before setup refactoring

This commit is contained in:
cortex
2026-05-20 15:17:30 +01:00
parent 4763fde62e
commit fe775ca1c2
4 changed files with 100 additions and 33 deletions
+45 -2
View File
@@ -51,8 +51,9 @@ write_state() {
local value="$2"
local init_file="${INIT_DIR}/init.ini"
local upper_value
upper_key=$(echo "$key" | tr '[:lower:]' '[:upper:]')
upper_value=$(echo "$value" | tr '[:lower:]' '[:upper:]')
echo "${key}=${upper_value}" >> "$init_file"
echo "${upper_key}=${upper_value}" >> "$init_file"
}
load_state() {
@@ -64,6 +65,31 @@ load_state() {
fi
}
toggle_block() {
local target_file="$1"
local start_marker="$2"
local end_marker="$3"
local keep_markers="$4" # "true" or "false"
if [[ -z "$target_file" ]]; then
echo "Error: Output file path is required for toggle_block." >&2
return 1
fi
if [[ ! -f "$target_file" ]]; then
echo "Error: Target file '$target_file' not found." >&2
return 1
fi
if [[ "$keep_markers" == "true" ]]; then
# Remove lines containing markers individually
sed -i "/${start_marker}/d; /${end_marker}/d" "$target_file"
else
# Remove block from start to end
sed -i "/${start_marker},/${end_marker}/d" "$target_file"
fi
}
clear_state() {
local init_file="${INIT_DIR}/init.ini"
> "$init_file"
@@ -110,7 +136,6 @@ prompt_var() {
final_value="$input"
fi
# Escape special characters for .env file
final_value="${final_value//\\/\\\\}"
final_value="${final_value//\"/\\\"}"
final_value="${final_value//\$/\\\$}"
@@ -119,6 +144,24 @@ prompt_var() {
echo "${var_name}=\"${final_value}\"" >> "$ENV_FILE"
}
auto_var() {
local name="$1"
local default="$2"
local is_pass="$3"
if [[ "$is_pass" == "yes" ]]; then
local secret
secret=$(generate_secret 32)
echo "${name}=\"${secret}\"" >> "$ENV_FILE"
log_info " Generated ${name}"
else
echo "${name}=\"${default}\"" >> "$ENV_FILE"
log_info " Set ${name} to default: ${default}"
fi
}
# --- File Permissions ---
fix_ownership() {
local target="$1"