diff --git a/cli/cli.go b/cli/cli.go index bddc942..56a9a38 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -34,6 +34,7 @@ type Cli struct { mode execMode user string raiseType remote.RaiseType + distributeType remote.CopyType raisePasswd string remoteTmpDir string delay int @@ -113,6 +114,7 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) { cli.connectTimeout = cfg.SSHConnectTimeout cli.remoteTmpDir = cfg.RemoteTmpdir cli.setRaiseType(cfg.RaiseType) + cli.setDistributeType(cfg.Distribute) // output cli.outputFileName = "" @@ -460,6 +462,7 @@ func (c *Cli) setRaiseType(rt string) { c.raiseType = remote.RTNone default: term.Errorf("Unknown raise type: %s\n", rt) + return } if c.raiseType != currentRaiseType { @@ -468,3 +471,17 @@ func (c *Cli) setRaiseType(rt string) { } remote.SetRaise(c.raiseType) } + +func (c *Cli) setDistributeType(dtr string) { + switch dtr { + case "tar": + c.distributeType = remote.CTTar + case "scp": + c.distributeType = remote.CTScp + default: + term.Errorf("Unknown distribute type: %s\n", dtr) + return + } + term.Successf("distribute_type set to %s\n", dtr) + remote.SetDistributeType(c.distributeType) +} diff --git a/cli/completer.go b/cli/completer.go index f907189..1c947c3 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -24,6 +24,7 @@ func newCompleter(store *store.Store, commands []string) *completer { x.handlers["debug"] = onOffCompleter() x.handlers["progressbar"] = onOffCompleter() x.handlers["prepend_hostnames"] = onOffCompleter() + x.handlers["use_password_manager"] = onOffCompleter() x.handlers["raise"] = staticCompleter([]string{"none", "su", "sudo"}) x.handlers["interpreter"] = staticCompleter([]string{"none", "su", "sudo"}) x.handlers["exec"] = x.completeExec @@ -39,6 +40,7 @@ func newCompleter(store *store.Store, commands []string) *completer { x.handlers["s_runscript"] = x.completeDistribute x.handlers["c_runscript"] = x.completeDistribute x.handlers["p_runscript"] = x.completeDistribute + x.handlers["distribute_type"] = staticCompleter([]string{"tar", "scp"}) helpTopics := append(commands, "expressions", "config", "rcfiles", "passmgr") x.handlers["help"] = staticCompleter(helpTopics) diff --git a/cli/handlers.go b/cli/handlers.go index 1182efc..4dc6cad 100644 --- a/cli/handlers.go +++ b/cli/handlers.go @@ -49,6 +49,7 @@ func (c *Cli) setupCmdHandlers() { c.handlers["c_runscript"] = c.doCRunScript c.handlers["p_runscript"] = c.doPRunScript c.handlers["use_password_manager"] = c.doUsePasswordManager + c.handlers["distribute_type"] = c.doDistributeType commands := make([]string, len(c.handlers)) i := 0 @@ -148,6 +149,18 @@ func (c *Cli) doRaise(name string, argsLine string, args ...string) { c.setRaiseType(args[0]) } +func (c *Cli) doDistributeType(name string, argsLine string, args ...string) { + if len(args) < 1 { + dtype := "scp" + if c.distributeType == remote.CTTar { + dtype = "tar" + } + term.Warnf("distribute_type is %s\n", dtype) + return + } + c.setDistributeType(args[0]) +} + func (c *Cli) doPasswd(name string, argsLine string, args ...string) { passwd, err := c.rl.ReadPassword("Set su/sudo password: ") if err != nil { diff --git a/config/config.go b/config/config.go index f40ca5e..fc9c126 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ log_file = raise = none exit_confirm = true exec_confirm = true +distribute = tar [executer] ssh_threads = 50 @@ -88,6 +89,7 @@ type XCConfig struct { Interpreter string PasswordManagerPath string LocalEnvironment map[string]string + Distribute string } const ( @@ -111,6 +113,7 @@ const ( defaultInterpreter = "/bin/bash" defaultSudoInterpreter = "sudo /bin/bash" defaultSuInterpreter = "su -" + defaultDistribute = "tar" ) var ( @@ -248,6 +251,12 @@ func read(filename string, secondPass bool) (*XCConfig, error) { } cfg.RaiseType = rt + dtr, err := props.GetString("main.distribute") + if err != nil { + dtr = defaultDistribute + } + cfg.Distribute = dtr + mode, err := props.GetString("main.mode") if err != nil { mode = defaultMode diff --git a/remote/distribute.go b/remote/distribute.go index 6690c53..66d8ad5 100644 --- a/remote/distribute.go +++ b/remote/distribute.go @@ -41,7 +41,7 @@ func Distribute(hosts []string, localFilename string, remoteFilename string, rec LocalFilename: localFilename, RemoteFilename: remoteFilename, RecursiveCopy: recursive, - Copy: CTTar, + Copy: currentDistributeType, Cmd: "", WG: &wg, } diff --git a/remote/remote.go b/remote/remote.go index e588212..3f74a67 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -14,6 +14,7 @@ var ( currentUser string currentPassword string currentRaise RaiseType + currentDistributeType CopyType currentUsePasswordManager bool currentProgressBar bool currentPrependHostnames bool @@ -59,6 +60,11 @@ func SetRaise(raise RaiseType) { currentRaise = raise } +// SetDistributeType sets executer distribute type +func SetDistributeType(dtr CopyType) { + currentDistributeType = dtr +} + // SetPassword sets executer password func SetPassword(password string) { currentPassword = password