@patiom/daemon 0.0.2 → 0.0.4
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/dist/index.js +14 -86
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import { consola } from "consola";
|
|
2
3
|
import { program } from "commander";
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
@@ -13,9 +14,8 @@ import "adm-zip";
|
|
|
13
14
|
import getPort, { portNumbers } from "get-port";
|
|
14
15
|
import { parse, stringify } from "smol-toml";
|
|
15
16
|
import dotenv from "dotenv";
|
|
16
|
-
import { confirm, input } from "@inquirer/prompts";
|
|
17
17
|
//#region package.json
|
|
18
|
-
var version = "0.0.
|
|
18
|
+
var version = "0.0.4";
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/config.ts
|
|
21
21
|
const PATIOM_ROOT = "/var/lib/patiom";
|
|
@@ -406,7 +406,7 @@ After=network.target
|
|
|
406
406
|
|
|
407
407
|
[Service]
|
|
408
408
|
Type=exec
|
|
409
|
-
ExecStart
|
|
409
|
+
ExecStart=/usr/local/bin/patiom-server serve
|
|
410
410
|
Restart=always
|
|
411
411
|
Environment=PORT=${port}
|
|
412
412
|
Environment=PATH=${nodeBinPath}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
@@ -896,81 +896,6 @@ const detectIP = async () => {
|
|
|
896
896
|
return "unknown";
|
|
897
897
|
}
|
|
898
898
|
};
|
|
899
|
-
const configureFirewall = async (os, port) => {
|
|
900
|
-
if (!await confirm({
|
|
901
|
-
message: "Configure firewall?",
|
|
902
|
-
default: true
|
|
903
|
-
})) {
|
|
904
|
-
consola.info("Skipping firewall configuration");
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
if (os === "ubuntu" || os === "debian") {
|
|
908
|
-
consola.start("Configuring UFW...");
|
|
909
|
-
await execa("ufw", [
|
|
910
|
-
"default",
|
|
911
|
-
"deny",
|
|
912
|
-
"incoming"
|
|
913
|
-
]);
|
|
914
|
-
await execa("ufw", [
|
|
915
|
-
"default",
|
|
916
|
-
"allow",
|
|
917
|
-
"outgoing"
|
|
918
|
-
]);
|
|
919
|
-
await execa("ufw", ["allow", "22/tcp"]);
|
|
920
|
-
await execa("ufw", ["allow", "80/tcp"]);
|
|
921
|
-
await execa("ufw", ["allow", "443/tcp"]);
|
|
922
|
-
await execa("ufw", ["allow", `${port}/tcp`]);
|
|
923
|
-
await execa("ufw", ["--force", "enable"]);
|
|
924
|
-
consola.success("UFW configured");
|
|
925
|
-
} else if ([
|
|
926
|
-
"almalinux",
|
|
927
|
-
"rocky",
|
|
928
|
-
"centos",
|
|
929
|
-
"fedora",
|
|
930
|
-
"rhel"
|
|
931
|
-
].includes(os)) {
|
|
932
|
-
consola.start("Configuring Firewalld...");
|
|
933
|
-
await execa("systemctl", [
|
|
934
|
-
"enable",
|
|
935
|
-
"--now",
|
|
936
|
-
"firewalld"
|
|
937
|
-
]);
|
|
938
|
-
await execa("firewall-cmd", [
|
|
939
|
-
"--permanent",
|
|
940
|
-
"--zone=public",
|
|
941
|
-
"--add-port=22/tcp"
|
|
942
|
-
]);
|
|
943
|
-
await execa("firewall-cmd", [
|
|
944
|
-
"--permanent",
|
|
945
|
-
"--zone=public",
|
|
946
|
-
"--add-port=80/tcp"
|
|
947
|
-
]);
|
|
948
|
-
await execa("firewall-cmd", [
|
|
949
|
-
"--permanent",
|
|
950
|
-
"--zone=public",
|
|
951
|
-
"--add-port=443/tcp"
|
|
952
|
-
]);
|
|
953
|
-
await execa("firewall-cmd", [
|
|
954
|
-
"--permanent",
|
|
955
|
-
"--zone=public",
|
|
956
|
-
"--add-port",
|
|
957
|
-
`${port}/tcp`
|
|
958
|
-
]);
|
|
959
|
-
await execa("firewall-cmd", ["--reload"]);
|
|
960
|
-
await execa("setsebool", [
|
|
961
|
-
"-P",
|
|
962
|
-
"httpd_can_network_connect",
|
|
963
|
-
"1"
|
|
964
|
-
]);
|
|
965
|
-
consola.success("Firewalld configured");
|
|
966
|
-
} else consola.warn(`Unsupported OS for firewall: ${os}`);
|
|
967
|
-
};
|
|
968
|
-
const configureACME = async () => {
|
|
969
|
-
return { email: await input({
|
|
970
|
-
message: "Email for Let's Encrypt certificates:",
|
|
971
|
-
validate: (v) => v.includes("@") ? true : "Please enter a valid email"
|
|
972
|
-
}) };
|
|
973
|
-
};
|
|
974
899
|
const setupPatiomDirs = async () => {
|
|
975
900
|
await fs.mkdir(PATIOM_ROOT, { recursive: true });
|
|
976
901
|
await fs.mkdir(path.join(PATIOM_ROOT, "apps"), { recursive: true });
|
|
@@ -1009,7 +934,7 @@ const installServices = async (nodeBinPath) => {
|
|
|
1009
934
|
await start("patiom-daemon");
|
|
1010
935
|
consola.success("Patiom daemon started");
|
|
1011
936
|
};
|
|
1012
|
-
const setup = async () => {
|
|
937
|
+
const setup = async (email) => {
|
|
1013
938
|
console.log("");
|
|
1014
939
|
consola.info("Patiom Server Setup");
|
|
1015
940
|
console.log("");
|
|
@@ -1019,9 +944,6 @@ const setup = async () => {
|
|
|
1019
944
|
consola.error("Unsupported OS. Please use Ubuntu, Debian, AlmaLinux, Rocky, CentOS, Fedora, or RHEL.");
|
|
1020
945
|
process.exit(1);
|
|
1021
946
|
}
|
|
1022
|
-
await configureFirewall(os, DAEMON_PORT);
|
|
1023
|
-
console.log("");
|
|
1024
|
-
const { email } = await configureACME();
|
|
1025
947
|
console.log("");
|
|
1026
948
|
consola.start("Setting up Patiom...");
|
|
1027
949
|
await setupPatiomDirs();
|
|
@@ -1041,10 +963,12 @@ const setup = async () => {
|
|
|
1041
963
|
consola.info("Next steps:");
|
|
1042
964
|
console.log(` patiom login --url http://${ip}:${DAEMON_PORT} --token ${token}`);
|
|
1043
965
|
console.log("");
|
|
966
|
+
consola.info("Firewall: ensure ports 22 (SSH), 80 (HTTP), 443 (HTTPS), and 4000 (daemon) are open");
|
|
967
|
+
console.log("");
|
|
1044
968
|
};
|
|
1045
|
-
const runSetup = async () => {
|
|
969
|
+
const runSetup = async (email) => {
|
|
1046
970
|
try {
|
|
1047
|
-
await setup();
|
|
971
|
+
await setup(email);
|
|
1048
972
|
} catch (err) {
|
|
1049
973
|
consola.error("Setup failed:", err);
|
|
1050
974
|
process.exit(1);
|
|
@@ -1066,9 +990,13 @@ program.command("serve").description("Start the daemon HTTP server").option(skip
|
|
|
1066
990
|
checkRoot(options.devSkipRootCheck);
|
|
1067
991
|
startServer();
|
|
1068
992
|
});
|
|
1069
|
-
program.command("setup").description("
|
|
993
|
+
program.command("setup").description("First-time server setup").requiredOption("--email <email>", "Email for Let's Encrypt certificates").option(skipRootOpt, "Skip root check for development").action((options) => {
|
|
1070
994
|
checkRoot(options.devSkipRootCheck);
|
|
1071
|
-
|
|
995
|
+
if (!/^\S+@\S+\.\S+$/u.test(options.email)) {
|
|
996
|
+
consola.error("Invalid email format. Provide a valid email for Let's Encrypt certificates.");
|
|
997
|
+
process.exit(1);
|
|
998
|
+
}
|
|
999
|
+
return runSetup(options.email);
|
|
1072
1000
|
});
|
|
1073
1001
|
program.command("upgrade").description("Update the daemon package and restart the service").option(skipRootOpt, "Skip root check for development").action(async (options) => {
|
|
1074
1002
|
checkRoot(options.devSkipRootCheck);
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patiom/daemon",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"patiom-server": "
|
|
6
|
+
"patiom-server": "dist/index.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@hono/node-server": "^2.0.4",
|
|
13
|
-
"@inquirer/prompts": "^7.8.2",
|
|
14
13
|
"adm-zip": "^0.5.17",
|
|
15
14
|
"commander": "^15.0.0",
|
|
16
15
|
"consola": "^3.4.2",
|