Files
hydra/scripts/postinstall.cjs

71 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2024-09-25 19:37:28 +01:00
const { default: axios } = require("axios");
2025-04-17 23:23:06 +01:00
const tar = require("tar");
2024-09-25 19:37:28 +01:00
const util = require("node:util");
const fs = require("node:fs");
const path = require("node:path");
const exec = util.promisify(require("node:child_process").exec);
2025-04-17 23:23:06 +01:00
const ludusaviVersion = "0.29.0";
2024-09-25 19:37:28 +01:00
const fileName = {
2025-04-18 00:06:30 +01:00
win32: `ludusavi-v${ludusaviVersion}-win64.zip`,
2025-04-17 23:23:06 +01:00
linux: `ludusavi-v${ludusaviVersion}-linux.tar.gz`,
darwin: `ludusavi-v${ludusaviVersion}-mac.tar.gz`,
2024-09-25 19:37:28 +01:00
};
2025-05-12 01:58:29 +01:00
const ludusaviBinaryName = {
win32: "ludusavi.exe",
linux: "ludusavi",
darwin: "ludusavi",
};
2024-09-25 19:37:28 +01:00
const downloadLudusavi = async () => {
2025-05-12 01:58:29 +01:00
if (
fs.existsSync(
path.join(process.cwd(), "ludusavi", ludusaviBinaryName[process.platform])
)
) {
2024-09-25 19:37:28 +01:00
console.log("Ludusavi already exists, skipping download...");
return;
}
const file = fileName[process.platform];
2025-04-17 23:23:06 +01:00
const downloadUrl = `https://github.com/mtkennerly/ludusavi/releases/download/v${ludusaviVersion}/${file}`;
2024-09-25 19:37:28 +01:00
console.log(`Downloading ${file}...`);
const response = await axios.get(downloadUrl, { responseType: "stream" });
const stream = response.data.pipe(fs.createWriteStream(file));
stream.on("finish", async () => {
console.log(`Downloaded ${file}, extracting...`);
const pwd = process.cwd();
const targetPath = path.join(pwd, "ludusavi");
2025-04-17 23:23:06 +01:00
await fs.promises.mkdir(targetPath, { recursive: true });
2025-04-18 00:06:30 +01:00
if (process.platform === "win32") {
await exec(`npx extract-zip ${file} ${targetPath}`);
} else {
await tar.x({
file: file,
cwd: targetPath,
});
}
if (process.platform !== "win32") {
fs.chmodSync(path.join(targetPath, "ludusavi"), 0o755);
}
2024-09-25 19:37:28 +01:00
console.log("Extracted. Renaming folder...");
console.log(`Extracted ${file}, removing compressed downloaded file...`);
fs.rmSync(file);
});
};
2025-04-15 15:41:08 +01:00
downloadLudusavi();