-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer.go
54 lines (42 loc) · 1.22 KB
/
installer.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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package workflow
import (
"os"
"os/exec"
"github.com/spf13/afero"
"github.com/ava-labs/apm/url"
)
type Installer interface {
Download(url string, path string) error
Decompress(source string, dest string) error
// Install installs the VM. installScriptPath is a path relative to
// workingDir.
Install(workingDir string, args ...string) error
}
var _ Installer = &VMInstaller{}
type VMInstallerConfig struct {
Fs afero.Fs
URLClient url.Client
}
func NewVMInstaller(config VMInstallerConfig) *VMInstaller {
return &VMInstaller{
fs: config.Fs,
Client: config.URLClient,
}
}
type VMInstaller struct {
fs afero.Fs
url.Client
}
func (t VMInstaller) Decompress(source string, dest string) error {
cmd := exec.Command("tar", "xf", source, "-C", dest, "--strip-components", "1")
return cmd.Run()
}
func (t VMInstaller) Install(workingDir string, args ...string) error {
cmd := exec.Command(args[0], args[1:]...) // #nosec G204 installation scripts are assumed to be trusted if a user is tracking a plugin repository
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = workingDir
return cmd.Run()
}