From 0dc66b8f3c69e00e0f57b088113ad59bdcdf62a1 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Tue, 20 Jan 2026 16:27:18 +0100 Subject: [PATCH] feat: Add update script for easier upgrades - Add scripts/update.sh with colored output and error handling - Automates: git pull, version freeze, docker compose rebuild - Update README with script usage and alias instructions Co-Authored-By: Claude Opus 4.5 --- README.md | 41 ++++++++++++++++++----- scripts/update.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 8 deletions(-) create mode 100755 scripts/update.sh diff --git a/README.md b/README.md index affc9d5..c9ba792 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,34 @@ For complete usage instructions, see the [User Guide](docs/user-guide.md). ## Updating -To update mc-webui to the latest version: +### Using the update script (recommended) + +The easiest way to update mc-webui: + +```bash +cd ~/mc-webui +./scripts/update.sh +``` + +The script automatically pulls changes, freezes the version, and rebuilds containers. + +**Optional: Create a global alias for quick updates** + +Add to your `~/.bashrc` or `~/.zshrc`: + +```bash +alias mcupdate='~/mc-webui/scripts/update.sh' +``` + +Then reload your shell (`source ~/.bashrc`) and update anytime with: + +```bash +mcupdate +``` + +### Manual update + +If you prefer to run commands manually: ```bash cd ~/mc-webui @@ -148,24 +175,22 @@ docker compose up -d --build The `python3 -m app.version freeze` command captures the current Git version (date + commit hash) for display in the app menu. -**Testing experimental features:** +### Testing experimental features The `dev` branch contains new features that are still being tested: ```bash +cd ~/mc-webui git checkout dev -git pull -python3 -m app.version freeze -docker compose up -d --build +./scripts/update.sh ``` To return to the stable version: ```bash +cd ~/mc-webui git checkout main -git pull -python3 -m app.version freeze -docker compose up -d --build +./scripts/update.sh ``` --- diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..143f746 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# +# mc-webui update script +# Updates the application from Git and rebuilds Docker containers +# +# Usage: +# ./scripts/update.sh # Run from mc-webui directory +# mcupdate # If alias is configured (see README) +# + +set -e # Exit on error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Print colored status messages +info() { echo -e "${BLUE}[INFO]${NC} $1"; } +success() { echo -e "${GREEN}[OK]${NC} $1"; } +warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } +error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } + +# Determine mc-webui directory +if [ -f "docker-compose.yml" ] && [ -d "app" ]; then + MCWEBUI_DIR="$(pwd)" +elif [ -n "$MCWEBUI_DIR" ] && [ -d "$MCWEBUI_DIR" ]; then + cd "$MCWEBUI_DIR" +elif [ -d "$HOME/mc-webui" ]; then + MCWEBUI_DIR="$HOME/mc-webui" + cd "$MCWEBUI_DIR" +else + error "Cannot find mc-webui directory. Run from mc-webui folder or set MCWEBUI_DIR environment variable." +fi + +info "Updating mc-webui in: $MCWEBUI_DIR" +echo "" + +# Step 1: Git pull +info "Pulling latest changes from Git..." +if git pull; then + success "Git pull completed" +else + error "Git pull failed" +fi +echo "" + +# Step 2: Freeze version +info "Freezing version..." +if python3 -m app.version freeze; then + success "Version frozen" +else + warn "Version freeze failed (non-critical, continuing...)" +fi +echo "" + +# Step 3: Rebuild and restart containers +info "Rebuilding and restarting Docker containers..." +if docker compose up -d --build; then + success "Containers rebuilt and started" +else + error "Docker compose failed" +fi +echo "" + +# Step 4: Show status +info "Container status:" +docker compose ps +echo "" + +# Step 5: Show version +if command -v curl &> /dev/null; then + sleep 2 # Wait for container to start + VERSION=$(curl -s http://localhost:5000/api/version 2>/dev/null | grep -o '"version":"[^"]*"' | cut -d'"' -f4) + if [ -n "$VERSION" ]; then + success "mc-webui updated to version: $VERSION" + else + warn "Could not fetch version (container may still be starting)" + fi +fi + +echo "" +echo -e "${GREEN}Update complete!${NC}"