mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Merge pull request #816 from Cooldude2606/fix/download-headless
Fix headless download
This commit is contained in:
1 file changed
+9
-6
@@ -754,8 +754,8 @@ async function inquirerMissingArgs(args) {
|
|||||||
async function downloadLinuxServer() {
|
async function downloadLinuxServer() {
|
||||||
let res = await fetch("https://factorio.com/get-download/stable/headless/linux64");
|
let res = await fetch("https://factorio.com/get-download/stable/headless/linux64");
|
||||||
|
|
||||||
const url = new URL(res.headers.location);
|
|
||||||
// get the filename of the latest factorio archive from redirected url
|
// get the filename of the latest factorio archive from redirected url
|
||||||
|
const url = new URL(res.url); // The res is redirects, need final url
|
||||||
const filename = path.posix.basename(url.pathname);
|
const filename = path.posix.basename(url.pathname);
|
||||||
const match = filename.match(/(?<=factorio_headless_x64_|factorio-headless_linux_)\d+\.\d+\.\d+(?=\.tar\.xz)/);
|
const match = filename.match(/(?<=factorio_headless_x64_|factorio-headless_linux_)\d+\.\d+\.\d+(?=\.tar\.xz)/);
|
||||||
if (!match || !match.length) {
|
if (!match || !match.length) {
|
||||||
@@ -772,10 +772,7 @@ async function downloadLinuxServer() {
|
|||||||
if (await fs.pathExists(factorioDir)) {
|
if (await fs.pathExists(factorioDir)) {
|
||||||
logger.warn(`setting downloadDir to ${factorioDir}, but not downloading because already existing`);
|
logger.warn(`setting downloadDir to ${factorioDir}, but not downloading because already existing`);
|
||||||
} else {
|
} else {
|
||||||
await fs.ensureDir(tmpDir);
|
await fs.emptyDir(tmpDir);
|
||||||
|
|
||||||
// follow the redirect
|
|
||||||
res = await fetch(url.href);
|
|
||||||
|
|
||||||
logger.info("Downloading latest Factorio server release. This may take a while.");
|
logger.info("Downloading latest Factorio server release. This may take a while.");
|
||||||
const writeStream = fs.createWriteStream(tmpArchivePath);
|
const writeStream = fs.createWriteStream(tmpArchivePath);
|
||||||
@@ -794,8 +791,10 @@ async function downloadLinuxServer() {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.unlink(archivePath);
|
await fs.ensureDir("factorio");
|
||||||
await fs.rename(tmpFactorioDir, factorioDir);
|
await fs.rename(tmpFactorioDir, factorioDir);
|
||||||
|
await fs.unlink(archivePath);
|
||||||
|
await fs.rm(tmpDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,6 +820,10 @@ async function main() {
|
|||||||
.option("http-port", {
|
.option("http-port", {
|
||||||
nargs: 1, describe: "HTTP port to listen on [standalone/controller]", type: "number",
|
nargs: 1, describe: "HTTP port to listen on [standalone/controller]", type: "number",
|
||||||
})
|
})
|
||||||
|
.option("download-headless", {
|
||||||
|
describe: "Download the latest headless release [standalone/controller] [linux only]",
|
||||||
|
type: "boolean", nargs: 0,
|
||||||
|
})
|
||||||
.option("host-name", {
|
.option("host-name", {
|
||||||
nargs: 1, describe: "Host name [host]", type: "string",
|
nargs: 1, describe: "Host name [host]", type: "string",
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user