setup.sh: add confirmation prompt, pre-flight checks, splash screen, color-free output

This commit is contained in:
Ada
2026-04-06 10:17:55 -04:00
parent 5ccf6b6aab
commit 9641d24edb

View File

@@ -1,91 +1,137 @@
#!/bin/bash #!/bin/bash
# Project Tracker - One-shot deploy script # Project Tracker - One-shot deploy script
# Run on a fresh Debian/Ubuntu server as root # 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 set -e
echo "=== Project Tracker Deploy ===" echo ""
echo "╔═══════════════════════════════════════════════╗"
echo "║ Project Tracker — Deploy Script ║"
echo "╚═══════════════════════════════════════════════╝"
echo "" echo ""
# Check if running as root # Check if running as root
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
echo "Please run as root: sudo $0" echo "ERROR: Please run as root: sudo $0"
exit 1 exit 1
fi fi
# Detect OS # Detect OS
if command -v apt-get &> /dev/null; then if ! command -v apt-get &> /dev/null; then
PKG_MANAGER="apt-get" echo "ERROR: This script requires Debian/Ubuntu."
elif command -v yum &> /dev/null; then echo " (yum/dnf support can be added on request)"
PKG_MANAGER="yum"
else
echo "Unsupported OS. This script requires Debian/Ubuntu or RHEL/CentOS."
exit 1 exit 1
fi 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 # Update system
echo "[1/5] Updating system packages..." echo "[1/4] Updating system packages..."
$PKG_MANAGER update -qq apt-get update -qq
$PKG_MANAGER install -y -qq curl git ca-certificates gnupg > /dev/null 2>&1 apt-get install -y -qq curl git ca-certificates gnupg > /dev/null 2>&1
# Install Docker # Install Docker
echo "[2/5] Installing Docker..." echo "[2/4] Installing Docker..."
if command -v docker &> /dev/null; then if [ "$DOCKER_INSTALLED" = "true" ]; then
echo " Docker already installed." echo " Docker already installed ($DOCKER_VERSION) — skipping."
else else
if [ "$PKG_MANAGER" = "apt-get" ]; then echo " Installing Docker from Docker Inc. repository..."
install -m 0755 -d /etc/apt/keyrings install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg 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 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 . /etc/os-release
$PKG_MANAGER update -qq 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
$PKG_MANAGER install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin > /dev/null 2>&1 apt-get update -qq
else apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin > /dev/null 2>&1
$PKG_MANAGER install -y -qq docker docker-compose-plugin > /dev/null 2>&1
fi
systemctl enable docker --now > /dev/null 2>&1
echo " Docker installed." echo " Docker installed."
fi fi
# Enable and start Docker
systemctl enable docker --now > /dev/null 2>&1 || true systemctl enable docker --now > /dev/null 2>&1 || true
# Clone or update repo # Clone or update repo
echo "[3/5] Setting up Project Tracker..." echo "[3/4] Setting up Project Tracker..."
if [ -d "/root/project-tracker" ]; then if [ "$REPO_EXISTS" = "true" ]; then
echo " Updating existing repo..." echo " Pulling latest changes into existing repo..."
cd /root/project-tracker cd "$REPO_DIR"
git pull git pull
else else
echo " Cloning repo..." 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 fi
# Build and start # Build and start
echo "[4/5] Building and starting containers..." echo "[4/4] Building and starting containers..."
cd /root/project-tracker/deploy cd "$REPO_DIR/deploy"
docker compose down --remove-orphans 2>/dev/null || true docker compose down --remove-orphans 2>/dev/null || true
docker compose up -d --build docker compose up -d --build
# Wait for backend to be ready # Wait for backend
echo "[5/5] Waiting for backend to start..." echo "Waiting for backend to start..."
sleep 3 sleep 4
# Verify # Verify
echo "" IP=$(hostname -I 2>/dev/null | awk '{print $1}' || echo "localhost")
echo "=== Done ===" HTTP_OK=$(curl -sf -o /dev/null -w "%{http_code}" http://localhost/api/projects 2>/dev/null || echo "000")
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
echo ""
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 ""
echo "Useful commands:" echo "Useful commands:"
echo " cd $REPO_DIR/deploy"
echo " docker compose logs -f # View logs" echo " docker compose logs -f # View logs"
echo " docker compose restart # Restart" echo " docker compose restart # Restart"
echo " docker compose down # Stop" echo " docker compose down # Stop"
echo " docker compose down -v # Stop and DELETE database (CAREFUL!)"
echo "" echo ""