arisa 2.1.7 → 2.1.9
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/arisa.js +62 -49
- package/package.json +1 -1
package/bin/arisa.js
CHANGED
|
@@ -437,8 +437,10 @@ function step(ok, msg) {
|
|
|
437
437
|
process.stdout.write(` ${ok ? "\u2713" : "\u2717"} ${msg}\n`);
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
const ARISA_BUN_ENV = 'export BUN_INSTALL=/home/arisa/.bun && export PATH=/home/arisa/.bun/bin:$PATH';
|
|
441
|
+
|
|
440
442
|
function runAsInherit(cmd) {
|
|
441
|
-
return spawnSync("su", ["-", "arisa", "-c", cmd], {
|
|
443
|
+
return spawnSync("su", ["-", "arisa", "-c", `${ARISA_BUN_ENV} && ${cmd}`], {
|
|
442
444
|
stdio: "inherit",
|
|
443
445
|
timeout: 180_000,
|
|
444
446
|
});
|
|
@@ -472,6 +474,15 @@ function provisionArisaUser() {
|
|
|
472
474
|
}
|
|
473
475
|
step(true, "Bun installed for arisa");
|
|
474
476
|
|
|
477
|
+
// Ensure .profile has bun PATH (login shells skip .bashrc non-interactive guard)
|
|
478
|
+
const profilePath = "/home/arisa/.profile";
|
|
479
|
+
const profileContent = existsSync(profilePath) ? readFileSync(profilePath, "utf8") : "";
|
|
480
|
+
if (!profileContent.includes("BUN_INSTALL")) {
|
|
481
|
+
const bunPath = '\n# bun\nexport BUN_INSTALL="/home/arisa/.bun"\nexport PATH="$BUN_INSTALL/bin:$PATH"\n';
|
|
482
|
+
writeFileSync(profilePath, profileContent + bunPath, "utf8");
|
|
483
|
+
spawnSync("chown", ["arisa:arisa", profilePath], { stdio: "ignore" });
|
|
484
|
+
}
|
|
485
|
+
|
|
475
486
|
// 3. Copy arisa source
|
|
476
487
|
const dest = "/home/arisa/arisa";
|
|
477
488
|
spawnSync("cp", ["-r", pkgRoot, dest], { stdio: "pipe" });
|
|
@@ -564,33 +575,38 @@ function isSystemdActive() {
|
|
|
564
575
|
return result.status === 0;
|
|
565
576
|
}
|
|
566
577
|
|
|
578
|
+
function canUseSystemdSystem() {
|
|
579
|
+
if (platform() !== "linux") return false;
|
|
580
|
+
if (!commandExists("systemctl")) return false;
|
|
581
|
+
const probe = runCommand("systemctl", ["is-system-running"], { stdio: "pipe" });
|
|
582
|
+
const state = (probe.stdout || "").trim();
|
|
583
|
+
return probe.status === 0 || state === "degraded" || state === "running";
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function runArisaForeground() {
|
|
587
|
+
const su = spawnSync("su", ["-", "arisa", "-c", `${ARISA_BUN_ENV} && /home/arisa/.bun/bin/bun /home/arisa/arisa/src/daemon/index.ts`], {
|
|
588
|
+
stdio: "inherit",
|
|
589
|
+
});
|
|
590
|
+
return su.status ?? 1;
|
|
591
|
+
}
|
|
592
|
+
|
|
567
593
|
// ── Root guard ──────────────────────────────────────────────────────
|
|
568
594
|
|
|
569
595
|
if (isRoot()) {
|
|
570
596
|
if (!isProvisioned()) {
|
|
571
597
|
provisionArisaUser();
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
598
|
+
if (canUseSystemdSystem()) {
|
|
599
|
+
writeSystemdSystemUnit();
|
|
600
|
+
spawnSync("systemctl", ["daemon-reload"], { stdio: "inherit" });
|
|
601
|
+
spawnSync("systemctl", ["enable", "arisa"], { stdio: "inherit" });
|
|
602
|
+
step(true, "Systemd service enabled (auto-starts on reboot)");
|
|
603
|
+
}
|
|
576
604
|
|
|
577
605
|
process.stdout.write("\nStarting interactive setup as user arisa...\n\n");
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
process.stdout.write(`
|
|
583
|
-
Arisa management:
|
|
584
|
-
Start: systemctl start arisa
|
|
585
|
-
Status: systemctl status arisa
|
|
586
|
-
Logs: journalctl -u arisa -f
|
|
587
|
-
Restart: systemctl restart arisa
|
|
588
|
-
Stop: systemctl stop arisa
|
|
589
|
-
`);
|
|
590
|
-
process.exit(su.status ?? 0);
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// Already provisioned — route commands to system-level systemd
|
|
606
|
+
process.exit(runArisaForeground());
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Already provisioned — route commands
|
|
594
610
|
if (command === "help" || command === "--help" || command === "-h") {
|
|
595
611
|
printHelp();
|
|
596
612
|
process.exit(0);
|
|
@@ -600,51 +616,48 @@ Arisa management:
|
|
|
600
616
|
process.exit(0);
|
|
601
617
|
}
|
|
602
618
|
|
|
603
|
-
|
|
619
|
+
const hasSystemd = canUseSystemdSystem();
|
|
620
|
+
|
|
621
|
+
// No args → setup if needed, then systemd or foreground
|
|
604
622
|
if (isDefaultInvocation) {
|
|
605
623
|
if (!isArisaConfigured()) {
|
|
606
624
|
process.stdout.write("Arisa is not configured yet. Starting interactive setup...\n\n");
|
|
607
|
-
|
|
608
|
-
stdio: "inherit",
|
|
609
|
-
});
|
|
610
|
-
process.stdout.write(`
|
|
611
|
-
Arisa management:
|
|
612
|
-
Start: systemctl start arisa
|
|
613
|
-
Status: systemctl status arisa
|
|
614
|
-
Logs: journalctl -u arisa -f
|
|
615
|
-
Restart: systemctl restart arisa
|
|
616
|
-
Stop: systemctl stop arisa
|
|
617
|
-
`);
|
|
618
|
-
process.exit(su.status ?? 0);
|
|
625
|
+
process.exit(runArisaForeground());
|
|
619
626
|
}
|
|
620
|
-
if (
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
627
|
+
if (hasSystemd) {
|
|
628
|
+
if (isSystemdActive()) {
|
|
629
|
+
process.exit(statusSystemdSystem());
|
|
630
|
+
} else {
|
|
631
|
+
process.exit(startSystemdSystem());
|
|
632
|
+
}
|
|
624
633
|
}
|
|
634
|
+
// No systemd → foreground
|
|
635
|
+
process.exit(runArisaForeground());
|
|
625
636
|
}
|
|
626
637
|
|
|
627
638
|
switch (command) {
|
|
628
639
|
case "start":
|
|
629
|
-
process.exit(startSystemdSystem());
|
|
640
|
+
if (hasSystemd) process.exit(startSystemdSystem());
|
|
641
|
+
process.exit(runArisaForeground());
|
|
630
642
|
break;
|
|
631
643
|
case "stop":
|
|
632
|
-
process.exit(stopSystemdSystem());
|
|
644
|
+
if (hasSystemd) process.exit(stopSystemdSystem());
|
|
645
|
+
process.stderr.write("No systemd available. Stop the foreground process with Ctrl+C.\n");
|
|
646
|
+
process.exit(1);
|
|
633
647
|
break;
|
|
634
648
|
case "restart":
|
|
635
|
-
process.exit(restartSystemdSystem());
|
|
649
|
+
if (hasSystemd) process.exit(restartSystemdSystem());
|
|
650
|
+
process.stderr.write("No systemd available. Restart the foreground process manually.\n");
|
|
651
|
+
process.exit(1);
|
|
636
652
|
break;
|
|
637
653
|
case "status":
|
|
638
|
-
process.exit(statusSystemdSystem());
|
|
654
|
+
if (hasSystemd) process.exit(statusSystemdSystem());
|
|
655
|
+
process.stderr.write("No systemd available.\n");
|
|
656
|
+
process.exit(1);
|
|
639
657
|
break;
|
|
640
658
|
case "daemon":
|
|
641
|
-
case "run":
|
|
642
|
-
|
|
643
|
-
const su = spawnSync("su", ["-", "arisa", "-c", "/home/arisa/.bun/bin/bun /home/arisa/arisa/src/daemon/index.ts"], {
|
|
644
|
-
stdio: "inherit",
|
|
645
|
-
});
|
|
646
|
-
process.exit(su.status ?? 1);
|
|
647
|
-
}
|
|
659
|
+
case "run":
|
|
660
|
+
process.exit(runArisaForeground());
|
|
648
661
|
default:
|
|
649
662
|
process.stderr.write(`Unknown command: ${command}\n\n`);
|
|
650
663
|
printHelp();
|