Подготовить HY2XS к production-сборке

This commit is contained in:
2026-04-25 23:13:12 +05:00
commit 84a4e94567
277 changed files with 26513 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import type { InstallContext } from "../types/context";
import { exists, readText } from "../lib/fs";
import { fail } from "../lib/log";
import { run } from "../lib/process";
async function isPortBusy(port: number): Promise<boolean> {
try {
const output = await run`ss -H -lntu`;
return output.split("\n").some((line) => line.includes(`:${port} `) || line.endsWith(`:${port}`));
} catch {
return false;
}
}
export async function preflight(context: InstallContext): Promise<void> {
if (process.getuid?.() !== 0) {
fail("installer must run as root");
}
const osRelease = await readText("/etc/os-release");
if (!/^ID=debian$/m.test(osRelease) || !/^VERSION_ID="?12"?$/m.test(osRelease)) {
fail("HY2XS baseline supports only clean Debian 12");
}
if (!(await exists(`${context.options.packageDir}/ui/hy2xs-admin`))) {
fail("bundled HY2XS admin is missing from install package");
}
if (await exists("/etc/hysteria/post-install.env")) {
fail("existing HY2XS post-install.env found; update/repair is out of scope");
}
if (await exists("/opt/hy2xs-admin")) {
fail("existing /opt/hy2xs-admin found; conflicting old state");
}
const ports = new Set([context.options.port, context.options.uiPort]);
if (ports.size !== 2) {
fail("Hysteria port and UI port must be different");
}
if (context.options.domain && !/^[a-zA-Z0-9.-]+$/.test(context.options.domain)) {
fail("domain contains unsupported characters");
}
if (await isPortBusy(context.options.port)) {
fail(`Hysteria UDP/TCP port already appears to be in use: ${context.options.port}`);
}
if (await isPortBusy(context.options.uiPort)) {
fail(`HY2XS admin port already appears to be in use: ${context.options.uiPort}`);
}
}