Update multiplane.sh

This commit is contained in:
2026-01-19 20:42:07 +00:00
parent 33a34b8f33
commit 4bc1b9a99b

View File

@@ -3,6 +3,8 @@
set -e
CONFIG_FILE="${1:-config.yaml}"
STYLE_SETTING1="--width 80 --cursor.foreground 220 --prompt.foreground 220"
STYLE_SETTING2="--width 80 --border-foreground 220"
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."
@@ -58,12 +60,12 @@ get_mac_address() {
while true; do
if [[ -z "$io" ]]; then
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" --width 80) || exit 130
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" $STYLE_SETTING1) || exit 130
else
if [[ -z "$(yq $io $CONFIG_FILE)" ]]; then
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" --width 80) || exit 130
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" $STYLE_SETTING1) || exit 130
else
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" --width 80 --value "$(yq $io $CONFIG_FILE)") && yq -i -oy "$io = \"$mac\"" "$CONFIG_FILE" || exit 130
mac=$(gum input --placeholder "MAC Address (e.g., BC:24:AC:76:96:DE)" $STYLE_SETTING1 --value "$(yq $io $CONFIG_FILE)") && yq -i -oy "$io = \"$mac\"" "$CONFIG_FILE" || exit 130
fi
fi
@@ -83,12 +85,12 @@ get_ipv4_address() {
while true; do
if [[ -z "$io" ]]; then
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14)" --width 80) || exit 130
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14)" $STYLE_SETTING1) || exit 130
else
if [[ -z "$(yq $io $CONFIG_FILE)" ]]; then
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14)" --width 80) || exit 130
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14)" $STYLE_SETTING1) || exit 130
else
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14))" --width 80 --value "$(yq $io $CONFIG_FILE)") && yq -i -oy "$io = \"$ip\"" "$CONFIG_FILE" || exit 130
ip=$(gum input --placeholder "IPv4 Address (e.g., 10.1.0.14))" $STYLE_SETTING1 --value "$(yq $io $CONFIG_FILE)") && yq -i -oy "$io = \"$ip\"" "$CONFIG_FILE" || exit 130
fi
fi
@@ -104,23 +106,23 @@ get_ipv4_address() {
config_setup() {
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
HOSTNAME=$(gum input --placeholder "cluster.local" --prompt "* " $STYLE_SETTING1 --value "$(yq '.k0s.hostname' $CONFIG_FILE)") && yq -i -oy ".k0s.hostname = \"$HOSTNAME\"" "$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
PRIVATE_IP_RANGE=$(gum input --placeholder "10.1.0.0/24" --prompt "* " $STYLE_SETTING1 --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 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
PUBLIC_IP_RANGE=$(gum input --placeholder "192.168.0.0/24" --prompt "* " $STYLE_SETTING1 --value "$(yq '.k0s.public_ip_range' $CONFIG_FILE)") && yq -i -oy ".k0s.public_ip_range = \"$PUBLIC_IP_RANGE\"" "$CONFIG_FILE" || exit 0
# Initialize array to store entries
declare -a entries
# Proxy node entry (2 nodes required)
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Configuration (2 Required)"; sleep 0.5
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "Proxy Configuration (2 Required)"; gum spin --spinner dot --title "Waiting..." -- sleep 2
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"
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "Proxy Node $i/2"
# Get MAC address
mac=$(get_mac_address ".haproxy.proxy.$i.mac") || exit 130
@@ -134,14 +136,14 @@ config_setup() {
trap - INT
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
HAPROXY_KUBE_VIP=$(gum input --placeholder "10.1.0.10" --prompt "* " $STYLE_SETTING1 --value "$(yq '.haproxy.kube.vip' $CONFIG_FILE)") && yq -i -oy ".haproxy.kube.vip = \"$HAPROXY_KUBE_VIP\"" "$CONFIG_FILE" || exit 0
# 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; gum style --border double --padding "1 2" $STYLE_SETTING2 "Controller Node Configuration (3 Required)"; gum spin --spinner dot --title "Waiting..." -- sleep 2
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"
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "Controller Node $i/3"
# Get MAC address
mac=$(get_mac_address ".nodes.controller.$i.mac") || exit 130
@@ -155,7 +157,7 @@ config_setup() {
trap - INT
# 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
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "Worker Node Configuration (3 Required)"; gum spin --spinner dot --title "Waiting..." -- sleep 2
# Add worker node loop
count=1
@@ -166,7 +168,7 @@ config_setup() {
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)"
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "Worker Node Entry ($((count))/250)"
# Get MAC address
mac=$(get_mac_address ".nodes.worker.$count.mac") || exit 130
@@ -181,23 +183,50 @@ config_setup() {
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
gum confirm "Check configuration file?" && gum pager < $CONFIG_FILE
clear; gum style --border double --padding "1 2" $STYLE_SETTING2 "✓ Configuration saved to $CONFIG_FILE"
}
swab_the_decks() {
exit 0
}
upgrades_everyone_upgrades() {
exit 0
}
your_good_your_good_your_good_and_stop() {
exit 0
}
thatll_buff_right_out_captin() {
exit 0
}
main() {
# Choices List
CHOICE=$(gum choose --header "Select a function to run:" --cursor "> " --height 10 "Configuration Setup" "Exit")
CHOICE=$(gum choose --header "Select a function to run:" --cursor "> " --height 10 --cursor.foreground 220 --header.foreground 220 "Configuration Setup" "Run Maintenance Tasks" "Run Cluster Upgrade" "Backup Cluster Configuration" "Restore Cluster Configuration" "Exit")
# Execute based on selection
case "$CHOICE" in
"Configuration Setup")
config_setup
;;
"Run Maintenance Tasks")
swab_the_decks
;;
"Run Cluster Upgrade")
upgrades_everyone_upgrades
;;
"Backup Cluster Configuration")
your_good_your_good_your_good_and_stop
;;
"Restore Cluster Configuration")
thatll_buff_right_out_captin
;;
"Exit")
echo "Exiting..."
exit 0