choice between distribute types

This commit is contained in:
Pavel Vorobyov
2019-09-25 12:53:08 +03:00
parent 1328d7d68c
commit e659ccb06f
6 changed files with 48 additions and 1 deletions

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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

View File

@@ -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,
}

View File

@@ -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