X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fmain.go;h=ab0bfae917286283e59bcb16af1c2ffabe15432a;hb=5d6cc7f14a4bacc36bf3a23cd735a75ad4a90f1d;hp=46a651aed947f96a3e136639da8f79b8ff366719;hpb=fcf8c31d7ce8cc47db014178d6bda936168c4a12;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index 46a651a..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,27 +22,54 @@ 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" "ruderich.org/simon/safcm/cmd/safcm-remote/run" "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) != 1 { - log.Fatalf("usage: %s", os.Args[0]) + if len(os.Args) < 2 { + usage() + } + + var err error + switch os.Args[1] { + case "sync": + if len(os.Args) != 2 { + usage() + } + err = mainLoop() + case "ainsl": + err = ainsl.Main(os.Args) + default: + usage() } - err := mainLoop() if err != nil { log.Fatalf("%s: %v", os.Args[0], err) } } 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