#!/bin/bash set -e # Build xdvdfs-tools from source # Tool for working with Xbox 360 ISO images (Rust-based) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" XDVDFS_DIR="$SCRIPT_DIR/src" BUILD_DIR="$SCRIPT_DIR/build" BIN_DIR="$SCRIPT_DIR/../bin" echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Build xdvdfs-tools (Xbox 360) ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" # Check if source exists if [ ! -d "$XDVDFS_DIR" ]; then echo "❌ xdvdfs-tools source not found!" echo " Please run ./clone.sh first to download the source." exit 1 fi cd "$XDVDFS_DIR" # Show version info if [ -f "$SCRIPT_DIR/VERSION.txt" ]; then echo "📝 Building from:" grep -E "^(Short|Tag|Date):" "$SCRIPT_DIR/VERSION.txt" | sed 's/^/ /' echo "" fi # Check dependencies echo "🔍 Checking build dependencies..." echo "" MISSING_DEPS=() # Check for Rust/Cargo if ! command -v cargo &> /dev/null; then MISSING_DEPS+=("cargo (Rust toolchain)") fi if ! command -v rustc &> /dev/null; then MISSING_DEPS+=("rustc (Rust compiler)") fi if [ ${#MISSING_DEPS[@]} -gt 0 ]; then echo "⚠️ Missing dependencies: ${MISSING_DEPS[*]}" echo "" echo "Install Rust toolchain with:" echo " curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" echo "" echo "Or via package manager:" echo " sudo apt-get install cargo rustc" echo "" read -p "🤔 Try to continue anyway? (y/N) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Build configuration echo "🔧 Build configuration:" echo " Cargo build system (Rust)" echo " Release build with optimizations" echo "" # Clean old build (optional) if [ -d "target/release" ]; then echo "" read -p "🧹 Clean previous build? (Y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Nn]$ ]]; then echo "🧹 Cleaning previous build..." cargo clean fi fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔨 Starting build..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "⏱️ This may take a few minutes (first build compiles dependencies)..." echo "" START_TIME=$(date +%s) # Run the build with release optimizations if cargo build --release; then END_TIME=$(date +%s) DURATION=$((END_TIME - START_TIME)) echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ Build completed successfully in ${DURATION}s!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # Find the built binaries RELEASE_DIR="$XDVDFS_DIR/target/release" if [ ! -d "$RELEASE_DIR" ]; then echo "⚠️ Could not find release directory!" exit 1 fi # Create build directory and copy binaries mkdir -p "$BUILD_DIR" echo "📦 Installing binaries to: $BUILD_DIR" echo "" # Copy all built binaries (xdvdfs has multiple tools) COPIED_COUNT=0 for binary in "$RELEASE_DIR"/xdvdfs*; do if [ -f "$binary" ] && [ -x "$binary" ]; then BASENAME=$(basename "$binary") cp "$binary" "$BUILD_DIR/$BASENAME" chmod +x "$BUILD_DIR/$BASENAME" # Get binary size SIZE=$(du -h "$BUILD_DIR/$BASENAME" | cut -f1) echo " ✅ $BASENAME ($SIZE)" # Create symlink in bin directory mkdir -p "$BIN_DIR" ln -sf "../xdvdfs-tools/build/$BASENAME" "$BIN_DIR/$BASENAME" COPIED_COUNT=$((COPIED_COUNT + 1)) fi done if [ $COPIED_COUNT -eq 0 ]; then echo " ⚠️ No binaries found!" exit 1 fi echo "" echo "🔗 Symlinks created in: $BIN_DIR" # Save build info BUILD_INFO_FILE="$BUILD_DIR/BUILD_INFO.txt" cat > "$BUILD_INFO_FILE" << EOF xdvdfs-tools Build Information Built: $(date) Build time: ${DURATION}s Source: $(cat "$SCRIPT_DIR/VERSION.txt" 2>/dev/null || echo "Version info not available") Build options: Command: cargo build --release Rust version: $(rustc --version 2>/dev/null || echo "unknown") Cargo version: $(cargo --version 2>/dev/null || echo "unknown") Binaries ($COPIED_COUNT total): $(ls -lh "$BUILD_DIR" | grep -v "^total" | grep -v ".txt" | awk '{print " " $9 " (" $5 ")"}') EOF echo "" echo "🧪 Testing built binaries..." echo "" for binary in "$BUILD_DIR"/xdvdfs*; do if [ -f "$binary" ] && [ -x "$binary" ]; then BASENAME=$(basename "$binary") echo "Testing $BASENAME:" "$binary" --help 2>&1 | head -5 || true echo "" fi done cat "$BUILD_INFO_FILE" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ All done!" echo "" echo "Usage:" echo " $BIN_DIR/xdvdfs --help" echo "" echo "Common operations:" echo " # List Xbox 360 ISO contents" echo " $BIN_DIR/xdvdfs list game.iso" echo "" echo " # Extract Xbox 360 ISO" echo " $BIN_DIR/xdvdfs unpack game.iso output_dir/" echo "" echo " # Create Xbox 360 ISO from directory" echo " $BIN_DIR/xdvdfs pack input_dir/ game.iso" echo "" echo "Or add to PATH:" echo " export PATH=\"$BIN_DIR:\$PATH\"" echo " xdvdfs --help" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" else echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "❌ Build failed!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Common issues:" echo " 1. Missing Rust toolchain - install from: https://rustup.rs" echo " 2. Outdated Rust version - update with: rustup update" echo " 3. Check build output above for specific errors" echo "" exit 1 fi