91 lines
2.6 KiB
Bash
Executable file
91 lines
2.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# NextWorkspace Installer — bootstraps a bare Linux VM
|
|
# Idempotent: safe to run multiple times.
|
|
|
|
TARGET_DIR="/opt/nextworkspace"
|
|
BACKUP_DIR="/opt/backup"
|
|
|
|
# --- Create backup vault and runtime directories ---
|
|
echo "=== NextWorkspace Setup ==="
|
|
mkdir -p "$BACKUP_DIR/certificates"
|
|
mkdir -p "$TARGET_DIR/config/nextworkspace"
|
|
mkdir -p "$TARGET_DIR/config/zoraxy/conf/proxy"
|
|
mkdir -p "$TARGET_DIR/config/zoraxy/www/html"
|
|
mkdir -p "$TARGET_DIR/data/zoraxy"
|
|
mkdir -p "$TARGET_DIR/compose"
|
|
mkdir -p "$TARGET_DIR/logs"
|
|
|
|
# --- Interactive prompts ---
|
|
read -p "Domain [nextwks.eu]: " DOMAIN
|
|
DOMAIN="${DOMAIN:-nextwks.eu}"
|
|
|
|
read -p "TLS email (Let's Encrypt) [den@2-4-h.net]: " TLS_EMAIL
|
|
TLS_EMAIL="${TLS_EMAIL:-den@2-4-h.net}"
|
|
|
|
read -p "Admin username [master]: " ADMIN_USERNAME
|
|
ADMIN_USERNAME="${ADMIN_USERNAME:-master}"
|
|
|
|
read -p "Admin password [auto-generated]: " ADMIN_PASSWORD
|
|
if [ -z "$ADMIN_PASSWORD" ]; then
|
|
ADMIN_PASSWORD="9Aku7MfklZU9ldnZ"
|
|
fi
|
|
|
|
echo ""
|
|
echo "========================================"
|
|
echo " Admin username: $ADMIN_USERNAME"
|
|
echo " Admin password: $ADMIN_PASSWORD"
|
|
echo " Save this password — it won't be shown again!"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# Write .env file in backup vault (deploy.sh copies it to production)
|
|
ENV_FILE="$BACKUP_DIR/.env"
|
|
cat > "$ENV_FILE" <<EOF
|
|
# NextWorkspace Configuration
|
|
# This file is auto-generated by install.sh — do not edit manually
|
|
DOMAIN=$DOMAIN
|
|
TLS_EMAIL=$TLS_EMAIL
|
|
ADMIN_USERNAME=$ADMIN_USERNAME
|
|
ADMIN_PASSWORD=$ADMIN_PASSWORD
|
|
EOF
|
|
|
|
chmod 600 "$ENV_FILE"
|
|
|
|
# ---- Go ----
|
|
if command -v go &>/dev/null; then
|
|
echo "[SKIP] Go already installed: $(go version)"
|
|
else
|
|
echo "[INSTALL] Installing Go..."
|
|
GO_URL="https://go.dev/dl/$(curl -sL https://go.dev/VERSION?m=text | head -1).linux-amd64.tar.gz"
|
|
curl -sL "$GO_URL" -o /tmp/go.tar.gz
|
|
rm -rf /usr/local/go
|
|
tar -C /usr/local -xzf /tmp/go.tar.gz
|
|
rm /tmp/go.tar.gz
|
|
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile.d/go.sh
|
|
chmod +x /etc/profile.d/go.sh
|
|
export PATH=$PATH:/usr/local/go/bin
|
|
echo "[OK] Go installed: $(go version)"
|
|
fi
|
|
|
|
# ---- System deps ----
|
|
echo "[INSTALL] git, build-essential, podman, podman-compose..."
|
|
apt-get update -qq
|
|
apt-get install -y -qq git build-essential curl podman podman-compose
|
|
|
|
# ---- Clone / pull repo ----
|
|
REPO_DIR="/opt/NextWks"
|
|
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
|
|
|
|
if [ -d "$REPO_DIR/.git" ]; then
|
|
echo "[UPDATE] Repository exists — pulling latest..."
|
|
cd "$REPO_DIR"
|
|
git pull
|
|
else
|
|
echo "[CLONE] Cloning repository..."
|
|
git clone "$REPO_URL" "$REPO_DIR"
|
|
fi
|
|
|
|
echo "[DONE] Bootstrapping complete. Running first deploy..."
|
|
"$REPO_DIR/deploy.sh" --destroy
|