From 8c0f83611eb662be419ac4a1f6af4ae44000e953 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Feb 2026 10:10:19 -0700 Subject: [PATCH] change for slot variables --- .../keepalived/deploy_keepalived.sh | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lxc1/p0-infrastructure/keepalived/deploy_keepalived.sh b/lxc1/p0-infrastructure/keepalived/deploy_keepalived.sh index dbae283..18a4076 100644 --- a/lxc1/p0-infrastructure/keepalived/deploy_keepalived.sh +++ b/lxc1/p0-infrastructure/keepalived/deploy_keepalived.sh @@ -25,34 +25,42 @@ cp "/docker/keepalived/keepalived_header.tpl" "$CONFIG_FILE" sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$CONFIG_FILE" # 3. DUAL-STAGE PARSING -# Split the string into individual slots using the semicolon +# Ensure we are splitting by semicolon IFS=';' read -ra SLOTS <<< "$SLOT_DEFINITIONS" for SLOT in "${SLOTS[@]}"; do - # Split the individual slot by commas - IFS=',' read -r s_num s_name s_dep s_state s_prio s_peer s_vip junk <<< "$SLOT" + # Skip empty slots + [[ -z "$SLOT" ]] && continue + + # Explicitly split the individual slot by commas + # We use a temporary IFS here to avoid leaking it to the rest of the script + s_num=$(echo "$SLOT" | cut -d',' -f1) + s_name=$(echo "$SLOT" | cut -d',' -f2) + s_dep=$(echo "$SLOT" | cut -d',' -f3) + s_state=$(echo "$SLOT" | cut -d',' -f4) + s_prio=$(echo "$SLOT" | cut -d',' -f5) + s_peer=$(echo "$SLOT" | cut -d',' -f6) + s_vip=$(echo "$SLOT" | cut -d',' -f7) [[ -z "$s_num" ]] && continue - echo "Processing Slot $s_num: $s_name (VIP: $s_vip)" + echo "Processing Slot $s_num: $s_name" - TEMP_SLOT="/docker/keepalived/tmp/slot_${s_num}.conf" - cp "/docker/keepalived/keepalived_slot.tpl" "$TEMP_SLOT" + TEMP_SLOT="/tmp/slot_${s_num}.conf" + cp "./keepalived_slot.tpl" "$TEMP_SLOT" - # Generate unique auth pass from the base password AUTH_PASS="${BASE_PASSWORD:0:7}-${s_num}" - # Perform replacements - sed -i "s/{{SLOT_NUM}}/${s_num}/g" "$TEMP_SLOT" - sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$TEMP_SLOT" - sed -i "s/{{SVC_NAME}}/${s_name}/g" "$TEMP_SLOT" - sed -i "s/{{SVC_DEP}}/${s_dep}/g" "$TEMP_SLOT" - sed -i "s/{{STATE}}/${s_state}/g" "$TEMP_SLOT" - sed -i "s/{{PRIORITY}}/${s_prio}/g" "$TEMP_SLOT" - sed -i "s/{{PEER}}/${s_peer}/g" "$TEMP_SLOT" - sed -i "s/{{SVC_VIP}}/${s_vip}/g" "$TEMP_SLOT" - sed -i "s/{{AUTH_PASS}}/${AUTH_PASS}/g" "$TEMP_SLOT" + # Use a different delimiter (|) for sed to avoid issues with potential slashes + sed -i "s|{{SLOT_NUM}}|${s_num}|g" "$TEMP_SLOT" + sed -i "s|{{LXC_NUM}}|${LXC_NUM}|g" "$TEMP_SLOT" + sed -i "s|{{SVC_NAME}}|${s_name}|g" "$TEMP_SLOT" + sed -i "s|{{SVC_DEP}}|${s_dep}|g" "$TEMP_SLOT" + sed -i "s|{{STATE}}|${s_state}|g" "$TEMP_SLOT" + sed -i "s|{{PRIORITY}}|${s_prio}|g" "$TEMP_SLOT" + sed -i "s|{{PEER}}|${s_peer}|g" "$TEMP_SLOT" + sed -i "s|{{SVC_VIP}}|${s_vip}|g" "$TEMP_SLOT" + sed -i "s|{{AUTH_PASS}}|${AUTH_PASS}|g" "$TEMP_SLOT" - # Append to main config and cleanup temp cat "$TEMP_SLOT" >> "$CONFIG_FILE" rm "$TEMP_SLOT" done