Update start.sh
Browse files1234565 unmodified lines121314151617181913 unmodified lines33343536373839404142434445464748495051525354554 unmodified lines606162636465666768697071727374757677#!/bin/bash# 1. Bucket Permission Bypass (Forces Hugging Face to unlock /data)if [ -d "/data" ]; thenecho "[System] Bucket found! Executing Root Bypass to take ownership of /data..."sudo chown -R minecraft:minecraft /data5 unmodified linescd /app/serverfi# Clean up ALL old plugin jars so we always get the newest onesecho "[System] Cleaning up old plugin jars for auto-update..."rm -f plugins/Via*.jarrm -f plugins/EaglerX*.jar13 unmodified lineswget -q -O plugins/EaglerXServer.jar "https://github.com$EAGLER_PATH"wget -q -O plugins/EaglerXRewind.jar "https://github.com$REWIND_PATH"# 4. Jenkins CI Auto-Updater Function for the ViaVersion Suitefetch_via() {JOB_NAME=$1JAR_NAME=$2echo "[System] Fetching latest $JAR_NAME from Jenkins CI..."# Query the Jenkins API for the relative path of the newest compiled artifactREL_PATH=$(curl -s "https://ci.viaversion.com/job/$JOB_NAME/lastSuccessfulBuild/api/json" | jq -r '.artifacts[] | select(.fileName | endswith(".jar")) | .relativePath' | head -n 1)if [ -n "$REL_PATH" ] && [ "$REL_PATH" != "null" ]; thenwget -q -O "plugins/$JAR_NAME" "https://ci.viaversion.com/job/$JOB_NAME/lastSuccessfulBuild/artifact/$REL_PATH"elseecho "[Error] Failed to find artifact for $JOB_NAME on Jenkins!"fi}# Download all Via plugins straight from the CIfetch_via "ViaVersion" "ViaVersion.jar"fetch_via "ViaBackwards" "ViaBackwards.jar"fetch_via "ViaRewind" "ViaRewind.jar"4 unmodified linesecho "server-port=25565" > server.propertiesecho "online-mode=false" >> server.properties# 6. Configure EaglerXServer to listen on Hugging Face Port 7860cat << 'EOF' > plugins/EaglercraftXServer/listeners.ymllisteners:- address: 0.0.0.0:7860motd: "&dEaglercraftX on Hugging Face\n&ePowered by EaglerXServer"max_players: 60online_mode: falseEOFecho "========================================="echo " Starting EaglerXServer "echo "========================================="# 7. Start the Serverexec java -Xms2G -Xmx2G -jar server.jar nogui1234565 unmodified lines121314151617181920212213 unmodified lines363738394041424344454647484950514 unmodified lines5657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154#!/bin/bash# 1. Bucket Permission Bypassif [ -d "/data" ]; thenecho "[System] Bucket found! Executing Root Bypass to take ownership of /data..."sudo chown -R minecraft:minecraft /data5 unmodified linescd /app/serverfi# Ensure log directory exists so the Web Console doesn't crash on first bootmkdir -p logstouch logs/latest.log# Clean up old jars to force auto-updatesrm -f plugins/Via*.jarrm -f plugins/EaglerX*.jar13 unmodified lineswget -q -O plugins/EaglerXServer.jar "https://github.com$EAGLER_PATH"wget -q -O plugins/EaglerXRewind.jar "https://github.com$REWIND_PATH"# 4. Jenkins CI Auto-Updater for ViaVersion Suitefetch_via() {JOB_NAME=$1JAR_NAME=$2echo "[System] Fetching latest $JAR_NAME from Jenkins CI..."REL_PATH=$(curl -s "https://ci.viaversion.com/job/$JOB_NAME/lastSuccessfulBuild/api/json" | jq -r '.artifacts[] | select(.fileName | endswith(".jar")) | .relativePath' | head -n 1)if [ -n "$REL_PATH" ] && [ "$REL_PATH" != "null" ]; thenwget -q -O "plugins/$JAR_NAME" "https://ci.viaversion.com/job/$JOB_NAME/lastSuccessfulBuild/artifact/$REL_PATH"fi}fetch_via "ViaVersion" "ViaVersion.jar"fetch_via "ViaBackwards" "ViaBackwards.jar"fetch_via "ViaRewind" "ViaRewind.jar"4 unmodified linesecho "server-port=25565" > server.propertiesecho "online-mode=false" >> server.properties# 6. Configure EaglerXServer to listen on an INTERNAL port (25566)cat << 'EOF' > plugins/EaglercraftXServer/listeners.ymllisteners:- address: 127.0.0.1:25566motd: "&dEaglercraftX on Hugging Face\n&ePowered by EaglerXServer"max_players: 60online_mode: falseEOF# 7. GENERATE THE NODE.JS WEB CONSOLE & MULTIPLEXERcat << 'EOF' > /app/webconsole.jsconst http = require('http');const net = require('net');const { exec } = require('child_process');const server = http.createServer((req, res) => {// Serve the Web Console HTML UIif (req.method === 'GET' && req.url === '/') {res.writeHead(200, { 'Content-Type': 'text/html' });res.end(`<html><body style="background: #1e1e1e; color: #d4d4d4; font-family: monospace; margin: 0; padding: 20px;"><h2 style="color: #569cd6; margin-top: 0;">Eaglercraft Live Console</h2><pre id="logs" style="height: 70vh; overflow-y: scroll; background: #000; padding: 15px; border: 1px solid #333; border-radius: 5px;"></pre><form action="/command" method="POST" target="hiddenFrame" onsubmit="setTimeout(()=>this.reset(), 10)" style="margin-top: 15px; display: flex;"><input type="text" name="cmd" style="flex-grow: 1; padding: 10px; background: #2d2d2d; color: white; border: 1px solid #444; border-radius: 3px;" placeholder="Type a command (e.g. op username)..." autocomplete="off" autofocus><button type="submit" style="padding: 10px 20px; background: #0e639c; color: white; border: none; border-radius: 3px; margin-left: 10px; cursor: pointer;">Send</button></form><iframe name="hiddenFrame" style="display:none;"></iframe><script>const logs = document.getElementById('logs');setInterval(() => {fetch('/logs').then(r => r.text()).then(t => {let isBottom = logs.scrollHeight - logs.clientHeight <= logs.scrollTop + 50;logs.textContent = t;if(isBottom) logs.scrollTop = logs.scrollHeight;});}, 1000);</script></body></html>`);}// API: Fetch the last 150 lines of the server logelse if (req.method === 'GET' && req.url === '/logs') {exec('tail -n 150 /data/logs/latest.log', (err, stdout) => {res.writeHead(200, { 'Content-Type': 'text/plain' });res.end(stdout || 'Starting server... please wait.');});}// API: Send a command to the Minecraft server via tmuxelse if (req.method === 'POST' && req.url === '/command') {let body = '';req.on('data', c => body += c);req.on('end', () => {const cmd = new URLSearchParams(body).get('cmd');if (cmd) exec(`tmux send-keys -t mc "${cmd}" ENTER`);res.writeHead(200); res.end();});} else {res.writeHead(404); res.end();}});// Proxy WebSocket connections to Eaglercraft!server.on('upgrade', (req, clientSocket, head) => {const serverSocket = net.connect(25566, '127.0.0.1', () => {let headers = \`\${req.method} \${req.url} HTTP/\${req.httpVersion}\r\n\`;for (let i = 0; i < req.rawHeaders.length; i += 2) {headers += \`\${req.rawHeaders[i]}: \${req.rawHeaders[i+1]}\r\n\`;}headers += '\r\n';serverSocket.write(headers);serverSocket.write(head);clientSocket.pipe(serverSocket);serverSocket.pipe(clientSocket);});serverSocket.on('error', () => clientSocket.end());clientSocket.on('error', () => serverSocket.end());});server.listen(7860, () => console.log('[WebConsole] Listening on Port 7860'));EOFecho "========================================="echo " Starting Eaglercraft & Web Console "echo "========================================="# 8. Start the Web Console Multiplexer in the backgroundnode /app/webconsole.js &# 9. Start the Minecraft Server inside a detached 'tmux' session# (This allows the Web Console to securely type commands into it)tmux new-session -d -s mc "java -Xms2G -Xmx2G -jar server.jar nogui"# 10. Tail the log file to keep the Docker container alive and print to HF Logstail -f logs/latest.log
start.sh+93-16