This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
forked from gomodules/x
/
debian_generic.go
144 lines (125 loc) · 3.94 KB
/
debian_generic.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package script
import (
"io/ioutil"
"log"
"os"
"github.com/appscode/go/os/repos"
"github.com/appscode/go/strings"
)
type DebianGeneric struct {
LinuxGeneric
}
func (script *DebianGeneric) ProcessEnable(ps string) {
// TODO(verify): unused
os.Remove("/etc/init/" + ps + ".override")
script.shell.Command("/usr/sbin/update-rc.d", ps, "enable").Run()
}
func (script *DebianGeneric) ProcessDisable(ps string) {
file := "/etc/init/" + ps + ".override"
if _, err := os.Stat(file); os.IsNotExist(err) {
ioutil.WriteFile(file, []byte("manual"), 0600)
}
// update-rc.d salt-minion disable
// service salt-minion stop
script.shell.Command("/usr/sbin/update-rc.d", ps, "disable").Run()
// TODO: Need a repeat loop?
/*
while service salt-minion status >/dev/null; do
echo "salt-minion found running, stopping"
service salt-minion stop
sleep 1
done
*/
script.shell.Command("/usr/sbin/service", ps, "stop").Run()
}
func (script *DebianGeneric) AddPPA(ppa ...string) {
a := append([]string{"-y"}, ppa...)
b := make([]interface{}, len(a))
for i, s := range a {
b[i] = s
}
script.shell.Command("/usr/bin/add-apt-repository", b...).Run()
script.shell.Command("/usr/bin/apt-get", "update").Run()
}
/*
Example:
wget -O- https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
nano /etc/apt/sources.list.d/saltstack.list
deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2015.8 trusty main
*/
func (script *DebianGeneric) AddRepo(r interface{}) {
repo := r.(repos.DebianRepo)
if repo.GPGKeyURL != "" {
script.shell.Command("wget", "-O-", repo.GPGKeyURL).Command("apt-key", "add", "-").Run()
}
if repo.Deb != "" {
script.AddLine(repo.Listing, repo.Deb)
}
if repo.DebSrc != "" {
script.AddLine(repo.Listing, repo.DebSrc)
}
script.shell.Command("/usr/bin/apt-get", "update").Run()
}
func (script *DebianGeneric) UpdateRepos() {
script.shell.Command("/usr/bin/apt-get", "update").Run()
}
func (script *DebianGeneric) UpgradePkgs() {
script.shell.Command("/usr/bin/apt-get", "upgrade", "-y").Run()
}
func (script *DebianGeneric) InstallPkgDeps() {
script.shell.Command("/usr/bin/apt-get", "install", "-f", "-y").Run()
}
func (script *DebianGeneric) InstallPkgs(pkgs ...string) {
a := append([]string{"install", "-y"}, pkgs...)
b := make([]interface{}, len(a))
for i, s := range a {
b[i] = s
}
script.shell.Command("/usr/bin/apt-get", b...).Run()
}
func (script *DebianGeneric) DeactivateDaemons() {
content := `#!/bin/sh
echo "Salt shall not start." >&2
exit 101`
ioutil.WriteFile("/usr/sbin/policy-rc.d", []byte(content), 0755)
}
func (script *DebianGeneric) ActivateDaemons() {
file := "/usr/sbin/policy-rc.d"
if _, err := os.Stat(file); err == nil {
if err := os.Remove(file); err != nil {
log.Fatal(err)
}
}
}
func (script *DebianGeneric) InstallSaltMaster(versions ...string) {
v := strings.VString(repos.DefaultSaltstackVersion["debian"], versions...)
if !script.ProcessExists("salt-master") || !script.ProcessExists("salt-minion") {
script.AddRepo(repos.DebianRepos[v])
script.InstallPkgs("salt-master", "salt-api", "salt-minion")
}
}
func (script *DebianGeneric) InstallSaltMinion(versions ...string) {
v := strings.VString(repos.DefaultSaltstackVersion["debian"], versions...)
if !script.ProcessExists("salt-minion") {
script.AddRepo(repos.DebianRepos[v])
script.InstallPkgs("salt-minion")
}
}
/*
func (script *ubuntuImpl) installSaltMinion() {
if !script.ProcessExists("salt-minion") {
script.InstallPkg("python-software-properties")
script.AddRepo("ppa:saltstack/salt")
script.InstallPkg("salt-minion")
}
script.ProcessRestart("salt-minion")
}
func (script *ubuntuImpl) installSaltMaster() {
if !script.ProcessExists("salt-master") || !script.ProcessExists("salt-minion") {
script.InstallPkg("python-software-properties")
script.AddRepo("ppa:saltstack/salt")
script.InstallPkg("salt-master", "salt-minion")
}
script.ProcessRestart("salt-minion", "salt-master")
}
*/