package cli import ( "errors" "fmt" "os" "runtime" "github.com/mattn/go-isatty" "github.com/spf13/cobra" ) // A bare `llmgw` in a terminal: the setup screens on a machine with nothing // installed, the console on a control plane. Anywhere else — a pipe, a // script, another operating system — it prints its help, as it always did. func interactive(cmd *cobra.Command) bool { return isTerminal(cmd.OutOrStdout()) && isatty.IsTerminal(os.Stdin.Fd()) } func runHome(cmd *cobra.Command) error { out := cmd.OutOrStdout() if runtime.GOOS != "linux" { fmt.Fprintln(out, "The setup and console screens run on the Linux machine they manage.") fmt.Fprintln(out) return cmd.Help() } if os.Geteuid() != 0 { return errors.New("run it as root — sudo llmgw — since it installs software and holds the certificate authority") } switch { // Installed is the service in place, not only its configuration: a setup // that stopped halfway has written server.yaml and nothing that runs, and // the setup screens are what finish it. case exists("/etc/llmgw/server.yaml") && exists("/etc/systemd/system/llmgw-server.service"): return runConsole(cmd.Context(), out, "/etc/llmgw/server.yaml") case exists("/etc/llmgw/agent.yaml"): // A node: its own settings. The cluster is watched from the // control plane. return runConsole(cmd.Context(), out, "/etc/llmgw/agent.yaml") } return runSetupTUI(cmd.Context(), out) } func exists(p string) bool { _, err := os.Stat(p) return err == nil }