Files
loc_az_hci/infrastructure/proxmox/provision-dev-ubuntu-22.sh
defiQUG c39465c2bd
Some checks failed
Test / test (push) Has been cancelled
Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 09:04:46 -08:00

145 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# -------------------------------------------------------------------
# Dev VM bootstrap for Ubuntu 22.04
# Installs:
# - Updates & base tools
# - Docker Engine (official repo)
# - NVM
# - Node.js 22 (via NVM, set as default)
# - PNPM (global)
#
# Can be used as:
# - cloud-init runcmd script
# - or run manually/over SSH
# -------------------------------------------------------------------
LOG_FILE="/var/log/dev-vm-bootstrap.log"
exec > >(tee -a "$LOG_FILE") 2>&1
echo "===== Dev VM bootstrap started: $(date) ====="
#-----------------------------
# 0. Sanity checks
#-----------------------------
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root (or with sudo)."
exit 1
fi
# Default non-root user (adjust if your image uses a different user)
DEV_USER="${DEV_USER:-ubuntu}"
if ! id "$DEV_USER" &>/dev/null; then
echo "User '$DEV_USER' not found; please set DEV_USER env var to the correct username."
exit 1
fi
#-----------------------------
# 1. Base system updates
#-----------------------------
echo "[1/5] Updating system packages..."
apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
apt-get install -y \
ca-certificates \
curl \
wget \
git \
build-essential \
apt-transport-https \
gnupg \
lsb-release \
software-properties-common
#-----------------------------
# 2. Docker Engine
#-----------------------------
echo "[2/5] Installing Docker Engine..."
# Remove any old Docker
apt-get remove -y docker docker-engine docker.io containerd runc || true
# Set up Docker repository
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
ARCH="$(dpkg --print-architecture)"
UBUNTU_CODENAME="$(. /etc/os-release && echo "$UBUNTU_CODENAME")"
echo \
"deb [arch=${ARCH} signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
${UBUNTU_CODENAME} stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update -y
apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
# Add dev user to docker group
usermod -aG docker "$DEV_USER"
# Enable/Start Docker
systemctl enable docker
systemctl restart docker
#-----------------------------
# 3. Install NVM (per-user)
#-----------------------------
echo "[3/5] Installing NVM for user '$DEV_USER'..."
# Run as the dev user
sudo -u "$DEV_USER" bash << 'EOF'
set -euo pipefail
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
# Official NVM install script
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
# Load NVM for this shell
export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1090
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
echo "NVM version: $(nvm --version)"
#-----------------------------
# 4. Node.js 22 LTS via NVM
#-----------------------------
echo "[4/5] Installing Node.js 22 LTS..."
# Install Node 22 (adjust if you prefer a specific LTS name)
nvm install 22
nvm alias default 22
nvm use default
node -v
npm -v
#-----------------------------
# 5. PNPM global
#-----------------------------
echo "[5/5] Installing PNPM globally..."
# Either via corepack (Node >=16.13), or directly with npm
corepack enable || true
npm install -g pnpm
pnpm -v
EOF
echo "===== Dev VM bootstrap completed: $(date) ====="