func decolateCmd(c conf.ServerInfo, cmd string, sudo bool) string { c.SudoOpt.ExecBySudo = true if sudo && c.User != "root" && !c.IsContainer() { switch { case c.SudoOpt.ExecBySudo: cmd = fmt.Sprintf("echo %s | sudo -S %s", c.Password, cmd) case c.SudoOpt.ExecBySudoSh: cmd = fmt.Sprintf("echo %s | sudo sh -c '%s'", c.Password, cmd) } } if c.Family != "FreeBSD" { // set pipefail option. Bash only // http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another cmd = fmt.Sprintf("set -o pipefail; %s", cmd) } if c.IsContainer() { switch c.Container.Type { case "", "docker": cmd = fmt.Sprintf(`docker exec %s /bin/bash -c "%s"`, c.Container.ContainerID, cmd) } } return cmd }
func decolateCmd(c conf.ServerInfo, cmd string, sudo bool) string { if sudo && c.User != "root" && !c.IsContainer() { cmd = fmt.Sprintf("sudo -S %s", cmd) cmd = strings.Replace(cmd, "|", "| sudo ", -1) } if c.Distro.Family != "FreeBSD" { // set pipefail option. Bash only // http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another cmd = fmt.Sprintf("set -o pipefail; %s", cmd) } if c.IsContainer() { switch c.Container.Type { case "", "docker": cmd = fmt.Sprintf(`docker exec %s /bin/bash -c "%s"`, c.Container.ContainerID, cmd) case "lxd": cmd = fmt.Sprintf(`lxc exec %s -- /bin/bash -c "%s"`, c.Container.Name, cmd) } } // cmd = fmt.Sprintf("set -x; %s", cmd) return cmd }