#!/bin/bash # VideoTools Universal Build Script (Linux/macOS/Windows via Git Bash) set -e PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Extract app version from main.go APP_VERSION="$(grep -E 'appVersion\s*=\s*"' "$PROJECT_ROOT/main.go" | head -1 | sed -E 's/.*"([^"]+)".*/\1/')" [ -z "$APP_VERSION" ] && APP_VERSION="(version unknown)" echo "════════════════════════════════════════════════════════════════" echo " VideoTools Universal Build Script" echo "════════════════════════════════════════════════════════════════" echo "" # Detect platform PLATFORM="$(uname -s)" case "$PLATFORM" in Linux*) OS="Linux" ;; Darwin*) OS="macOS" ;; CYGWIN*|MINGW*|MSYS*) OS="Windows" ;; *) echo "❌ Unknown platform: $PLATFORM"; exit 1 ;; esac echo "🔍 Detected platform: $OS" echo "" # Go check if ! command -v go >/dev/null 2>&1; then echo "❌ ERROR: Go is not installed. Please install Go 1.21+ (go version currently missing)." exit 1 fi echo "📦 Go version:" go version echo "" diagnostics() { echo "Diagnostics: version=$APP_VERSION os=$OS arch=$(uname -m) go=$(go version | awk '{print $3}')" } case "$OS" in Linux|macOS) echo "→ Building VideoTools $APP_VERSION for $OS..." echo "" exec "$SCRIPT_DIR/build-linux.sh" ;; Windows) echo "→ Building VideoTools $APP_VERSION for Windows..." echo "" cd "$PROJECT_ROOT" echo "🧹 Cleaning previous builds..." rm -f VideoTools.exe 2>/dev/null || true echo "✓ Cache cleaned" echo "" echo "⬇️ Downloading dependencies..." go mod download echo "✓ Dependencies downloaded" echo "" echo "🔨 Building VideoTools $APP_VERSION for Windows..." export CGO_ENABLED=1 if go build -ldflags="-H windowsgui -s -w" -o VideoTools.exe .; then echo "✓ Build successful! (VideoTools $APP_VERSION)" echo "" if [ -f "setup-windows.bat" ]; then echo "════════════════════════════════════════════════════════════════" echo "✅ BUILD COMPLETE - $APP_VERSION" echo "════════════════════════════════════════════════════════════════" echo "" echo "Output: VideoTools.exe" if [ -f "VideoTools.exe" ]; then SIZE=$(du -h VideoTools.exe 2>/dev/null | cut -f1 || echo "unknown") echo "Size: $SIZE" fi diagnostics echo "" echo "Next step: Get FFmpeg" echo " Run: setup-windows.bat" echo " Or: .\\scripts\\setup-windows.ps1 -Portable" echo "" if ffmpeg -version >/dev/null 2>&1 && ffprobe -version >/dev/null 2>&1; then echo "FFmpeg detected on PATH. Skipping bundled download." else echo "FFmpeg not detected on PATH." echo "Next step: Get FFmpeg" echo " Run: setup-windows.bat" echo " Or: .\\scripts\\setup-windows.ps1 -Portable" echo "You can skip if FFmpeg is already installed elsewhere." fi else echo "✓ Build complete: VideoTools.exe" diagnostics fi else echo "❌ Build failed! (VideoTools $APP_VERSION)" diagnostics exit 1 fi ;; esac