import { Terminal } from "lucide-react"; import { useTranslations } from "next-intl"; import { useState } from "react"; import { FaDocker, FaWindows } from "react-icons/fa"; import CopyTextBox from "./CopyTextBox"; import { SettingsSection, SettingsSectionBody, SettingsSectionDescription, SettingsSectionHeader, SettingsSectionTitle } from "./Settings"; import { Button } from "./ui/button"; export type CommandItem = string | { title: string; command: string }; const PLATFORMS = ["unix", "windows", "docker"] as const; type Platform = (typeof PLATFORMS)[number]; export type OlmInstallCommandsProps = { id: string; secret: string; endpoint: string; version?: string; }; export function OlmInstallCommands({ id, secret, endpoint, version = "latest" }: OlmInstallCommandsProps) { const t = useTranslations(); const [platform, setPlatform] = useState("unix"); const [architecture, setArchitecture] = useState( () => getArchitectures(platform)[0] ); const commandList: Record> = { unix: { All: [ { title: t("install"), command: `curl -fsSL https://static.pangolin.net/get-olm.sh | bash` }, { title: t("run"), command: `sudo olm --id ${id} --secret ${secret} --endpoint ${endpoint}` } ] }, windows: { x64: [ { title: t("install"), command: `curl -o olm.exe -L "https://github.com/fosrl/olm/releases/download/${version}/olm_windows_installer.exe"` }, { title: t("run"), command: `olm.exe --id ${id} --secret ${secret} --endpoint ${endpoint}` } ] }, docker: { "Docker Compose": [ `services: olm: image: fosrl/olm container_name: olm restart: unless-stopped network_mode: host cap_add: - NET_ADMIN devices: - /dev/net/tun:/dev/net/tun environment: - PANGOLIN_ENDPOINT=${endpoint} - OLM_ID=${id} - OLM_SECRET=${secret}` ], "Docker Run": [ `docker run -dit --network host --cap-add NET_ADMIN --device /dev/net/tun:/dev/net/tun fosrl/olm --id ${id} --secret ${secret} --endpoint ${endpoint}` ] } }; const commands = commandList[platform][architecture]; return ( {t("clientInstallOlm")} {t("clientInstallOlmDescription")}

{t("operatingSystem")}

{PLATFORMS.map((os) => ( ))}

{["docker", "podman"].includes(platform) ? t("method") : t("architecture")}

{getArchitectures(platform).map((arch) => ( ))}

{t("commands")}

{commands.map((item, index) => { const commandText = typeof item === "string" ? item : item.command; const title = typeof item === "string" ? undefined : item.title; return (
{title && (

{title}

)}
); })}
); } function getArchitectures(platform: Platform) { switch (platform) { case "unix": return ["All"]; case "windows": return ["x64"]; case "docker": return ["Docker Compose", "Docker Run"]; default: return ["x64"]; } } function getPlatformName(platformName: Platform) { switch (platformName) { case "windows": return "Windows"; case "unix": return "Unix & macOS"; case "docker": return "Docker"; default: return "Unix & macOS"; } } function getPlatformIcon(platformName: Platform) { switch (platformName) { case "windows": return ; case "unix": return ; case "docker": return ; default: return ; } }