magalh 1.0.9 → 1.0.11

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.
Files changed (2) hide show
  1. package/bin/mgl.js +84 -5
  2. 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
- "msh - start Magala server",
15
+ "magalh - Magala Media Server",
16
16
  "",
17
17
  "Usage:",
18
- " msh [--help]",
19
- "",
20
- "Notes:",
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;
@@ -129,6 +177,37 @@ if (args.includes("--install-service")) {
129
177
  process.exit(0);
130
178
  }
131
179
 
180
+ if (process.platform === "linux" && !process.env.MAGALH_UPGRADED) {
181
+ var _MIN = 20;
182
+ var _curMaj = parseInt(process.versions.node.split(".")[0], 10);
183
+ if (_curMaj < _MIN) {
184
+ console.log("[magalh] Node.js v" + process.versions.node + " detected (need v" + _MIN + "+). Auto-upgrading...");
185
+ var _nvmHome = process.env.NVM_DIR || path.join(process.env.HOME || "/root", ".nvm");
186
+ var _nvmSh = path.join(_nvmHome, "nvm.sh");
187
+ var _upCmd = (fs.existsSync(_nvmSh)
188
+ ? "source " + _nvmSh
189
+ : "curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash && source " + _nvmSh) +
190
+ " && nvm install " + _MIN + " && nvm alias default " + _MIN;
191
+ var _newNode = null;
192
+ try {
193
+ execFileSync("bash", ["-c", _upCmd], { stdio: "inherit" });
194
+ _newNode = execFileSync("bash", ["-c", "source " + _nvmSh + " && nvm which " + _MIN], { encoding: "utf8" }).trim();
195
+ } catch (_e) {
196
+ console.warn("[magalh] Auto-upgrade failed. Run manually: magalh --upgrade-node");
197
+ }
198
+ if (_newNode && fs.existsSync(_newNode)) {
199
+ console.log("[magalh] Restarting with Node.js v" + _MIN + "...");
200
+ var _env = Object.assign({}, process.env, { MAGALH_UPGRADED: "1" });
201
+ var _rs = spawn(_newNode, [__filename].concat(args), { cwd: rootDir, env: _env, stdio: "inherit" });
202
+ _rs.on("exit", function(c, s) { process.exit(s ? 1 : (typeof c === "number" ? c : 0)); });
203
+ _rs.on("error", function(e) { process.stderr.write(String(e) + "\n"); process.exit(1); });
204
+ return;
205
+ }
206
+ console.error("[magalh] Cannot start: requires Node.js v" + _MIN + "+. Run: magalh --upgrade-node");
207
+ process.exit(1);
208
+ }
209
+ }
210
+
132
211
  const entryFile = path.join(rootDir, "msh.js");
133
212
 
134
213
  const child = spawn(process.execPath, [entryFile, ...args], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magalh",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Magala Media Server — self-hosted streaming and media management server",
5
5
  "keywords": [
6
6
  "media-server",