Update multiplane.sh

This commit is contained in:
2026-01-19 16:09:41 +00:00
parent 97e46b8c33
commit 89b81812b0

View File

@@ -2,7 +2,7 @@
set -e
CONFIG_FILE="${1:-config.toml}"
CONFIG_FILE="${1:-config.yaml}"
if [[ "$EUID" -ne 0 ]]; then
echo -e "\e[31m[FATAL]\e[39m Currently this script requires being ran as root user - please try again as root."
@@ -51,45 +51,75 @@ validate_ipv4() {
return 1
}
yq -i -o toml ".k0s.hostname = \"$(gum input --placeholder "Cluster Domain:" --prompt "* " --width 80 --value "$(yq '.k0s.hostname' $CONFIG_FILE)")\"" "$CONFIG_FILE"
yq -i -o toml ".k0s.private_ip_range = \"$(gum input --placeholder "Node IP Range::" --prompt "* " --width 80 --value "$(yq '.k0s.private_ip_range' $CONFIG_FILE)")\"" "$CONFIG_FILE"
# Initialize array to store entries
declare -a entries
# Add worker node loop
count=0
while [ $count -lt 250 ]; do
gum style --border double --padding "1 2" --border-foreground 212 \
"Worker Node Entry ($(($count + 1))/250)"
# Get MAC address with validation loop
# Function to get and validate MAC address
get_mac_address() {
local mac
while true; do
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)")
[ -z "$mac" ] && break 2
if validate_mac "$mac"; then
echo "$mac"
break
else
gum style --foreground 196 "Invalid MAC address format. Use XX:XX:XX:XX:XX:XX"
fi
done
}
# Get IPv4 address with validation loop
# Function to get and validate IPv4 address
get_ipv4_address() {
local ip
while true; do
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14)")
[ -z "$ip" ] && break 2
if validate_ipv4 "$ip"; then
echo "$ip"
break
else
gum style --foreground 196 "Invalid IPv4 address format"
fi
done
}
yq -i -oy ".k0s.hostname = \"$(gum input --placeholder "Cluster Domain:" --prompt "* " --width 80 --value "$(yq '.k0s.hostname' $CONFIG_FILE)")\"" "$CONFIG_FILE"
yq -i -oy ".k0s.private_ip_range = \"$(gum input --placeholder "Node IP Range::" --prompt "* " --width 80 --value "$(yq '.k0s.private_ip_range' $CONFIG_FILE)")\"" "$CONFIG_FILE"
# Initialize array to store entries
declare -a entries
# Controller node entry (3 nodes required)
gum style --border double --padding "1 2" --border-foreground 212 "Controller Node Configuration (3 Required)"
for i in 1 2 3; do
gum style --border double --padding "1 2" --border-foreground 212 "Controller Node $i/3"
# Get MAC address
mac=$(get_mac_address)
# Get IPv4 address
ip=$(get_ipv4_address)
# Add entry using yq
((count++))
yq -i -o toml ".nodes.worker.$count = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
yq -i -oy ".nodes.controller.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
done
# Controller node entry (3 nodes required)
gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Configuration (2 Required)"
# Add worker node loop
count=0
while [ $count -lt 250 ]; do
gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Entry ($(($count + 1))/250)"
# Get MAC address
mac=$(get_mac_address)
# Get IPv4 address
ip=$(get_ipv4_address)
# Add entry using yq
count=$((count+1))
yq -i -oy ".nodes.worker.$count = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
# Ask to continue
if [ $count -lt 250 ]; then