Files
Multiplane/install.sh
2026-01-19 14:11:30 +00:00

142 lines
3.8 KiB
Bash

#!/bin/bash
set -e
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-install.log
info() {
echo -e "\e[34m[INFO]\e[39m $1"
echo "[INFO] $1" >> /tmp/multiplane-install.log
}
debug() {
if [[ ! -z "$DEBUG" ]]; then
echo -e "\e[96m[DEBUG]\e[39m $1"
fi
echo "[DEBUG] $1" >> /tmp/multiplane-install.log
}
warn() {
echo -e "\e[33m[WARNING]\e[39m $1"
echo "[WARNING] $1" >> /tmp/multiplane-install.log
}
fatal() {
echo -e "\e[31m[FATAL]\e[39m $1"
echo "[FATAL] $1" >> /tmp/multiplane-install.log
exit 1
}
# Source the os-release file to get distribution info
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
fatal "Cannot determine OS"
exit 1
fi
# Check if OS is Debian, AlmaLinux (almalinux or alma), or Ubuntu
if [[ "$OS" != "debian" && "$OS" != "ubuntu" && "$OS" != "almalinux" && "$OS" != "alma" ]]; then
debug "Unsupported OS: $OS"
fatal "This script only supports Debian, AlmaLinux, or Ubuntu"
exit 1
fi
install_dependencies () {
info "Checking dependencies..."
# Install curl if not present (required for downloading Nix tarball)
if ! command -v curl &> /dev/null; then
info "Installing curl..."
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y curl
elif command -v dnf &> /dev/null; then
sudo dnf install -y curl
elif command -v yum &> /dev/null; then
sudo yum install -y curl
elif command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm curl
else
fatal "Please install curl manually for your distribution"
fi
fi
# Install yq (required for config and templates)
info "Installing yq..."
if ! curl -sSL -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64; then
echo "Error: Failed to download yq." >&2
exit 1
else
chmod +x /usr/local/bin/yq
fi
# Install gum (required for config and templates)
info "Installing gum..."
if ! curl -sSL -o /tmp/gum_0.17.0_Linux_x86_64.tar.gz https://github.com/charmbracelet/gum/releases/download/v0.17.0/gum_0.17.0_Linux_x86_64.tar.gz; then
echo "Error: Failed to download gum." >&2
exit 1
else
tar -xzf /tmp/gum_0.17.0_Linux_x86_64.tar.gz -C /usr/local/bin --strip-components=1 gum_0.17.0_Linux_x86_64/gum
rm -rf /tmp/gum_0.17.0_Linux_x86_64.tar.gz
chmod +x /usr/local/bin/gum
fi
# Install k0sctl (required for kubernetes cluster)
info "Installing k0sctl..."
if ! curl -sSL -o /usr/local/bin/k0sctl https://github.com/k0sproject/k0sctl/releases/latest/download/k0sctl-linux-amd64; then
echo "Error: Failed to download k0sctl." >&2
exit 1
else
chmod +x /usr/local/bin/k0sctl
fi
# Install tinkerbell (required for node provisioning)
info "Installing tinkerbell..."
if ! curl -sSL -o /usr/local/bin/tinkerbell https://github.com/tinkerbell/tinkerbell/releases/latest/download/tinkerbell-embedded-linux-amd64; then
echo "Error: Failed to download tinkerbell." >&2
exit 1
else
chmod +x /usr/local/bin/tinkerbell
cat <<EOT > /etc/systemd/system/tinkerbell.service
[Unit]
Description=Tinkerbell is a bare metal provisioning engine.
After=docker.service
[Service]
User=root
WorkingDirectory=/etc/tinkerbell
LimitNOFILE=4096
PIDFile=/var/run/tinkerbell/daemon.pid
ExecStart=/usr/local/bin/tinkerbell
Restart=on-failure
StartLimitInterval=600
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload > /dev/null 2>&1
fi
}
main() {
info "Script loaded, starting the install process..."
install_dependencies
info "Install script finished. You can now run .\multiplane.sh... starting setup..."
exec ./multiplane.sh "$@"
}
main