mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-24 13:14:23 +00:00
520478dc37
setup.sh accepts Oracle Linux 10.2+ (<11) on x86_64 with a running UEK R8 kernel and an x86-64-v3 CPU, beside Debian 13+ and Ubuntu 24.04+, and parses os-release instead of sourcing it. New scripts/lib/distro.sh probes the package manager, OVS umbrella unit, OVN central layout, CA trust store and OVN logrotate file; it ships in the release tarball, is installed to /usr/local/share/spinifex/lib/, and is sourced by setup-ovn.sh, uninstall-spx.sh and dev-install.sh. setup.sh and node-reset.sh carry inline copies, kept identical by scripts/lib/distro_test.sh. New runtime/host/hostos resolves the QEMU binary, CA trust store and boot tools by probing, naming every candidate on failure. Callers are wired in later stages.
126 lines
5.3 KiB
Bash
Executable File
126 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# dev-install.sh — Full local development setup via production installer.
|
|
# Builds from source, assembles a tarball, runs setup.sh for scaffolding
|
|
# (user creation, directories, systemd units), initializes the cluster,
|
|
# and starts services via systemd.
|
|
#
|
|
# Environment variables:
|
|
# SPINIFEX_REGION Region for spx admin init (default: ap-southeast-2)
|
|
# SPINIFEX_AZ AZ for spx admin init (default: ${SPINIFEX_REGION}a)
|
|
# DEV_INSTALL_SKIP_INIT Internal flag used by reset-dev-env.sh. When 1,
|
|
# stops after setup.sh and skips setup-ovn, init,
|
|
# CA trust, service start, and LB image import —
|
|
# caller owns those steps. Do not set manually.
|
|
#
|
|
# Usage: ./scripts/dev-install.sh
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
MULGA_ROOT="$(cd "$PROJECT_ROOT/.." && pwd)"
|
|
|
|
# Host-OS capability probes: beside this script in a checkout and in the
|
|
# installed share dir, else where setup.sh installs them.
|
|
DISTRO_LIB=""
|
|
for candidate in "$(dirname "${BASH_SOURCE[0]}")/lib/distro.sh" /usr/local/share/spinifex/lib/distro.sh; do
|
|
if [ -f "$candidate" ]; then DISTRO_LIB="$candidate"; break; fi
|
|
done
|
|
if [ -z "$DISTRO_LIB" ]; then
|
|
echo "ERROR: distro.sh not found at $(dirname "${BASH_SOURCE[0]}")/lib/distro.sh or /usr/local/share/spinifex/lib/distro.sh; re-run setup.sh to install it" >&2
|
|
exit 1
|
|
fi
|
|
# shellcheck source=lib/distro.sh
|
|
. "$DISTRO_LIB"
|
|
|
|
echo "=== Building ==="
|
|
cd "$PROJECT_ROOT" && make build
|
|
cd "$MULGA_ROOT/viperblock" && make go_build_nbd
|
|
|
|
echo "=== Assembling tarball for setup.sh ==="
|
|
STAGING=$(mktemp -d)
|
|
trap 'rm -rf "$STAGING"' EXIT
|
|
cp "$PROJECT_ROOT/bin/spx" "$STAGING/spx"
|
|
cp "$MULGA_ROOT/viperblock/lib/nbdkit-viperblock-plugin.so" "$STAGING/"
|
|
cp "$PROJECT_ROOT/scripts/setup-ovn.sh" "$STAGING/"
|
|
cp "$PROJECT_ROOT/scripts/node-reset.sh" "$STAGING/"
|
|
cp "$PROJECT_ROOT/scripts/uninstall-spx.sh" "$STAGING/"
|
|
mkdir -p "$STAGING/lib"
|
|
cp "$PROJECT_ROOT/scripts/lib/distro.sh" "$STAGING/lib/"
|
|
mkdir -p "$STAGING/systemd"
|
|
cp "$PROJECT_ROOT/build/systemd/"* "$STAGING/systemd/"
|
|
mkdir -p "$STAGING/scripts"
|
|
cp "$PROJECT_ROOT/build/scripts/"* "$STAGING/scripts/"
|
|
mkdir -p "$STAGING/udev"
|
|
cp "$PROJECT_ROOT/build/udev/"* "$STAGING/udev/"
|
|
cp "$PROJECT_ROOT/build/logrotate/spinifex" "$STAGING/logrotate-spinifex"
|
|
tar czf /tmp/spinifex-local.tar.gz -C "$STAGING" .
|
|
|
|
echo "=== Cleaning stale state from previous installs ==="
|
|
# Stop any running services before modifying files
|
|
sudo systemctl stop spinifex.target 2>/dev/null || true
|
|
sudo systemctl reset-failed 'spinifex-*' 2>/dev/null || true
|
|
|
|
# Remove stale files owned by the dev user in production paths.
|
|
# A prior admin init run without sudo can leave files owned by tf-user that
|
|
# service users (spinifex-nats, etc.) can't read under systemd's
|
|
# ProtectSystem=strict sandboxing.
|
|
for dir in /var/lib/spinifex /var/log/spinifex /etc/spinifex; do
|
|
if [ -d "$dir" ]; then
|
|
# Remove PID files, stale logs, and the legacy ~/spinifex/config symlink
|
|
sudo find "$dir" -name '*.pid' -delete 2>/dev/null || true
|
|
sudo find "$dir" -name '*.log' -delete 2>/dev/null || true
|
|
sudo find "$dir" -name '*.log.*' -delete 2>/dev/null || true
|
|
fi
|
|
done
|
|
# Remove legacy data dir contents that conflict with production layout
|
|
if [ -d /var/lib/spinifex/config ]; then
|
|
sudo rm -rf /var/lib/spinifex/config
|
|
fi
|
|
|
|
echo "=== Running setup.sh (creates users, dirs, systemd units) ==="
|
|
sudo INSTALL_SPINIFEX_TARBALL=/tmp/spinifex-local.tar.gz INSTALL_SPINIFEX_SKIP_NEWGRP=1 bash "$PROJECT_ROOT/scripts/setup.sh"
|
|
rm -f /tmp/spinifex-local.tar.gz
|
|
|
|
if [ "${DEV_INSTALL_SKIP_INIT:-0}" = "1" ]; then
|
|
echo "=== DEV_INSTALL_SKIP_INIT=1 — stopping after setup.sh ==="
|
|
echo "Caller owns: setup-ovn, spx admin init, CA trust, service start, LB image."
|
|
exit 0
|
|
fi
|
|
|
|
echo "=== Setting up OVN ==="
|
|
sudo /usr/local/share/spinifex/setup-ovn.sh --management
|
|
|
|
SPINIFEX_REGION="${SPINIFEX_REGION:-ap-southeast-2}"
|
|
SPINIFEX_AZ="${SPINIFEX_AZ:-${SPINIFEX_REGION}a}"
|
|
|
|
echo "=== Initializing (region=$SPINIFEX_REGION az=$SPINIFEX_AZ) ==="
|
|
sudo spx admin init --force --region "$SPINIFEX_REGION" --az "$SPINIFEX_AZ" --node node1 --nodes 1
|
|
|
|
echo "=== Starting services ==="
|
|
sudo systemctl start spinifex.target
|
|
|
|
# Check if user needs to re-login for spinifex group membership
|
|
if ! id -Gn 2>/dev/null | grep -qw spinifex; then
|
|
newgrp spinifex
|
|
fi
|
|
|
|
echo "=== Building and installing microVM artifacts ==="
|
|
cd "$PROJECT_ROOT" && make build-lb-agent install-microvm
|
|
|
|
# Unified EKS node AMI (server + agent; role chosen at first boot). Heavy (full
|
|
# Alpine + K3s build, needs sudo + network), so it is opt-in: set
|
|
# DEV_INSTALL_EKS=1 to build + register it. Without it, `aws eks create-cluster`
|
|
# fails AMI resolution until the operator runs `make import-eks-node-image`.
|
|
if [ "${DEV_INSTALL_EKS:-0}" = "1" ]; then
|
|
echo "=== Building + importing eks-node AMI ==="
|
|
cd "$PROJECT_ROOT" && make import-eks-node-image
|
|
else
|
|
echo "=== Skipping eks-node AMI (set DEV_INSTALL_EKS=1 to enable, or run 'make import-eks-node-image') ==="
|
|
fi
|
|
|
|
echo "=== Done ==="
|
|
echo "Services: sudo systemctl status spinifex.target"
|
|
echo "Logs: journalctl -u 'spinifex-*' -f"
|
|
echo "Test: AWS_PROFILE=spinifex aws ec2 describe-instances"
|
|
echo "Iterate: make deploy (rebuild + restart all)"
|