From fe729ec762d1fb5c7d84c9dd845b23f280b02018 Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Tue, 20 Jan 2026 05:21:18 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7wip:=20command=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/commands.tsx | 174 ++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 src/components/commands.tsx diff --git a/src/components/commands.tsx b/src/components/commands.tsx new file mode 100644 index 00000000..daee185c --- /dev/null +++ b/src/components/commands.tsx @@ -0,0 +1,174 @@ +import { useTranslations } from "next-intl"; +import CopyTextBox from "./CopyTextBox"; + +import type { id } from "date-fns/locale"; + +// function getCommand(): CommandItem[] { +// const placeholder: CommandItem[] = [t("unknownCommand")]; +// if (!commands) { +// return placeholder; +// } +// let platformCommands = commands[platform as keyof Commands]; + +// if (!platformCommands) { +// // get first key +// const firstPlatform = Object.keys(commands)[0] as Platform; +// platformCommands = commands[firstPlatform as keyof Commands]; + +// setPlatform(firstPlatform); +// } + +// let architectureCommands = platformCommands[architecture]; +// if (!architectureCommands) { +// // get first key +// const firstArchitecture = Object.keys(platformCommands)[0]; +// architectureCommands = platformCommands[firstArchitecture]; + +// setArchitecture(firstArchitecture); +// } + +// return architectureCommands || placeholder; +// }; + +export type CommandItem = string | { title: string; command: string }; + +type CommandByPlatform = { + unix: Record; + windows: Record; + docker: Record; + kubernetes: Record; + podman: Record; + nixos: Record; +}; +type Platform = keyof CommandByPlatform; + +export type SiteCommandsProps = { + id: string; + secret: string; + endpoint: string; + version: string; + acceptClients: boolean; + platform: Platform; +}; + +export function SiteCommands({ + acceptClients, + id, + secret, + endpoint, + version, + platform +}: SiteCommandsProps) { + const t = useTranslations(); + + const acceptClientsFlag = !acceptClients ? " --disable-clients" : ""; + const acceptClientsEnv = !acceptClients + ? "\n - DISABLE_CLIENTS=true" + : ""; + + const commandList: Record> = { + unix: { + All: [ + { + title: t("install"), + command: `curl -fsSL https://static.pangolin.net/get-newt.sh | bash` + }, + { + title: t("run"), + command: `newt --id ${id} --secret ${secret} --endpoint ${endpoint}${acceptClientsFlag}` + } + ] + }, + windows: { + x64: [ + { + title: t("install"), + command: `curl -o newt.exe -L "https://github.com/fosrl/newt/releases/download/${version}/newt_windows_amd64.exe"` + }, + { + title: t("run"), + command: `newt.exe --id ${id} --secret ${secret} --endpoint ${endpoint}${acceptClientsFlag}` + } + ] + }, + docker: { + "Docker Compose": [ + `services: + newt: + image: fosrl/newt + container_name: newt + restart: unless-stopped + environment: + - PANGOLIN_ENDPOINT=${endpoint} + - NEWT_ID=${id} + - NEWT_SECRET=${secret}${acceptClientsEnv}` + ], + "Docker Run": [ + `docker run -dit fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}${acceptClientsFlag}` + ] + }, + kubernetes: { + "Helm Chart": [ + `helm repo add fossorial https://charts.fossorial.io`, + `helm repo update fossorial`, + `helm install newt fossorial/newt \\ + --create-namespace \\ + --set newtInstances[0].name="main-tunnel" \\ + --set-string newtInstances[0].auth.keys.endpointKey="${endpoint}" \\ + --set-string newtInstances[0].auth.keys.idKey="${id}" \\ + --set-string newtInstances[0].auth.keys.secretKey="${secret}"` + ] + }, + podman: { + "Podman Quadlet": [ + `[Unit] +Description=Newt container + +[Container] +ContainerName=newt +Image=docker.io/fosrl/newt +Environment=PANGOLIN_ENDPOINT=${endpoint} +Environment=NEWT_ID=${id} +Environment=NEWT_SECRET=${secret}${!acceptClients ? "\nEnvironment=DISABLE_CLIENTS=true" : ""} +# Secret=newt-secret,type=env,target=NEWT_SECRET + +[Service] +Restart=always + +[Install] +WantedBy=default.target` + ], + "Podman Run": [ + `podman run -dit docker.io/fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}${acceptClientsFlag}` + ] + }, + nixos: { + All: [ + `nix run 'nixpkgs#fosrl-newt' -- --id ${id} --secret ${secret} --endpoint ${endpoint}${acceptClientsFlag}` + ] + } + }; + + const commands = commandList[platform]; + + return ( +
+ {[].map((item, index) => { + const commandText = + typeof item === "string" ? item : item.command; + const title = typeof item === "string" ? undefined : item.title; + + return ( +
+ {title && ( +

+ {title} +

+ )} + +
+ ); + })} +
+ ); +}