159 lines
4.6 KiB
Bash
159 lines
4.6 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
CONFIG_FILE="${1:-config-test.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."
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "\n\nINSTALL LOG: $(date --rfc-3339=seconds)\n" >> /tmp/multiplane.log
|
|
|
|
info() {
|
|
echo -e "\e[34m[INFO]\e[39m $1"
|
|
echo "[INFO] $1" >> /tmp/multiplane.log
|
|
}
|
|
|
|
debug() {
|
|
if [[ ! -z "$DEBUG" ]]; then
|
|
echo -e "\e[96m[DEBUG]\e[39m $1"
|
|
fi
|
|
echo "[DEBUG] $1" >> /tmp/multiplane.log
|
|
}
|
|
|
|
warn() {
|
|
echo -e "\e[33m[WARNING]\e[39m $1"
|
|
echo "[WARNING] $1" >> /tmp/multiplane.log
|
|
}
|
|
|
|
fatal() {
|
|
echo -e "\e[31m[FATAL]\e[39m $1"
|
|
echo "[FATAL] $1" >> /tmp/multiplane.log
|
|
exit 1
|
|
}
|
|
|
|
# Function to validate MAC address
|
|
validate_mac() {
|
|
[[ $1 =~ ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ ]]
|
|
}
|
|
|
|
# Function to validate IPv4 address
|
|
validate_ipv4() {
|
|
[[ $1 =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]] && {
|
|
IFS='.' read -ra octets <<< "$1"
|
|
for octet in "${octets[@]}"; do
|
|
((octet > 255)) && return 1
|
|
done
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
# 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)")
|
|
|
|
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
|
|
}
|
|
|
|
# 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)")
|
|
|
|
if validate_ipv4 "$ip"; then
|
|
echo "$ip"
|
|
break
|
|
else
|
|
gum style --foreground 196 "Invalid IPv4 address format"
|
|
fi
|
|
done
|
|
}
|
|
|
|
clear; echo "Enter a cluster hostname. (e.g., cluster.local)";
|
|
yq -i -oy ".k0s.hostname = \"$(gum input --placeholder "cluster.local" --prompt "* " --width 80 --value "$(yq '.k0s.hostname' $CONFIG_FILE)")\"" "$CONFIG_FILE"
|
|
|
|
clear; echo "Enter a cluster IP subnet. (e.g., 10.1.0.0/24)";
|
|
yq -i -oy ".k0s.private_ip_range = \"$(gum input --placeholder "10.1.0.0/24" --prompt "* " --width 80 --value "$(yq '.k0s.private_ip_range' $CONFIG_FILE)")\"" "$CONFIG_FILE"
|
|
|
|
clear; echo "Enter a public IP subnet. (e.g., 192.168.0.0/24)";
|
|
yq -i -oy ".metallb.public_ip_range = \"$(gum input --placeholder "192.168.0.0/24" --prompt "* " --width 80 --value "$(yq '.metallb.public_ip_range' $CONFIG_FILE)")\"" "$CONFIG_FILE"
|
|
|
|
# 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 3
|
|
|
|
for i in 1 2; do
|
|
clear; gum style --border double --padding "1 2" --border-foreground 212 "Proxy Node $i/2"
|
|
|
|
# Get MAC address
|
|
mac=$(get_mac_address)
|
|
|
|
# Get IPv4 address
|
|
ip=$(get_ipv4_address)
|
|
|
|
# Add entry using yq
|
|
yq -i -oy ".haproxy.proxy.$i = {\"mac\": \"$mac\", \"ip\": \"$ip\"}" "$CONFIG_FILE"
|
|
done
|
|
|
|
clear; echo "HAProxy Kuberenetes VIP. (e.g., 10.1.0.10)";
|
|
yq -i -oy ".haproxy.kube.vip = \"$(gum input --placeholder "10.1.0.10" --prompt "* " --width 80 --value "$(yq '.haproxy.kube.vip' $CONFIG_FILE)")\"" "$CONFIG_FILE"
|
|
|
|
# Controller node entry (3 nodes required)
|
|
clear; gum style --border double --padding "1 2" --border-foreground 212 "Controller Node Configuration (3 Required)"; sleep 3
|
|
|
|
for i in 1 2 3; do
|
|
clear; 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
|
|
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)"; sleep 3
|
|
|
|
# Add worker node loop
|
|
count=0
|
|
while [ $count -lt 250 ]; do
|
|
clear; 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
|
|
clear; gum confirm "Add another worker node?" || break
|
|
fi
|
|
done
|
|
|
|
# Display results
|
|
if [ $count -gt 0 ]; then
|
|
clear; gum style --border double --padding "1 2" --border-foreground 212 "✓ Configuration saved to $CONFIG_FILE"
|
|
fi
|