arisa 2.2.9 → 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 +68 -13
- package/package.json +1 -1
package/bin/arisa.js
CHANGED
|
@@ -586,6 +586,59 @@ function runArisaForeground() {
|
|
|
586
586
|
return result.status ?? 1;
|
|
587
587
|
}
|
|
588
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`);
|
|
640
|
+
}
|
|
641
|
+
|
|
589
642
|
// ── Root guard ──────────────────────────────────────────────────────
|
|
590
643
|
|
|
591
644
|
if (isRoot()) {
|
|
@@ -597,12 +650,14 @@ if (isRoot()) {
|
|
|
597
650
|
spawnSync("systemctl", ["enable", "arisa"], { stdio: "inherit" });
|
|
598
651
|
step(true, "Systemd service enabled (auto-starts on reboot)");
|
|
599
652
|
}
|
|
653
|
+
}
|
|
600
654
|
|
|
601
|
-
|
|
602
|
-
|
|
655
|
+
// Minimal setup: collect tokens here (no second bun process)
|
|
656
|
+
if (!isArisaConfigured()) {
|
|
657
|
+
runMinimalSetup();
|
|
603
658
|
}
|
|
604
659
|
|
|
605
|
-
// Already provisioned — route commands
|
|
660
|
+
// Already provisioned + configured — route commands
|
|
606
661
|
if (command === "help" || command === "--help" || command === "-h") {
|
|
607
662
|
printHelp();
|
|
608
663
|
process.exit(0);
|
|
@@ -614,20 +669,20 @@ if (isRoot()) {
|
|
|
614
669
|
|
|
615
670
|
const hasSystemd = canUseSystemdSystem();
|
|
616
671
|
|
|
617
|
-
// No args → setup if needed, then systemd or foreground
|
|
618
672
|
if (isDefaultInvocation) {
|
|
619
|
-
if (!isArisaConfigured()) {
|
|
620
|
-
process.stdout.write("Arisa is not configured yet. Starting interactive setup...\n\n");
|
|
621
|
-
process.exit(runArisaForeground());
|
|
622
|
-
}
|
|
623
673
|
if (hasSystemd) {
|
|
624
|
-
if (isSystemdActive()) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
process.exit(startSystemdSystem());
|
|
674
|
+
if (!isSystemdActive()) {
|
|
675
|
+
const start = startSystemdSystem();
|
|
676
|
+
if (start !== 0) process.exit(start);
|
|
628
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);
|
|
629
684
|
}
|
|
630
|
-
// No systemd → foreground
|
|
685
|
+
// No systemd → foreground (two bun processes, but no other option)
|
|
631
686
|
process.exit(runArisaForeground());
|
|
632
687
|
}
|
|
633
688
|
|