server / prepare.sh
pabla1322's picture
Upload 17 files
722781c verified
Raw
History Blame Contribute Delete
2.58 kB
#!/bin/bash
set -e
# ── Helper: retry a command up to N times ────────────────────────────
retry() {
local n=1 max=4 delay=5
until "$@"; do
if [ $n -ge $max ]; then
echo "[ERROR] Command failed after $max attempts: $*"
exit 1
fi
echo "[RETRY] Attempt $n/$max failed. Retrying in ${delay}s..."
sleep $delay
n=$((n + 1))
delay=$((delay * 2))
done
}
# ── Download Minecraft Bedrock Dedicated Server ───────────────────────
echo "[*] Fetching Minecraft Bedrock download URL..."
MINECRAFT_PAGE=$(curl -fsSL \
--retry 3 --retry-delay 3 \
-H "Accept-Language: en-US,en;q=0.9" \
-H "Accept: text/html" \
-A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
"https://www.minecraft.net/en-us/download/server/bedrock")
# Try multiple URL patterns (Minecraft changes these sometimes)
MINECRAFT_URL=$(echo "$MINECRAFT_PAGE" | grep -oP 'https://[^"]+bin-linux/[^"]+\.zip' | head -1)
if [ -z "$MINECRAFT_URL" ]; then
MINECRAFT_URL=$(echo "$MINECRAFT_PAGE" | grep -oP 'https://minecraft\.azureedge\.net/bin-linux/[^"]+' | head -1)
fi
if [ -z "$MINECRAFT_URL" ]; then
MINECRAFT_URL=$(echo "$MINECRAFT_PAGE" | grep -oP 'https://[^"]*bedrock[^"]*linux[^"]*\.zip' | head -1)
fi
if [ -z "$MINECRAFT_URL" ]; then
echo "[ERROR] Could not find Minecraft Bedrock download URL."
echo " Minecraft.net may have changed its page layout."
echo " Page snippet:"
echo "$MINECRAFT_PAGE" | grep -i "bedrock" | head -5
exit 1
fi
echo "[OK] Found URL: $MINECRAFT_URL"
echo "[*] Downloading Minecraft Bedrock server..."
retry curl -fsSL --retry 3 -o /tmp/bedrock-server.zip "$MINECRAFT_URL"
echo "[*] Extracting..."
unzip -o /tmp/bedrock-server.zip -d /data/bedrock-server > /dev/null
rm /tmp/bedrock-server.zip
chmod +x /data/bedrock-server/bedrock_server
echo "[OK] Minecraft Bedrock server installed."
# ── Download playit agent ─────────────────────────────────────────────
echo "[*] Downloading playit agent..."
retry curl -fsSL --retry 3 \
-o /usr/local/bin/playit \
"https://github.com/playit-cloud/playit-agent/releases/latest/download/playit-linux-amd64"
chmod +x /usr/local/bin/playit
echo "[OK] playit agent installed: $(playit --version 2>/dev/null || echo 'version unknown')"
echo ""
echo "===== prepare.sh complete ====="