change for slot variables
This commit is contained in:
parent
99c7520536
commit
8c0f83611e
1 changed files with 26 additions and 18 deletions
|
|
@ -25,34 +25,42 @@ cp "/docker/keepalived/keepalived_header.tpl" "$CONFIG_FILE"
|
||||||
sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$CONFIG_FILE"
|
sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$CONFIG_FILE"
|
||||||
|
|
||||||
# 3. DUAL-STAGE PARSING
|
# 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"
|
IFS=';' read -ra SLOTS <<< "$SLOT_DEFINITIONS"
|
||||||
|
|
||||||
for SLOT in "${SLOTS[@]}"; do
|
for SLOT in "${SLOTS[@]}"; do
|
||||||
# Split the individual slot by commas
|
# Skip empty slots
|
||||||
IFS=',' read -r s_num s_name s_dep s_state s_prio s_peer s_vip junk <<< "$SLOT"
|
[[ -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
|
[[ -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"
|
TEMP_SLOT="/tmp/slot_${s_num}.conf"
|
||||||
cp "/docker/keepalived/keepalived_slot.tpl" "$TEMP_SLOT"
|
cp "./keepalived_slot.tpl" "$TEMP_SLOT"
|
||||||
|
|
||||||
# Generate unique auth pass from the base password
|
|
||||||
AUTH_PASS="${BASE_PASSWORD:0:7}-${s_num}"
|
AUTH_PASS="${BASE_PASSWORD:0:7}-${s_num}"
|
||||||
|
|
||||||
# Perform replacements
|
# 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|{{SLOT_NUM}}|${s_num}|g" "$TEMP_SLOT"
|
||||||
sed -i "s/{{LXC_NUM}}/${LXC_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_NAME}}|${s_name}|g" "$TEMP_SLOT"
|
||||||
sed -i "s/{{SVC_DEP}}/${s_dep}/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|{{STATE}}|${s_state}|g" "$TEMP_SLOT"
|
||||||
sed -i "s/{{PRIORITY}}/${s_prio}/g" "$TEMP_SLOT"
|
sed -i "s|{{PRIORITY}}|${s_prio}|g" "$TEMP_SLOT"
|
||||||
sed -i "s/{{PEER}}/${s_peer}/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|{{SVC_VIP}}|${s_vip}|g" "$TEMP_SLOT"
|
||||||
sed -i "s/{{AUTH_PASS}}/${AUTH_PASS}/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"
|
cat "$TEMP_SLOT" >> "$CONFIG_FILE"
|
||||||
rm "$TEMP_SLOT"
|
rm "$TEMP_SLOT"
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue