generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
aptbinary.go
57 lines (50 loc) · 1.22 KB
/
aptbinary.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
package autostartconf
import (
"path/filepath"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
)
type AptBinaryConfigurer struct {
LinuxSystemdConfigurer
URL string
Name string
aptDependencies []string
}
func (abc AptBinaryConfigurer) Install() error {
_ = abc.UnInstall() // best effort
// install apt dependencies
err := execCommands([][]string{
{"apt-get", "update"},
append([]string{"apt-get", "install", "-y"}, abc.aptDependencies...),
})
if err != nil {
return breverrors.WrapAndTrace(err)
}
// download binary
err = abc.Store.DownloadBinary(
abc.URL,
filepath.Join("/usr/local/bin", abc.Name),
)
if err != nil {
return breverrors.WrapAndTrace(err)
}
err = abc.Store.WriteString(abc.getDestConfigFile(), abc.ValueConfigFile)
if err != nil {
return breverrors.WrapAndTrace(err)
}
if ShouldSymlink() {
errother := abc.CreateForcedSymlink()
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
} else {
errother := execCommands([][]string{
{"systemctl", "enable", abc.ServiceName},
{"systemctl", "start", abc.ServiceName},
{"systemctl", "daemon-reload"},
})
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
}
return nil
}