X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fmain.go;h=ab0bfae917286283e59bcb16af1c2ffabe15432a;hb=5d6cc7f14a4bacc36bf3a23cd735a75ad4a90f1d;hp=9c58d3af8175c337aa60a2b47bc1383105cc0226;hpb=ddd21f01f764a4ff61204d8e9d0ef8421ebf685c;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index 9c58d3a..ab0bfae 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -1,4 +1,4 @@ -// Helper copied to the remote hosts to run commands and deploy configuration +// Helper copied to the remote host to run commands and deploy configuration // Copyright (C) 2021 Simon Ruderich // @@ -22,6 +22,8 @@ import ( "log" "os" + "golang.org/x/term" + "ruderich.org/simon/safcm" "ruderich.org/simon/safcm/cmd/safcm-remote/ainsl" "ruderich.org/simon/safcm/cmd/safcm-remote/info" @@ -29,19 +31,31 @@ import ( "ruderich.org/simon/safcm/cmd/safcm-remote/sync" ) +func usage() { + log.Fatalf("usage: %[1]s sync\n"+ + "usage: %[1]s ainsl [options] ", + os.Args[0]) +} + func main() { // Timestamps are added by `safcm` log.SetFlags(0) + if len(os.Args) < 2 { + usage() + } + var err error - if len(os.Args) == 1 { + switch os.Args[1] { + case "sync": + if len(os.Args) != 2 { + usage() + } err = mainLoop() - } else if len(os.Args) >= 2 && os.Args[1] == "ainsl" { + case "ainsl": err = ainsl.Main(os.Args) - } else { - log.Fatalf("usage: %[1]s\n"+ - "usage: %[1]s ainsl [options] ", - os.Args[0]) + default: + usage() } if err != nil { @@ -50,6 +64,12 @@ func main() { } func mainLoop() error { + if term.IsTerminal(int(os.Stdin.Fd())) || + term.IsTerminal(int(os.Stdout.Fd())) { + return fmt.Errorf("sync should only be called from `safcm` " + + "(redirect stdin/stdout to circumvent this check)") + } + conn := safcm.NewGobConn(os.Stdin, os.Stdout) var logLevel safcm.LogLevel