-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.go
51 lines (45 loc) · 894 Bytes
/
helper.go
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
51
package main
import (
"fmt"
"io/ioutil"
"os/user"
"path/filepath"
)
const netrcFile = `
machine %s
login %s
password %s
`
// helper function to write a netrc file.
func writeNetrc(machine, login, password string) error {
if machine == "" {
return nil
}
out := fmt.Sprintf(
netrcFile,
machine,
login,
password,
)
home := "/root"
u, err := user.Current()
if err == nil {
home = u.HomeDir
}
path := filepath.Join(home, ".netrc")
return ioutil.WriteFile(path, []byte(out), 0600)
}
// func debugGit() {
// cmd := exec.Command("env")
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// if err := cmd.Run(); err != nil {
// log.Printf("error in debug\n%v", err)
// }
// cmd = exec.Command("cat", "/root/.netrc")
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
// if err := cmd.Run(); err != nil {
// log.Printf("error in debug\n%v", err)
// }
// }