diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-04-17 21:42:43 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-04-17 21:42:43 +0100 |
| commit | fb9210408c1d8792600410a08727b41404f6c418 (patch) | |
| tree | 48cbcf6a821570c43175f3df9b169310c0148b76 /entrypoint.mjs | |
| parent | 74799435dca411e9bb5aa59f4b8bdc6dd1384ad4 (diff) | |
| download | NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.gz NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.bz2 NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.tar.xz NuclearOptionDedicatedServerDocker-fb9210408c1d8792600410a08727b41404f6c418.zip | |
use node instead of bash
Diffstat (limited to 'entrypoint.mjs')
| -rw-r--r-- | entrypoint.mjs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/entrypoint.mjs b/entrypoint.mjs new file mode 100644 index 0000000..10c90d7 --- /dev/null +++ b/entrypoint.mjs @@ -0,0 +1,81 @@ +import { execFileSync } from "node:child_process"; +import { existsSync, readFileSync, writeFileSync, cpSync } from "node:fs"; + +const { STEAM_USERNAME = "", STEAM_PASSWORD = "" } = process.env; + +// Validate Steam credentials +if (STEAM_USERNAME === "anonymous") { + console.log("Using anonymous login. No password needed."); +} else if (!STEAM_USERNAME || !STEAM_PASSWORD) { + console.error( + "Please set STEAM_USERNAME and STEAM_PASSWORD environment variables.\n" + + "If you want to use anonymous login, set STEAM_USERNAME to 'anonymous' and leave STEAM_PASSWORD empty.", + ); + process.exit(1); +} + +// Install game server via steamcmd +execFileSync( + "steamcmd", + [ + "+login", + STEAM_USERNAME, + STEAM_PASSWORD || "", + "+force_install_dir", + "/app", + "+app_update", + "3930080", + "validate", + "+quit", + ], + { stdio: "inherit" }, +); + +// Apply overlay if it exists +if (existsSync("/overlay")) { + console.log("Applying overlay from /overlay to /app"); + cpSync("/overlay", "/app", { recursive: true }); +} + +// Handle configuration file changes via environment variables +const CONFIG_FIELDS = [ + { name: "MissionDirectory", type: "string" }, + { name: "ModdedServer", type: "boolean" }, + { name: "Hidden", type: "boolean" }, + { name: "ServerName", type: "string" }, + { name: "Password", type: "string" }, + { name: "MaxPlayers", type: "number" }, + { name: "DisableErrorKick", type: "boolean" }, + { name: "NoPlayerStopTime", type: "number" }, + { name: "PostMissionDelay", type: "number" }, + { name: "RotationType", type: "number" }, +]; + +const CONFIG_PATH = "/app/DedicatedServerConfig.json"; +const config = JSON.parse(readFileSync(CONFIG_PATH, "utf-8")); + +for (const { name, type } of CONFIG_FIELDS) { + const envVar = process.env[`CONFIG_${name.toUpperCase()}`]; + if (envVar == null || envVar === "") continue; + + console.log(`Setting ${name} to ${envVar} in ${CONFIG_PATH}`); + + if (!(name in config)) continue; + + switch (type) { + case "boolean": + config[name] = envVar === "true"; + break; + case "number": + config[name] = Number(envVar); + break; + default: + config[name] = envVar; + break; + } +} + +writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n"); + +// Run the server +execFileSync("sh", ["/app/RunServer.sh"], { stdio: "inherit" }); |
