Files
hy2-panel/lib/install-script.ts
T

22 lines
742 B
TypeScript

import { readFileSync } from "node:fs";
import path from "node:path";
import { decryptText } from "@/lib/crypto";
import type { Installation } from "@/lib/provisioning";
const quote = (value: string) => "'" + value.replaceAll("'", "'\\''") + "'";
export function buildInstallScript(job: Installation) {
const token = decryptText(job.token_encrypted);
if (!token) throw new Error("installation_token_unavailable");
const values: Record<string, string> = {
PANEL: job.origin,
TOKEN: token,
INSTALL_ID: job.id,
SLUG: job.slug,
};
return readFileSync(
path.join(process.cwd(), "lib/templates/install-node.sh"),
"utf8",
).replace(/__(PANEL|TOKEN|INSTALL_ID|SLUG)__/g, (_, key) =>
quote(values[key]),
);
}