-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (44 loc) · 899 Bytes
/
main.go
File metadata and controls
50 lines (44 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"flag"
"fmt"
"os"
"os/exec"
)
func main() {
os.Exit(Main())
}
func Main() int {
var pemPath string
var host string
var dir string
flag.StringVar(&pemPath, "i", "~/.ssh/id_rsa", "through to ssh -i")
flag.StringVar(&host, "h", "", "user@host")
flag.StringVar(&dir, "d", "", "working dir")
flag.Parse()
err := update(host, pemPath, dir)
if err != nil {
fmt.Println(err)
return 1
}
return 0
}
func update(host, pemPath, dir string) error {
cmd := fmt.Sprintf(`
bash -xe -c '
cd %s
git checkout master
git pull
bin/update
'
`, dir)
c := exec.Command("ssh", host, "-t", "-t", "-i", pemPath, "-oStrictHostKeyChecking=no", cmd)
buf := bytes.NewBuffer([]byte{})
c.Stdout = buf
c.Stderr = buf
if err := c.Run(); err != nil {
return fmt.Errorf("ssh to %s is failed.\n\nError:\n%s\n\nOutput:\n\n%s", host, err, buf.String())
}
return nil
}