package main
import (
- "fmt"
- "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"
+ "ruderich.org/simon/safcm/remote"
)
-func usage() {
- log.Fatalf("usage: %[1]s sync\n"+
- "usage: %[1]s ainsl [options] <path> <line>",
- os.Args[0])
-}
-
func main() {
- // Timestamps are added by `safcm`
- log.SetFlags(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()
- }
-
- 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
- logFunc := func(level safcm.LogLevel, msg string) {
- if logLevel >= level {
- conn.Send(safcm.MsgLog{
- Level: level,
- Text: msg,
- })
- }
- }
-
- var quitResp safcm.MsgQuitResp
- for {
- x, err := conn.Recv()
- if err != nil {
- return err
- }
-
- var resp safcm.Msg
- switch x := x.(type) {
- case safcm.MsgInfoReq:
- logLevel = x.LogLevel // set log level globally
- resp = info.Handle(x, run.ExecRunner{}, logFunc)
- case safcm.MsgSyncReq:
- resp = sync.Handle(x, run.ExecRunner{}, logFunc)
- case safcm.MsgQuitReq:
- resp = quitResp
- default:
- return fmt.Errorf("unsupported message %#v", x)
- }
-
- err = conn.Send(resp)
- if err != nil {
- return err
- }
- if resp == quitResp {
- break
- }
- }
- return nil
+ remote.Main()
}
"testing"
"ruderich.org/simon/safcm"
- ft "ruderich.org/simon/safcm/cmd/safcm-remote/sync/filetest"
+ ft "ruderich.org/simon/safcm/remote/sync/filetest"
"ruderich.org/simon/safcm/testutil"
)
"os"
"path/filepath"
- "ruderich.org/simon/safcm/cmd/safcm-remote/sync"
"ruderich.org/simon/safcm/cmd/safcm/config"
+ "ruderich.org/simon/safcm/remote/sync"
)
func MainFixperms() error {
"testing"
"time"
- ft "ruderich.org/simon/safcm/cmd/safcm-remote/sync/filetest"
+ ft "ruderich.org/simon/safcm/remote/sync/filetest"
"ruderich.org/simon/safcm/testutil"
)
"strings"
"syscall"
- "ruderich.org/simon/safcm/cmd/safcm-remote/sync"
+ "ruderich.org/simon/safcm/remote/sync"
)
func Main(args []string) error {
"syscall"
"testing"
- ft "ruderich.org/simon/safcm/cmd/safcm-remote/sync/filetest"
+ ft "ruderich.org/simon/safcm/remote/sync/filetest"
"ruderich.org/simon/safcm/testutil"
)
"runtime"
"ruderich.org/simon/safcm"
- "ruderich.org/simon/safcm/cmd/safcm-remote/log"
- "ruderich.org/simon/safcm/cmd/safcm-remote/run"
+ "ruderich.org/simon/safcm/remote/log"
+ "ruderich.org/simon/safcm/remote/run"
)
type Info struct {
--- /dev/null
+// Helper copied to the remote host to run commands and deploy configuration
+
+// Copyright (C) 2021 Simon Ruderich
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package remote
+
+import (
+ "fmt"
+ "log"
+ "os"
+
+ "golang.org/x/term"
+
+ "ruderich.org/simon/safcm"
+ "ruderich.org/simon/safcm/remote/ainsl"
+ "ruderich.org/simon/safcm/remote/info"
+ "ruderich.org/simon/safcm/remote/run"
+ "ruderich.org/simon/safcm/remote/sync"
+)
+
+func usage() {
+ log.Fatalf("usage: %[1]s sync\n"+
+ "usage: %[1]s ainsl [options] <path> <line>",
+ os.Args[0])
+}
+
+func Main() {
+ // Timestamps are added by `safcm`
+ log.SetFlags(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()
+ }
+
+ 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
+ logFunc := func(level safcm.LogLevel, msg string) {
+ if logLevel >= level {
+ conn.Send(safcm.MsgLog{
+ Level: level,
+ Text: msg,
+ })
+ }
+ }
+
+ var quitResp safcm.MsgQuitResp
+ for {
+ x, err := conn.Recv()
+ if err != nil {
+ return err
+ }
+
+ var resp safcm.Msg
+ switch x := x.(type) {
+ case safcm.MsgInfoReq:
+ logLevel = x.LogLevel // set log level globally
+ resp = info.Handle(x, run.ExecRunner{}, logFunc)
+ case safcm.MsgSyncReq:
+ resp = sync.Handle(x, run.ExecRunner{}, logFunc)
+ case safcm.MsgQuitReq:
+ resp = quitResp
+ default:
+ return fmt.Errorf("unsupported message %#v", x)
+ }
+
+ err = conn.Send(resp)
+ if err != nil {
+ return err
+ }
+ if resp == quitResp {
+ break
+ }
+ }
+ return nil
+}
"os/exec"
"strings"
- "ruderich.org/simon/safcm/cmd/safcm-remote/log"
+ "ruderich.org/simon/safcm/remote/log"
)
type Cmd struct {
"strings"
"ruderich.org/simon/safcm"
- "ruderich.org/simon/safcm/cmd/safcm-remote/run"
+ "ruderich.org/simon/safcm/remote/run"
)
func (s *Sync) syncCommands() error {
"testing"
"ruderich.org/simon/safcm"
- ft "ruderich.org/simon/safcm/cmd/safcm-remote/sync/filetest"
+ ft "ruderich.org/simon/safcm/remote/sync/filetest"
"ruderich.org/simon/safcm/testutil"
)
"os/user"
"ruderich.org/simon/safcm"
- "ruderich.org/simon/safcm/cmd/safcm-remote/log"
- "ruderich.org/simon/safcm/cmd/safcm-remote/run"
+ "ruderich.org/simon/safcm/remote/log"
+ "ruderich.org/simon/safcm/remote/run"
)
type Sync struct {
"github.com/google/go-cmp/cmp/cmpopts"
"ruderich.org/simon/safcm"
- "ruderich.org/simon/safcm/cmd/safcm-remote/log"
- "ruderich.org/simon/safcm/cmd/safcm-remote/run"
+ "ruderich.org/simon/safcm/remote/log"
+ "ruderich.org/simon/safcm/remote/run"
)
// testRunner implements run.Runner to test commands without actually running