1 // Helper copied to the remote hosts to run commands and deploy configuration
3 // Copyright (C) 2021 Simon Ruderich
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "ruderich.org/simon/safcm"
26 "ruderich.org/simon/safcm/cmd/safcm-remote/info"
27 "ruderich.org/simon/safcm/cmd/safcm-remote/run"
28 "ruderich.org/simon/safcm/cmd/safcm-remote/sync"
32 if len(os.Args) != 1 {
34 log.Fatalf("usage: %s", os.Args[0])
40 log.Fatalf("%s: %v", os.Args[0], err)
44 func mainLoop() error {
45 conn := safcm.NewGobConn(os.Stdin, os.Stdout)
47 var logLevel safcm.LogLevel
48 logFunc := func(level safcm.LogLevel, format string, a ...interface{}) {
49 if logLevel >= level {
50 conn.Send(safcm.MsgLog{
52 Text: fmt.Sprintf(format, a...),
57 var quitResp safcm.MsgQuitResp
65 switch x := x.(type) {
66 case safcm.MsgInfoReq:
67 logLevel = x.LogLevel // set log level globally
68 resp = info.Handle(x, run.ExecRunner{}, logFunc)
69 case safcm.MsgSyncReq:
70 resp = sync.Handle(x, run.ExecRunner{}, logFunc)
71 case safcm.MsgQuitReq:
74 return fmt.Errorf("unsupported message %#v", x)