30 lines
927 B
TypeScript
30 lines
927 B
TypeScript
import { SING_BOX_VERSION } from "@/lib/anytls";
|
|
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,
|
|
SING_BOX_VERSION,
|
|
};
|
|
return readFileSync(
|
|
path.join(
|
|
process.cwd(),
|
|
"lib", "templates",
|
|
job.protocol === "anytls"
|
|
? "install-anytls.sh"
|
|
: "install-node.sh",
|
|
),
|
|
"utf8",
|
|
).replace(/__(PANEL|TOKEN|INSTALL_ID|SLUG|SING_BOX_VERSION)__/g, (_, key) =>
|
|
quote(values[key]),
|
|
);
|
|
}
|