arisa 2.2.8 → 2.2.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/arisa.js +73 -22
- package/package.json +1 -1
package/bin/arisa.js
CHANGED
|
@@ -580,14 +580,63 @@ function canUseSystemdSystem() {
|
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
function runArisaForeground() {
|
|
583
|
-
|
|
584
|
-
// On 1GB VPS, two bun processes trigger OOM.
|
|
585
|
-
const child = spawn("su", ["-", "arisa", "-c", `${ARISA_BUN_ENV} && export ARISA_PROJECT_DIR=${SHARED_ARISA_ROOT} && exec /home/arisa/.bun/bin/bun ${sharedDaemonEntry}`], {
|
|
583
|
+
const result = spawnSync("su", ["-", "arisa", "-c", `${ARISA_BUN_ENV} && export ARISA_PROJECT_DIR=${SHARED_ARISA_ROOT} && exec /home/arisa/.bun/bin/bun ${sharedDaemonEntry}`], {
|
|
586
584
|
stdio: "inherit",
|
|
587
|
-
detached: true,
|
|
588
585
|
});
|
|
589
|
-
|
|
590
|
-
|
|
586
|
+
return result.status ?? 1;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// ── Minimal setup (runs as root, no second bun process) ─────────────
|
|
590
|
+
|
|
591
|
+
function askLine(promptText) {
|
|
592
|
+
process.stdout.write(promptText);
|
|
593
|
+
const result = spawnSync("bash", ["-c", "read -r line; echo \"$line\""], {
|
|
594
|
+
stdio: ["inherit", "pipe", "inherit"],
|
|
595
|
+
});
|
|
596
|
+
return (result.stdout || "").toString().trim();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function runMinimalSetup() {
|
|
600
|
+
const arisaDataDir = "/home/arisa/.arisa";
|
|
601
|
+
const envPath = join(arisaDataDir, ".env");
|
|
602
|
+
|
|
603
|
+
// Load existing .env if any
|
|
604
|
+
const vars = {};
|
|
605
|
+
if (existsSync(envPath)) {
|
|
606
|
+
for (const line of readFileSync(envPath, "utf8").split("\n")) {
|
|
607
|
+
const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.+)$/);
|
|
608
|
+
if (match) vars[match[1]] = match[2].trim();
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (!vars.TELEGRAM_BOT_TOKEN) {
|
|
613
|
+
process.stdout.write("\nArisa Setup\n\n");
|
|
614
|
+
const token = askLine("Telegram Bot Token (from https://t.me/BotFather): ");
|
|
615
|
+
if (!token) {
|
|
616
|
+
process.stdout.write("No token provided. Cannot start without Telegram Bot Token.\n");
|
|
617
|
+
process.exit(1);
|
|
618
|
+
}
|
|
619
|
+
vars.TELEGRAM_BOT_TOKEN = token;
|
|
620
|
+
process.stdout.write(" Token saved.\n");
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (!vars.OPENAI_API_KEY) {
|
|
624
|
+
const key = askLine("OpenAI API Key (optional, enter to skip): ");
|
|
625
|
+
if (key) {
|
|
626
|
+
vars.OPENAI_API_KEY = key;
|
|
627
|
+
process.stdout.write(" Key saved.\n");
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
vars.ARISA_SETUP_COMPLETE = "1";
|
|
632
|
+
|
|
633
|
+
// Write .env
|
|
634
|
+
mkdirSync(arisaDataDir, { recursive: true });
|
|
635
|
+
const content = Object.entries(vars).map(([k, v]) => `${k}=${v}`).join("\n") + "\n";
|
|
636
|
+
writeFileSync(envPath, content, "utf8");
|
|
637
|
+
spawnSync("chown", ["-R", "arisa:arisa", arisaDataDir], { stdio: "ignore" });
|
|
638
|
+
|
|
639
|
+
process.stdout.write(`\nConfig saved to ${envPath}\n`);
|
|
591
640
|
}
|
|
592
641
|
|
|
593
642
|
// ── Root guard ──────────────────────────────────────────────────────
|
|
@@ -601,12 +650,14 @@ if (isRoot()) {
|
|
|
601
650
|
spawnSync("systemctl", ["enable", "arisa"], { stdio: "inherit" });
|
|
602
651
|
step(true, "Systemd service enabled (auto-starts on reboot)");
|
|
603
652
|
}
|
|
653
|
+
}
|
|
604
654
|
|
|
605
|
-
|
|
606
|
-
|
|
655
|
+
// Minimal setup: collect tokens here (no second bun process)
|
|
656
|
+
if (!isArisaConfigured()) {
|
|
657
|
+
runMinimalSetup();
|
|
607
658
|
}
|
|
608
659
|
|
|
609
|
-
// Already provisioned — route commands
|
|
660
|
+
// Already provisioned + configured — route commands
|
|
610
661
|
if (command === "help" || command === "--help" || command === "-h") {
|
|
611
662
|
printHelp();
|
|
612
663
|
process.exit(0);
|
|
@@ -618,27 +669,27 @@ if (isRoot()) {
|
|
|
618
669
|
|
|
619
670
|
const hasSystemd = canUseSystemdSystem();
|
|
620
671
|
|
|
621
|
-
// No args → setup if needed, then systemd or foreground
|
|
622
672
|
if (isDefaultInvocation) {
|
|
623
|
-
if (!isArisaConfigured()) {
|
|
624
|
-
process.stdout.write("Arisa is not configured yet. Starting interactive setup...\n\n");
|
|
625
|
-
runArisaForeground(); // exits parent process internally
|
|
626
|
-
}
|
|
627
673
|
if (hasSystemd) {
|
|
628
|
-
if (isSystemdActive()) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
process.exit(startSystemdSystem());
|
|
674
|
+
if (!isSystemdActive()) {
|
|
675
|
+
const start = startSystemdSystem();
|
|
676
|
+
if (start !== 0) process.exit(start);
|
|
632
677
|
}
|
|
678
|
+
process.stdout.write("\nArisa is running. Management commands:\n");
|
|
679
|
+
process.stdout.write(" Status: systemctl status arisa\n");
|
|
680
|
+
process.stdout.write(" Logs: journalctl -u arisa -f\n");
|
|
681
|
+
process.stdout.write(" Restart: systemctl restart arisa\n");
|
|
682
|
+
process.stdout.write(" Stop: systemctl stop arisa\n\n");
|
|
683
|
+
process.exit(0);
|
|
633
684
|
}
|
|
634
|
-
// No systemd → foreground
|
|
635
|
-
runArisaForeground();
|
|
685
|
+
// No systemd → foreground (two bun processes, but no other option)
|
|
686
|
+
process.exit(runArisaForeground());
|
|
636
687
|
}
|
|
637
688
|
|
|
638
689
|
switch (command) {
|
|
639
690
|
case "start":
|
|
640
691
|
if (hasSystemd) process.exit(startSystemdSystem());
|
|
641
|
-
runArisaForeground();
|
|
692
|
+
process.exit(runArisaForeground());
|
|
642
693
|
break;
|
|
643
694
|
case "stop":
|
|
644
695
|
if (hasSystemd) process.exit(stopSystemdSystem());
|
|
@@ -657,7 +708,7 @@ if (isRoot()) {
|
|
|
657
708
|
break;
|
|
658
709
|
case "daemon":
|
|
659
710
|
case "run":
|
|
660
|
-
runArisaForeground();
|
|
711
|
+
process.exit(runArisaForeground());
|
|
661
712
|
default:
|
|
662
713
|
process.stderr.write(`Unknown command: ${command}\n\n`);
|
|
663
714
|
printHelp();
|