Update start.sh
Browse files123456789101 unmodified line12131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143#!/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 /datasudo chmod -R 775 /datacd /dataelseecho "[Warning] No /data bucket found. World will reset on restart!"1 unmodified linecd /app/serverfi# Clean up old/corrupted jars to ensure fresh downloadsecho "[System] Cleaning up old jars..."rm -f plugins/Via*.jarrm -f plugins/EaglerX*.jarrm -f server.jarmkdir -p logsecho "[System] Clearing Paperclip cache..."rm -rf cache# Install the official HTTP Proxy moduleecho "[System] Installing WebSocket Proxy Dependencies..."npm install http-proxy# 2. Download Paper 1.12.2echo "[System] Downloading Paper 1.12.2..."curl -sL -A "Mozilla/5.0" -o server.jar "https://api.papermc.io/v2/projects/paper/versions/1.12.2/builds/1620/downloads/paper-1.12.2-1620.jar"mkdir -p plugins/EaglercraftXServerrm -rf plugins/# 3. Download Plugins using curl (Follows redirects and spoofs browser)echo "[System] Fetching EaglerXServer & EaglerXRewind..."curl -sL -A "Mozilla/5.0" -o plugins/EaglerXServer.jar "https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXServer.jar"curl -sL -A "Mozilla/5.0" -o plugins/EaglerXRewind.jar "https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXRewind.jar"echo "[System] Fetching ViaVersion Suite from Official Paper Hangar..."curl -sL -A "Mozilla/5.0" -o plugins/ViaVersion.jar "https://github.com/ViaVersion/ViaVersion/releases/download/5.8.1/ViaVersion-5.8.1.jar"curl -sL -A "Mozilla/5.0" -o plugins/ViaBackwards.jar "https://cdn.modrinth.com/data/NpvuJQoq/versions/8YdMHUIl/ViaBackwards-5.9.0-SNAPSHOT.jar"curl -sL -A "Mozilla/5.0" -o plugins/ViaRewind.jar "https://cdn.modrinth.com/data/TbHIxhx5/versions/r3AZ5yTY/ViaRewind-4.1.0-SNAPSHOT.jar"# 4. Accept EULA and Set Base Propertiesecho "eula=true" > eula.txtecho "server-port=25565" > server.propertiesecho "online-mode=false" >> server.properties# 5. 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: falseforward_ip: trueEOF# 6. GENERATE THE NODE.JS MASTER CONTROLLERcat << 'EOF' > webconsole.jsconst http = require('http');const fs = require('fs');const { spawn, exec } = require('child_process');const httpProxy = require('http-proxy');console.log('=========================================');console.log(' Starting Eaglercraft & Web Console ');console.log('=========================================');const mcProcess = spawn('java', ['-Xms2G', '-Xmx2G', '-jar', 'server.jar', 'nogui']);const logStream = fs.createWriteStream('logs/latest.log', { flags: 'w' });mcProcess.stdout.pipe(logStream);mcProcess.stderr.pipe(logStream);mcProcess.stdout.pipe(process.stdout);mcProcess.stderr.pipe(process.stderr);const proxy = httpProxy.createProxyServer({target: 'ws://127.0.0.1:25566',ws: true});proxy.on('error', (err) => {console.log('[Proxy] Error routing to server: (Is it still booting up?)', err.message);});const server = http.createServer((req, res) => {if (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>`);} else if (req.method === 'GET' && req.url === '/logs') {exec('tail -n 150 logs/latest.log', (err, stdout) => {res.writeHead(200, { 'Content-Type': 'text/plain' });res.end(stdout || 'Starting server... please wait.');});} else 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 && mcProcess.stdin.writable) {mcProcess.stdin.write(cmd + '\n');}res.writeHead(200); res.end();});} else {res.writeHead(404); res.end();}});server.on('upgrade', (req, socket, head) => {console.log('[Proxy] Routing incoming player WebSocket to Eaglercraft...');proxy.ws(req, socket, head);});server.listen(7860, () => console.log('[WebConsole] Listening on Port 7860...'));EOF# 7. Start the Master Controllerexec node webconsole.js123456789101112131 unmodified line15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295#!/bin/bashset -e# βββββββββββββββββββββββββββββββββββββββββββββ# 1. Resolve Working Directory# βββββββββββββββββββββββββββββββββββββββββββββif [ -d "/data" ]; thenecho "[System] Persistent /data bucket found. Taking ownership..."sudo chown -R minecraft:minecraft /data 2>/dev/null || truesudo chmod -R 775 /data 2>/dev/null || truecd /dataelseecho "[Warning] No /data bucket found. World will reset on restart!"1 unmodified linecd /app/serverfiWORKDIR=$(pwd)echo "[System] Working directory: $WORKDIR"# βββββββββββββββββββββββββββββββββββββββββββββ# 2. Clean Up Old/Corrupted Files# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Cleaning up old jars..."# Only remove specific old plugin jars, NOT the whole plugins dir yetrm -f plugins/Via*.jarrm -f plugins/EaglerX*.jarrm -f server.jarecho "[System] Clearing Paperclip cache..."rm -rf cachemkdir -p logsmkdir -p plugins/EaglercraftXServer# βββββββββββββββββββββββββββββββββββββββββββββ# 3. Install Node.js Dependencies# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Installing WebSocket proxy dependencies..."npm install http-proxy --save 2>&1 | tail -1# βββββββββββββββββββββββββββββββββββββββββββββ# 4. Download Paper 1.12.2# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Downloading Paper 1.12.2..."curl -fsSL \-A "Mozilla/5.0" \-o server.jar \"https://api.papermc.io/v2/projects/paper/versions/1.12.2/builds/1620/downloads/paper-1.12.2-1620.jar"if [ ! -s server.jar ]; thenecho "[Error] server.jar download failed or is empty. Aborting."exit 1fiecho "[System] server.jar downloaded successfully ($(du -sh server.jar | cut -f1))."# βββββββββββββββββββββββββββββββββββββββββββββ# 5. Download Plugins# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Downloading EaglerXServer & EaglerXRewind..."curl -fsSL -A "Mozilla/5.0" \-o plugins/EaglerXServer.jar \"https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXServer.jar"curl -fsSL -A "Mozilla/5.0" \-o plugins/EaglerXRewind.jar \"https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXRewind.jar"echo "[System] Downloading ViaVersion suite..."curl -fsSL -A "Mozilla/5.0" \-o plugins/ViaVersion.jar \"https://github.com/ViaVersion/ViaVersion/releases/download/5.8.1/ViaVersion-5.8.1.jar"curl -fsSL -A "Mozilla/5.0" \-o plugins/ViaBackwards.jar \"https://cdn.modrinth.com/data/NpvuJQoq/versions/8YdMHUIl/ViaBackwards-5.9.0-SNAPSHOT.jar"curl -fsSL -A "Mozilla/5.0" \-o plugins/ViaRewind.jar \"https://cdn.modrinth.com/data/TbHIxhx5/versions/r3AZ5yTY/ViaRewind-4.1.0-SNAPSHOT.jar"# Verify all plugins downloadedecho "[System] Verifying plugin downloads..."for jar in \plugins/EaglerXServer.jar \plugins/EaglerXRewind.jar \plugins/ViaVersion.jar \plugins/ViaBackwards.jar \plugins/ViaRewind.jardoif [ ! -s "$jar" ]; thenecho "[Error] $jar is missing or empty! Aborting."exit 1fiecho " [OK] $jar ($(du -sh "$jar" | cut -f1))"done# βββββββββββββββββββββββββββββββββββββββββββββ# 6. Server Configuration# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Writing eula.txt and server.properties..."echo "eula=true" > eula.txtcat > server.properties << 'PROPS'server-port=25565online-mode=falsemotd=Eaglercraft Servermax-players=60PROPS# βββββββββββββββββββββββββββββββββββββββββββββ# 7. EaglerXServer Listener Config# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Writing EaglercraftXServer listener config..."cat > plugins/EaglercraftXServer/listeners.yml << 'LISTENEOF'listeners:- address: 127.0.0.1:25566motd: "&dEaglercraftX\n&ePowered by EaglerXServer"max_players: 60online_mode: falseforward_ip: trueLISTENEOF# βββββββοΏ½οΏ½βββββββββββββββββββββββββββββββββββββ# 8. Generate Node.js Web Console# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Writing webconsole.js..."cat > webconsole.js << 'NODEEOF''use strict';const http = require('http');const fs = require('fs');const path = require('path');const { spawn, exec } = require('child_process');const httpProxy = require('http-proxy');const LOG_FILE = path.join(__dirname, 'logs', 'latest.log');const MC_PORT = 25566; // EaglerXServer internal WS portconst WEB_PORT = 7860; // Exposed port// ββ Banner ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconsole.log('=========================================');console.log(' Eaglercraft Server + Web Console ');console.log('=========================================');// ββ Start Minecraft βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst mcProcess = spawn('java', ['-Xms2G', '-Xmx2G','-XX:+UseG1GC','-jar', 'server.jar', 'nogui'], { cwd: __dirname });const logStream = fs.createWriteStream(LOG_FILE, { flags: 'w' });mcProcess.stdout.pipe(logStream, { end: false });mcProcess.stderr.pipe(logStream, { end: false });mcProcess.stdout.pipe(process.stdout);mcProcess.stderr.pipe(process.stderr);mcProcess.on('exit', (code) => {console.log(`[MC] Server process exited with code ${code}`);logStream.end();});// ββ WebSocket Proxy βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst proxy = httpProxy.createProxyServer({target: `ws://127.0.0.1:${MC_PORT}`,ws: true});proxy.on('error', (err, req, socket) => {console.warn('[Proxy] Routing error (server may still be booting):', err.message);if (socket && socket.writable) socket.destroy();});// ββ HTML Page βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst PAGE_HTML = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Eaglercraft Console</title><style>* { box-sizing: border-box; margin: 0; padding: 0; }body {background: #1e1e1e; color: #d4d4d4;font-family: 'Consolas', monospace;display: flex; flex-direction: column;height: 100vh; padding: 16px; gap: 12px;}h2 { color: #569cd6; font-size: 1.1rem; }#logs {flex: 1; overflow-y: auto; white-space: pre-wrap; word-break: break-all;background: #0d0d0d; padding: 12px;border: 1px solid #333; border-radius: 4px;font-size: 0.82rem; line-height: 1.45;}form { display: flex; gap: 8px; }input[type=text] {flex: 1; padding: 9px 12px;background: #2d2d2d; color: #fff;border: 1px solid #444; border-radius: 4px; font-family: inherit;}button {padding: 9px 20px; background: #0e639c; color: #fff;border: none; border-radius: 4px; cursor: pointer; font-family: inherit;}button:hover { background: #1177bb; }</style></head><body><h2>▶ Eaglercraft Live Console</h2><div id="logs">Connecting to server logβ¦</div><form action="/command" method="POST" target="_blank"onsubmit="setTimeout(()=>this.reset(),10)"><input type="text" name="cmd"placeholder="e.g. op YourName | say Hello!"autocomplete="off" autofocus><button type="submit">Send</button></form><script>const logs = document.getElementById('logs');let last = '';async function poll() {try {const t = await fetch('/logs').then(r => r.text());if (t !== last) {last = t;const atBottom =logs.scrollHeight - logs.clientHeight <= logs.scrollTop + 60;logs.textContent = t;if (atBottom) logs.scrollTop = logs.scrollHeight;}} catch(_) {}setTimeout(poll, 1000);}poll();</script></body></html>`;// ββ HTTP Server βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst server = http.createServer((req, res) => {// ββ GET / β console pageif (req.method === 'GET' && req.url === '/') {res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });return res.end(PAGE_HTML);}// ββ GET /logs β last 200 lines of logif (req.method === 'GET' && req.url === '/logs') {exec(`tail -n 200 "${LOG_FILE}"`, (err, stdout) => {res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });res.end(stdout || '(Waiting for server outputβ¦)');});return;}// ββ POST /command β write to MC stdinif (req.method === 'POST' && req.url === '/command') {let body = '';req.on('data', chunk => { body += chunk; });req.on('end', () => {const cmd = new URLSearchParams(body).get('cmd') || '';const safe = cmd.trim().replace(/[\r\n]+/g, ''); // no newline injectionif (safe && mcProcess.stdin.writable) {mcProcess.stdin.write(safe + '\n');console.log(`[Console] Command sent: ${safe}`);}res.writeHead(200, { 'Content-Type': 'text/plain' });res.end('ok');});return;}res.writeHead(404);res.end('Not found');});// ββ Upgrade β proxy WebSocket to Eaglercraftserver.on('upgrade', (req, socket, head) => {console.log(`[Proxy] WS upgrade from ${socket.remoteAddress} β MC:${MC_PORT}`);proxy.ws(req, socket, head);});server.listen(WEB_PORT, '0.0.0.0', () => {console.log(`[WebConsole] Listening on http://0.0.0.0:${WEB_PORT}`);});NODEEOF# βββββββββββββββββββββββββββββββββββββββββββββ# 9. Launch# βββββββββββββββββββββββββββββββββββββββββββββecho "[System] Handing off to Node.js master controller..."exec node webconsole.js
start.sh+236-84