#!/usr/bin/env bash set -euo pipefail # Kubestrap Installer # Usage: curl -sfL https://get.kubestrap.com | bash DOCKER_IMAGE="damurai/kubestrap:latest" SERVICE_NAME="kubestrap" DATA_DIR="/root/.kubestrap" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" info() { printf "\033[32m[INFO]\033[0m %s\n" "$*"; } warn() { printf "\033[33m[WARN]\033[0m %s\n" "$*"; } error() { printf "\033[31m[ERROR]\033[0m %s\n" "$*"; exit 1; } check_root() { if [ "$(id -u)" -ne 0 ]; then error "This installer must be run as root. Try: curl -sfL https://get.kubestrap.com | sudo bash" fi } check_systemd() { if [ ! -d /run/systemd/system ]; then error "systemd is required but not detected. Kubestrap needs systemd to run as a service." fi } check_docker() { if ! command -v docker >/dev/null 2>&1; then warn "Docker is not installed." info "Install Docker first: https://docs.docker.com/engine/install/" info "" info "Quick install (most Linux distros):" info " curl -fsSL https://get.docker.com | sh" info "" error "Please install Docker and re-run this installer." fi if ! docker info >/dev/null 2>&1; then error "Docker daemon is not running. Start it with: systemctl start docker" fi } check_existing() { if systemctl is-active --quiet "$SERVICE_NAME" 2>/dev/null; then info "Kubestrap service is already running. Upgrading..." systemctl stop "$SERVICE_NAME" fi } pull_image() { info "Pulling ${DOCKER_IMAGE}..." docker pull "$DOCKER_IMAGE" } create_data_dir() { info "Creating data directory at ${DATA_DIR}..." mkdir -p "${DATA_DIR}" mkdir -p "${DATA_DIR}/ssh-keys" mkdir -p "${DATA_DIR}/kubeconfigs" mkdir -p "${DATA_DIR}/reports" } install_service() { info "Installing systemd service..." cat > "$SERVICE_FILE" <