-
Notifications
You must be signed in to change notification settings - Fork 15
/
installbybash.go
97 lines (83 loc) · 2.68 KB
/
installbybash.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package install
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/CS-SI/SafeScale/lib/server/install/enums/Action"
"github.com/CS-SI/SafeScale/lib/server/install/enums/Method"
)
// bashInstaller is an installer using script to add and remove a feature
type bashInstaller struct{}
func (i *bashInstaller) GetName() string {
return "script"
}
// Check checks if the feature is installed, using the check script in Specs
func (i *bashInstaller) Check(f *Feature, t Target, v Variables, s Settings) (Results, error) {
yamlKey := "feature.install.bash.check"
if !f.specs.IsSet(yamlKey) {
msg := `syntax error in feature '%s' specification file (%s): no key '%s' found`
return nil, fmt.Errorf(msg, f.DisplayName(), f.DisplayFilename(), yamlKey)
}
worker, err := newWorker(f, t, Method.Bash, Action.Check, nil)
if err != nil {
return nil, err
}
err = worker.CanProceed(s)
if err != nil {
log.Println(err.Error())
return nil, err
}
return worker.Proceed(v, s)
}
// Add installs the feature using the install script in Specs
// 'values' contains the values associated with parameters as defined in specification file
func (i *bashInstaller) Add(f *Feature, t Target, v Variables, s Settings) (Results, error) {
// Determining if install script is defined in specification file
if !f.specs.IsSet("feature.install.bash.add") {
msg := `syntax error in feature '%s' specification file (%s):
no key 'feature.install.bash.add' found`
return nil, fmt.Errorf(msg, f.DisplayName(), f.DisplayFilename())
}
worker, err := newWorker(f, t, Method.Bash, Action.Add, nil)
if err != nil {
return nil, err
}
err = worker.CanProceed(s)
if err != nil {
log.Println(err.Error())
return nil, err
}
if !worker.ConcernsCluster() {
if _, ok := v["Username"]; !ok {
v["Username"] = "safescale"
}
}
return worker.Proceed(v, s)
}
// Remove uninstalls the feature
func (i *bashInstaller) Remove(f *Feature, t Target, v Variables, s Settings) (Results, error) {
if !f.specs.IsSet("feature.install.bash.remove") {
msg := `syntax error in feature '%s' specification file (%s):
no key 'feature.install.bash.remove' found`
return nil, fmt.Errorf(msg, f.DisplayName(), f.DisplayFilename())
}
worker, err := newWorker(f, t, Method.Bash, Action.Remove, nil)
if err != nil {
return nil, err
}
err = worker.CanProceed(s)
if err != nil {
log.Println(err.Error())
return nil, err
}
_, clusterTarget, _ := determineContext(t)
if clusterTarget == nil {
if _, ok := v["Username"]; !ok {
v["Username"] = "safescale"
}
}
return worker.Proceed(v, s)
}
// NewBashInstaller creates a new instance of Installer using script
func NewBashInstaller() Installer {
return &bashInstaller{}
}