-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
73 lines (58 loc) · 1.05 KB
/
utils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package utils
import (
"io"
"os"
"path/filepath"
"runtime"
)
func GetHomeDir() string {
if runtime.GOOS == "windows" {
return os.Getenv("USERPROFILE")
}
return os.Getenv("HOME")
}
func GetBaseDir() string {
baseDir := os.Getenv("MACHINE_DIR")
if baseDir == "" {
baseDir = GetHomeDir()
}
return baseDir
}
func GetDockerDir() string {
return filepath.Join(GetBaseDir(), ".docker")
}
func GetMachineDir() string {
return filepath.Join(GetDockerDir(), "machines")
}
func GetMachineClientCertDir() string {
return filepath.Join(GetMachineDir(), ".client")
}
func GetUsername() string {
u := "unknown"
osUser := ""
switch runtime.GOOS {
case "darwin", "linux":
osUser = os.Getenv("USER")
case "windows":
osUser = os.Getenv("USERNAME")
}
if osUser != "" {
u = osUser
}
return u
}
func CopyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
if _, err = io.Copy(out, in); err != nil {
return err
}
return nil
}