Update multiplane.sh

This commit is contained in:
2026-01-19 18:42:39 +00:00
parent f204134d7d
commit 33a34b8f33

View File

@@ -2,7 +2,7 @@
set -e
CONFIG_FILE="${1:-config-test.yaml}"
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."
@@ -101,85 +101,113 @@ get_ipv4_address() {
done
}
clear; echo "Enter a cluster hostname. (e.g., cluster.local)";
HOSTNAME=$(gum input --placeholder "cluster.local" --prompt "* " --width 80 --value "$(yq '.k0s.hostname' $CONFIG_FILE)") && yq -i -oy ".k0s.hostname = \"$HOSTNAME\"" "$CONFIG_FILE" || exit 0
config_setup() {
clear; echo "Enter a cluster IP subnet. (e.g., 10.1.0.0/24)";
PRIVATE_IP_RANGE=$(gum input --placeholder "10.1.0.0/24" --prompt "* " --width 80 --value "$(yq '.k0s.private_ip_range' $CONFIG_FILE)") && yq -i -oy ".k0s.private_ip_range = \"$PRIVATE_IP_RANGE\"" "$CONFIG_FILE" || exit 0
clear; echo "Enter a cluster hostname. (e.g., cluster.local)";
HOSTNAME=$(gum input --placeholder "cluster.local" --prompt "* " --width 80 --value "$(yq '.k0s.hostname' $CONFIG_FILE)") && yq -i -oy ".k0s.hostname = \"$HOSTNAME\"" "$CONFIG_FILE" || exit 0
clear; echo "Enter a public IP subnet. (e.g., 192.168.0.0/24)";
PUBLIC_IP_RANGE=$(gum input --placeholder "192.168.0.0/24" --prompt "* " --width 80 --value "$(yq '.k0s.public_ip_range' $CONFIG_FILE)") && yq -i -oy ".k0s.public_ip_range = \"$PUBLIC_IP_RANGE\"" "$CONFIG_FILE" || exit 0
clear; echo "Enter a cluster IP subnet. (e.g., 10.1.0.0/24)";
PRIVATE_IP_RANGE=$(gum input --placeholder "10.1.0.0/24" --prompt "* " --width 80 --value "$(yq '.k0s.private_ip_range' $CONFIG_FILE)") && yq -i -oy ".k0s.private_ip_range = \"$PRIVATE_IP_RANGE\"" "$CONFIG_FILE" || exit 0
# Initialize array to store entries
declare -a entries
clear; echo "Enter a public IP subnet. (e.g., 192.168.0.0/24)";
PUBLIC_IP_RANGE=$(gum input --placeholder "192.168.0.0/24" --prompt "* " --width 80 --value "$(yq '.k0s.public_ip_range' $CONFIG_FILE)") && yq -i -oy ".k0s.public_ip_range = \"$PUBLIC_IP_RANGE\"" "$CONFIG_FILE" || exit 0
# Proxy node entry (2 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Configuration (2 Required)"; sleep 0.5
# Initialize array to store entries
declare -a entries
trap 'clear; echo -e "\nExiting..."; exit 130' INT
for i in 1 2; do
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Node $i/2"
# Proxy node entry (2 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Configuration (2 Required)"; sleep 0.5
# Get MAC address
mac=$(get_mac_address ".haproxy.proxy.$i.mac") || exit 130
trap 'clear; echo -e "\nExiting..."; exit 130' INT
for i in 1 2; do
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Node $i/2"
# Get IPv4 address
ip=$(get_ipv4_address ".haproxy.proxy.$i.ip") || exit 130
# Get MAC address
mac=$(get_mac_address ".haproxy.proxy.$i.mac") || exit 130
# Add entry using yq
yq -i -oy ".haproxy.proxy.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
done
trap - INT
# Get IPv4 address
ip=$(get_ipv4_address ".haproxy.proxy.$i.ip") || exit 130
clear; echo "HAProxy Kuberenetes VIP. (e.g., 10.1.0.10)";
HAPROXY_KUBE_VIP=$(gum input --placeholder "10.1.0.10" --prompt "* " --width 80 --value "$(yq '.haproxy.kube.vip' $CONFIG_FILE)") && yq -i -oy ".haproxy.kube.vip = \"$HAPROXY_KUBE_VIP\"" "$CONFIG_FILE" || exit 0
# Add entry using yq
yq -i -oy ".haproxy.proxy.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
done
trap - INT
# Controller node entry (3 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Controller Node Configuration (3 Required)"; sleep 0.5
clear; echo "HAProxy Kuberenetes VIP. (e.g., 10.1.0.10)";
HAPROXY_KUBE_VIP=$(gum input --placeholder "10.1.0.10" --prompt "* " --width 80 --value "$(yq '.haproxy.kube.vip' $CONFIG_FILE)") && yq -i -oy ".haproxy.kube.vip = \"$HAPROXY_KUBE_VIP\"" "$CONFIG_FILE" || exit 0
trap 'clear; echo -e "\nExiting..."; exit 130' INT
for i in 1 2 3; do
clear; gum style --border double --padding "1 2" --border-foreground 212 "Controller Node $i/3"
# Controller node entry (3 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Controller Node Configuration (3 Required)"; sleep 0.5
# Get MAC address
mac=$(get_mac_address ".nodes.controller.$i.mac") || exit 130
trap 'clear; echo -e "\nExiting..."; exit 130' INT
for i in 1 2 3; do
clear; gum style --border double --padding "1 2" --border-foreground 212 "Controller Node $i/3"
# Get IPv4 address
ip=$(get_ipv4_address ".nodes.controller.$i.ip") || exit 130
# Get MAC address
mac=$(get_mac_address ".nodes.controller.$i.mac") || exit 130
# Add entry using yq
yq -i -oy ".nodes.controller.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
done
trap - INT
# Get IPv4 address
ip=$(get_ipv4_address ".nodes.controller.$i.ip") || exit 130
# Controller node entry (3 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Configuration (3 Required)"; sleep 0.5
# Add entry using yq
yq -i -oy ".nodes.controller.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
done
trap - INT
# Add worker node loop
count=1
trap 'clear; echo -e "\nExiting..."; exit 130' INT
while [ $count -lt 250 ]; do
# Ask to continue
if [ $count -gt 3 ]; then
clear; gum confirm "Add another worker node?" || break
# Controller node entry (3 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Configuration (3 Required)"; sleep 0.5
# Add worker node loop
count=1
trap 'clear; echo -e "\nExiting..."; exit 130' INT
while [ $count -lt 250 ]; do
# Ask to continue
if [ $count -gt 3 ]; then
clear; gum confirm "Add another worker node?" || break
fi
clear; gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Entry ($((count))/250)"
# Get MAC address
mac=$(get_mac_address ".nodes.worker.$count.mac") || exit 130
# Get IPv4 address
ip=$(get_ipv4_address ".nodes.worker.$count.ip") || exit 130
# Add entry using yq
yq -i -oy ".nodes.worker.$count = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
count=$((count + 1))
done
trap - INT
# Display results
if [ $count -gt 0 ]; then
clear; gum style --border double --padding "1 2" --border-foreground 212 "✓ Configuration saved to $CONFIG_FILE"
fi
clear; gum style --border double --padding "1 2" --border-foreground 212 "Worker Node Entry ($((count))/250)"
}
# Get MAC address
mac=$(get_mac_address ".nodes.worker.$count.mac") || exit 130
main() {
# Choices List
CHOICE=$(gum choose --header "Select a function to run:" --cursor "> " --height 10 "Configuration Setup" "Exit")
# Get IPv4 address
ip=$(get_ipv4_address ".nodes.worker.$count.ip") || exit 130
# Execute based on selection
case "$CHOICE" in
"Configuration Setup")
config_setup
;;
"Exit")
echo "Exiting..."
exit 0
;;
*)
echo "No selection made"
exit 1
;;
esac
# Add entry using yq
yq -i -oy ".nodes.worker.$count = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
}
count=$((count + 1))
done
trap - INT
# Display results
if [ $count -gt 0 ]; then
clear; gum style --border double --padding "1 2" --border-foreground 212 "✓ Configuration saved to $CONFIG_FILE"
fi
main