magalh 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mgl.js +53 -5
- package/msh.js +1 -1
- package/package.json +1 -1
package/bin/mgl.js
CHANGED
|
@@ -12,19 +12,67 @@ const rootDir = path.resolve(__dirname, "..");
|
|
|
12
12
|
if (args.includes("--help") || args.includes("-h")) {
|
|
13
13
|
process.stdout.write(
|
|
14
14
|
[
|
|
15
|
-
"
|
|
15
|
+
"magalh - Magala Media Server",
|
|
16
16
|
"",
|
|
17
17
|
"Usage:",
|
|
18
|
-
"
|
|
19
|
-
"",
|
|
20
|
-
"
|
|
21
|
-
" - Pass PORTS env var to control ports (e.g., PORTS=80,800,737)",
|
|
18
|
+
" magalh [--help]",
|
|
19
|
+
" magalh --install-service",
|
|
20
|
+
" magalh --upgrade-node",
|
|
22
21
|
"",
|
|
23
22
|
].join("\n"),
|
|
24
23
|
);
|
|
25
24
|
process.exit(0);
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
if (args.includes("--upgrade-node")) {
|
|
28
|
+
if (process.platform !== "linux") {
|
|
29
|
+
console.log("[magalh] --upgrade-node is only supported on Linux.");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var MIN_NODE_MAJOR = 20;
|
|
34
|
+
var current = parseInt(process.versions.node.split(".")[0], 10);
|
|
35
|
+
|
|
36
|
+
if (current >= MIN_NODE_MAJOR) {
|
|
37
|
+
console.log("[magalh] Node.js v" + process.versions.node + " is already v" + MIN_NODE_MAJOR + "+. No upgrade needed.");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log("[magalh] Node.js v" + process.versions.node + " is too old. Upgrading to v" + MIN_NODE_MAJOR + " via nvm...");
|
|
42
|
+
|
|
43
|
+
var nvmDir = (process.env.NVM_DIR) ||
|
|
44
|
+
(process.env.HOME ? path.join(process.env.HOME, ".nvm") : "");
|
|
45
|
+
var nvmScript = nvmDir ? path.join(nvmDir, "nvm.sh") : "";
|
|
46
|
+
|
|
47
|
+
var installCmd;
|
|
48
|
+
if (nvmScript && fs.existsSync(nvmScript)) {
|
|
49
|
+
installCmd = [
|
|
50
|
+
"source " + nvmScript,
|
|
51
|
+
"nvm install " + MIN_NODE_MAJOR,
|
|
52
|
+
"nvm alias default " + MIN_NODE_MAJOR,
|
|
53
|
+
"nvm use " + MIN_NODE_MAJOR,
|
|
54
|
+
].join(" && ");
|
|
55
|
+
} else {
|
|
56
|
+
installCmd = [
|
|
57
|
+
"curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash",
|
|
58
|
+
"export NVM_DIR=\"$HOME/.nvm\"",
|
|
59
|
+
"source \"$NVM_DIR/nvm.sh\"",
|
|
60
|
+
"nvm install " + MIN_NODE_MAJOR,
|
|
61
|
+
"nvm alias default " + MIN_NODE_MAJOR,
|
|
62
|
+
"nvm use " + MIN_NODE_MAJOR,
|
|
63
|
+
].join(" && ");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
execFileSync("bash", ["-c", installCmd], { stdio: "inherit" });
|
|
68
|
+
console.log("[magalh] Node.js v" + MIN_NODE_MAJOR + " installed. Run: npm install -g magalh");
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error("[magalh] Upgrade failed: " + ((err && err.message) || String(err)));
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
|
|
28
76
|
if (args.includes("--install-service")) {
|
|
29
77
|
const SERVICE_NAME = "magalh";
|
|
30
78
|
const nodeBin = process.execPath;
|