#!/usr/bin/env bash set -euo pipefail # Bootstrap script for provisioning # Usage: # On a fresh Debian system as root: # apt-get update && apt-get install -y curl git sudo # adduser sudo # su - # Then run: # curl -fsSL https://git.sdf.org/jchenry/provision/raw/branch/main/bootstrap | bash REPO_URL="https://git.sdf.org/jchenry/provision.git" CLONE_DIR="$HOME/.workspace/src/git.sdf.org/jchenry/provision" echo "=== Provision Bootstrap ===" echo "" # Check if running as root if [ "$EUID" -eq 0 ]; then echo "ERROR: Do not run this script as root" echo "" echo "If you're on a fresh Debian system, first run as root:" echo " apt-get update && apt-get install -y curl git sudo" echo " adduser $SUDO_USER sudo" echo "" echo "Then log out and back in, and run this script as your regular user." exit 1 fi # Check for git if ! command -v git >/dev/null 2>&1; then echo "ERROR: git is not installed" echo "" echo "On Debian/Ubuntu, run as root:" echo " apt-get update && apt-get install -y git" echo "" echo "On Arch, run as root:" echo " pacman -Sy git" exit 1 fi # Check for sudo access if ! sudo -n true 2>/dev/null; then echo "ERROR: You don't have sudo access" echo "" echo "On Debian/Ubuntu, run as root:" echo " adduser $(whoami) sudo" echo "" echo "Then log out and back in for the change to take effect." exit 1 fi echo "✓ Prerequisites check passed" echo "" # Ensure workspace directory exists if [ ! -d "$HOME/.workspace" ]; then echo "Creating workspace directory..." mkdir -p "$HOME/.workspace/src/git.sdf.org/jchenry" fi # Clone or update repository if [ -d "$CLONE_DIR" ]; then echo "Updating existing provision repository..." cd "$CLONE_DIR" git pull else echo "Cloning provision repository..." git clone "$REPO_URL" "$CLONE_DIR" cd "$CLONE_DIR" fi echo "" echo "Repository ready at $CLONE_DIR" echo "" # Make provision script executable chmod +x "$CLONE_DIR/provision" # Run provision with any arguments passed to this script echo "Starting provision..." echo "" exec "$CLONE_DIR/provision" "$@"