-
-
Notifications
You must be signed in to change notification settings - Fork 479
/
setup.go
59 lines (51 loc) · 1.25 KB
/
setup.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
package manifest
import (
"os"
"os/exec"
"runtime"
"sort"
"strings"
homedir "github.com/mitchellh/go-homedir"
)
// Render returns the rendered wrapper and manifest
func Render(browser, wrapperPath, binPath string, global bool) ([]byte, []byte, error) {
mf, err := getManifestContent(browser, wrapperPath)
if err != nil {
return nil, nil, err
}
if binPath == "" {
binPath = gopassPath(global)
}
wrap, err := getWrapperContent(binPath)
if err != nil {
return nil, nil, err
}
return wrap, mf, nil
}
// ValidBrowser returns true if the given browser is supported on this platform
func ValidBrowser(name string) bool {
_, found := manifestPath[runtime.GOOS][name]
return found
}
// ValidBrowsers are all browsers for which the manifest can be currently installed
func ValidBrowsers() []string {
keys := make([]string, 0, len(manifestPath[runtime.GOOS]))
for k := range manifestPath[runtime.GOOS] {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
func gopassPath(global bool) string {
if !global {
if hd, err := homedir.Dir(); err == nil {
if gpp, err := os.Executable(); err == nil && strings.HasPrefix(gpp, hd) {
return gpp
}
}
}
if gpp, err := exec.LookPath("gopass"); err == nil {
return gpp
}
return "gopass"
}