This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
os.go
77 lines (63 loc) · 1.71 KB
/
os.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
package phases
import (
"fmt"
. "github.com/flanksource/konfigadm/pkg/types"
)
//OS provides an abstraction over different operating systems
type OS interface {
// GetVersionCodeName returns the distributions version codename e.g. bionic, xenial, squeeze
GetVersionCodeName() string
//GetPackageManager returns the packagemanager used by the OS
GetPackageManager() PackageManager
//GetTags returns all the tags to which this OS applies
GetTags() []Flag
//DetectAtRuntime will detect if it is compatible with the current running OS
DetectAtRuntime() bool
}
type OperatingSystemList []OS
//SupportedOperatingSystems is a list of all supported OS's, used primarily for detecting runtime flags
var SupportedOperatingSystems = OperatingSystemList{
Debian,
Redhat,
Ubuntu,
AmazonLinux,
RedhatEnterprise,
Centos,
Fedora,
}
var OperatingSystems = map[string]OS{
"ubuntu": Ubuntu,
"debian": Debian,
"redhat": Redhat,
"amazonLinux": AmazonLinux,
"centos": Centos,
"fedora": Fedora,
}
//BaseOperatingSystems is the list of base distributions that are supported, which is currently only debian and redhat
var BaseOperatingSystems = OperatingSystemList{
Debian,
Redhat,
Fedora,
}
func GetOSForTag(tags ...Flag) (OS, error) {
for _, t := range tags {
for _, os := range SupportedOperatingSystems {
for _, tag := range os.GetTags() {
if tag.Name == t.Name {
return os, nil
}
}
}
}
return nil, fmt.Errorf("Unable to find OS for %s", tags)
}
//Detect returns a list of all compatible operating systems at runtime
func (l OperatingSystemList) Detect() []OS {
var list []OS
for _, os := range l {
if os.DetectAtRuntime() {
list = append(list, os)
}
}
return list
}