From 9641d24edbe7d4a4e3b254d517999a303f9807b3 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 6 Apr 2026 10:17:55 -0400 Subject: [PATCH] setup.sh: add confirmation prompt, pre-flight checks, splash screen, color-free output --- deploy/setup.sh | 146 +++++++++++++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 50 deletions(-) diff --git a/deploy/setup.sh b/deploy/setup.sh index cf39276..d0461ee 100755 --- a/deploy/setup.sh +++ b/deploy/setup.sh @@ -1,91 +1,137 @@ #!/bin/bash # Project Tracker - One-shot deploy script # Run on a fresh Debian/Ubuntu server as root -# Usage: curl -sL https://gitea.ledrew.me/ledadmin/project-tracker/raw/branch/master/deploy/setup.sh | bash set -e -echo "=== Project Tracker Deploy ===" +echo "" +echo "╔═══════════════════════════════════════════════╗" +echo "║ Project Tracker — Deploy Script ║" +echo "╚═══════════════════════════════════════════════╝" echo "" # Check if running as root if [ "$EUID" -ne 0 ]; then - echo "Please run as root: sudo $0" + echo "ERROR: Please run as root: sudo $0" exit 1 fi # Detect OS -if command -v apt-get &> /dev/null; then - PKG_MANAGER="apt-get" -elif command -v yum &> /dev/null; then - PKG_MANAGER="yum" -else - echo "Unsupported OS. This script requires Debian/Ubuntu or RHEL/CentOS." +if ! command -v apt-get &> /dev/null; then + echo "ERROR: This script requires Debian/Ubuntu." + echo " (yum/dnf support can be added on request)" exit 1 fi +# Check for Docker +DOCKER_INSTALLED=false +if command -v docker &> /dev/null; then + DOCKER_INSTALLED=true + DOCKER_VERSION=$(docker --version 2>/dev/null | awk '{print $3}' | tr -d ',') +fi + +# Check if repo already exists +REPO_DIR="/root/project-tracker" +REPO_EXISTS=false +if [ -d "$REPO_DIR" ]; then + REPO_EXISTS=true +fi + +# Show pre-flight +echo "Pre-flight check:" +echo " OS: $(lsb_release -ds 2>/dev/null || cat /etc/os-release | grep PRETTY_NAME | cut -d'"' -f2)" +echo " Docker: ${DOCKER_INSTALLED:+$DOCKER_VERSION (installed)}" +echo " Repo dir: ${REPO_EXISTS:+WARNING — $REPO_DIR already exists (will git pull)}" +echo "" + +echo "This script will:" +echo " 1. Update system packages" +echo " 2. Install Docker (if not present)" +echo " 3. Clone/pull the Project Tracker repo to $REPO_DIR" +echo " 4. Build and start the app via Docker Compose" +echo "" +echo "Container ports used:" +echo " Port 80 — Web UI + API" +echo "" +echo "Data: SQLite database is stored in a Docker named volume." +echo " Use 'docker compose down -v' to DELETE the database." +echo "" + +# Confirm +echo -n "Continue? [Y/n]: " +read -r CONFIRM +CONFIRM=${CONFIRM:-Y} +if [ "$CONFIRM" != "Y" ] && [ "$CONFIRM" != "y" ]; then + echo "Aborted." + exit 0 +fi + +echo "" +echo "=== Starting deploy ===" +echo "" + # Update system -echo "[1/5] Updating system packages..." -$PKG_MANAGER update -qq -$PKG_MANAGER install -y -qq curl git ca-certificates gnupg > /dev/null 2>&1 +echo "[1/4] Updating system packages..." +apt-get update -qq +apt-get install -y -qq curl git ca-certificates gnupg > /dev/null 2>&1 # Install Docker -echo "[2/5] Installing Docker..." -if command -v docker &> /dev/null; then - echo " Docker already installed." +echo "[2/4] Installing Docker..." +if [ "$DOCKER_INSTALLED" = "true" ]; then + echo " Docker already installed ($DOCKER_VERSION) — skipping." else - if [ "$PKG_MANAGER" = "apt-get" ]; then - 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 - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list - $PKG_MANAGER update -qq - $PKG_MANAGER install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin > /dev/null 2>&1 - else - $PKG_MANAGER install -y -qq docker docker-compose-plugin > /dev/null 2>&1 - fi - systemctl enable docker --now > /dev/null 2>&1 + echo " Installing Docker from Docker Inc. 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 + . /etc/os-release + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $VERSION_CODENAME stable" > /etc/apt/sources.list.d/docker.list + apt-get update -qq + apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin > /dev/null 2>&1 echo " Docker installed." fi -# Enable and start Docker systemctl enable docker --now > /dev/null 2>&1 || true # Clone or update repo -echo "[3/5] Setting up Project Tracker..." -if [ -d "/root/project-tracker" ]; then - echo " Updating existing repo..." - cd /root/project-tracker +echo "[3/4] Setting up Project Tracker..." +if [ "$REPO_EXISTS" = "true" ]; then + echo " Pulling latest changes into existing repo..." + cd "$REPO_DIR" git pull else echo " Cloning repo..." - git clone https://gitea.ledrew.me/ledadmin/project-tracker.git /root/project-tracker + git clone https://gitea.ledrew.me/ledadmin/project-tracker.git "$REPO_DIR" + cd "$REPO_DIR" fi # Build and start -echo "[4/5] Building and starting containers..." -cd /root/project-tracker/deploy +echo "[4/4] Building and starting containers..." +cd "$REPO_DIR/deploy" docker compose down --remove-orphans 2>/dev/null || true docker compose up -d --build -# Wait for backend to be ready -echo "[5/5] Waiting for backend to start..." -sleep 3 +# Wait for backend +echo "Waiting for backend to start..." +sleep 4 # Verify -echo "" -echo "=== Done ===" -IP=$(hostname -I | awk '{print $1}') -if curl -sf http://localhost/api/projects > /dev/null 2>&1; then - echo "Project Tracker is LIVE at http://$IP" -else - echo "Project Tracker may need a moment. Check: docker compose logs" - echo "App should be at http://$IP" -fi +IP=$(hostname -I 2>/dev/null | awk '{print $1}' || echo "localhost") +HTTP_OK=$(curl -sf -o /dev/null -w "%{http_code}" http://localhost/api/projects 2>/dev/null || echo "000") echo "" -echo "Useful commands:" -echo " docker compose logs -f # View logs" -echo " docker compose restart # Restart" -echo " docker compose down # Stop" +echo "=== Deploy complete ===" +if [ "$HTTP_OK" = "200" ]; then + echo "Project Tracker is LIVE at http://$IP" +else + echo "App started — verify at http://$IP" + echo "(Backend may still be initializing, give it a few seconds)" +fi +echo "" +echo "Useful commands:" +echo " cd $REPO_DIR/deploy" +echo " docker compose logs -f # View logs" +echo " docker compose restart # Restart" +echo " docker compose down # Stop" +echo " docker compose down -v # Stop and DELETE database (CAREFUL!)" echo ""