Tag: minecraft linux auto update

  • Minecraft Linux Server Auto-Update

    Keeping your Minecraft Bedrock Dedicated Server up to date is essential for performance, stability, and player compatibility. In this guide, we’ll show you how to set up a lightweight Bash script that checks for new server versions and installs them, all while preserving your world and configuration files.

    Step 1: Install Dependencies

    sudo apt update
    sudo apt install curl jq unzip rsync wget

    Step 2: Create the Update Script

    Save the following as ~/update-bedrock.sh.:

    #!/usr/bin/env bash
    set -euo pipefail
    
    HOME_DIR="$HOME"
    INSTALL_DIR="$HOME_DIR/bedrock-server"
    TMP_DIR="$HOME_DIR/bedrock-tmp"
    API_URL="https://net-secondary.web.minecraft-services.net/api/v1.0/download/links"
    ZIP_NAME="bedrock.zip"
    
    command -v jq >/dev/null || { echo "jq is required"; exit 1; }
    
    echo "Fetching version info..."
    DATA=$(curl -fsSL "$API_URL")
    DOWNLOAD_URL=$(echo "$DATA" | jq -r '.result.links[] | select(.downloadType == "serverBedrockLinux") | .downloadUrl')
    VERSION=$(basename "$DOWNLOAD_URL" | grep -o '[0-9.]\+')
    
    [[ -z "$DOWNLOAD_URL" || -z "$VERSION" ]] && { echo "Failed to extract URL/version"; exit 1; }
    
    [[ -f "$INSTALL_DIR/bedrock-server.version" && "$(cat "$INSTALL_DIR/bedrock-server.version")" == "$VERSION" ]] && {
      echo "Already up to date"
      exit 0
    }
    
    mkdir -p "$TMP_DIR"
    wget -q -O "$TMP_DIR/$ZIP_NAME" "$DOWNLOAD_URL"
    unzip -t "$TMP_DIR/$ZIP_NAME" >/dev/null || { echo "ZIP test failed"; exit 1; }
    unzip -oq "$TMP_DIR/$ZIP_NAME" -d "$TMP_DIR/unpacked"
    
    [[ -x "$TMP_DIR/unpacked/bedrock_server" ]] || { echo "Missing server binary"; exit 1; }
    
    rsync -a \
      --exclude='autoupdate.sh' \
      --exclude='server.properties' \
      --exclude='permissions.json' \
      --exclude='whitelist.json' \
      --exclude='ops.json' \
      --exclude='allowlist.json' \
      --exclude='valid_known_packs.json' \
      --exclude='worlds/' \
      "$TMP_DIR/unpacked/" "$INSTALL_DIR/"
    
    echo "$VERSION" > "$INSTALL_DIR/bedrock-server.version"
    rm -rf "$TMP_DIR"
    echo "Updated to version $VERSION"
    

    Step 3: Make It Executable

    chmod +x ~/update-bedrock.sh

    Step 4: Automate with Cron (Optional)

    Edit your crontab with crontab -e and add this line to check daily at 3 AM:

    0 3 * * * ~/update-bedrock.sh >> ~/bedrock-update.log 2>&1

    Done ✅

    You now have a self-maintaining Minecraft Bedrock server that stays updated automatically!