Start Up is a simple deployment tool that performs given set of commands on multiple hosts in parallel.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
956 B

package stup
import (
"bytes"
"fmt"
"io"
"os"
"strings"
"sync"
"github.com/pkg/errors"
)
var (
mtx = &sync.Mutex{}
sudoFunc = func(sudoerPassword string, in io.Writer, output *bytes.Buffer, endChan chan struct{}) {
for {
select {
case <-endChan:
default:
//TODO: Refactor it
mtx.Lock()
if output.Len() > 0 {
msg := output.String()
if strings.Contains(msg, "[sudo] ") {
_, err := in.Write([]byte(sudoerPassword + "\n"))
if err != nil && err != io.EOF {
fmt.Fprintf(os.Stderr, "%v", errors.Wrap(err, "some went wrong when trying remote sudo"))
}
}
}
mtx.Unlock()
}
}
}
execFunc = func(session Session, command string) {
err := session.Run(command)
if err != nil {
fmt.Fprintf(os.Stderr, "%v", errors.Wrap(err, "some went wrong when trying execute remote command"))
}
}
)
type Session interface {
Run(cmd string) error
Wait() error
Close() error
}