mybot 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ module Core
2
+ module Osx
3
+ class Git < Mybot::Lib
4
+ def initialize(node)
5
+ @node = node
6
+ end
7
+
8
+ def installed?(options = {})
9
+ options[:file] = "/usr/bin/git"
10
+ @node.exists?(options)
11
+ end
12
+
13
+ def clone(options = {})
14
+ error "repo not specified" unless options[:repo]
15
+
16
+ options[:dest] ||= ""
17
+ options[:key_passphrase] ||= ""
18
+ options[:cmd] = "git clone #{options[:repo]} #{options[:dest]}"
19
+ @node.run(options) do |cmd|
20
+ cmd.on "Are you sure you want to continue connecting (yes/no)?" do
21
+ cmd.write "yes"
22
+ end
23
+
24
+ cmd.on "Enter passphrase for key" do
25
+ cmd.write options[:key_passphrase]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Apache < Mybot::Lib
4
+ def initialize(node)
5
+ @node = node
6
+ @node.use [
7
+ "core/fs",
8
+ "core/ubuntu/apt",
9
+ "core/ubuntu/service"
10
+ ]
11
+ @apache2conf_tpl = tpl_file "core/ubuntu/apache/apache2.conf.erb"
12
+ end
13
+
14
+ def installed?(options = {})
15
+ @node.fs.exists?({ :file => "/usr/sbin/apache2"} )
16
+ end
17
+
18
+ def install(options = {})
19
+ options[:pkg] = "apache2"
20
+ @node.apt.install(options)
21
+ end
22
+
23
+ def remove(options = {})
24
+ options[:pkg] = "apache2"
25
+ @node.apt.remove(options)
26
+ end
27
+
28
+ def reconfigure(options = {})
29
+ error "config is required" unless options[:config]
30
+
31
+ options[:file] = "/etc/apache2/apache2.conf"
32
+ @node.fs.remove(options)
33
+
34
+ options[:content] = @apache2conf_tpl.render(options[:config])
35
+ @node.fs.create(options)
36
+
37
+ options[:service] = "apache2"
38
+ @node.service.restart(options)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Apt < Mybot::Lib
4
+ DF = "DEBIAN_FRONTEND=noninteractive"
5
+
6
+ def initialize(node)
7
+ @node = node
8
+ end
9
+
10
+ def update(options = {})
11
+ options[:cmd] = "#{DF} apt-get update"
12
+ @node.run(options)
13
+ end
14
+
15
+ def upgrade(options = {})
16
+ options[:cmd] = "#{DF} apt-get upgrade -y"
17
+ @node.run(options)
18
+ end
19
+
20
+ def dist_upgrade(options = {})
21
+ options[:cmd] = "#{DF} apt-get dist-upgrade -y"
22
+ @node.run(options)
23
+ end
24
+
25
+ def install(options = {})
26
+ error "pkg not specified" unless options[:pkg]
27
+
28
+ options[:cmd] = "#{DF} apt-get install -y #{options[:pkg]}"
29
+ @node.run(options)
30
+ end
31
+
32
+ def remove(options = {})
33
+ error "pkg not specified" unless options[:pkg]
34
+
35
+ options[:cmd] = "#{DF} apt-get --purge autoremove -y #{options[:pkg]}"
36
+ @node.run(options)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Git < Mybot::Lib
4
+ def initialize(node)
5
+ @node = node
6
+ @node.use [
7
+ "core/fs",
8
+ "core/ubuntu/apt"
9
+ ]
10
+ end
11
+
12
+ def installed?(options = {})
13
+ options[:file] = "/usr/bin/git"
14
+ @node.fs.exists?(options)
15
+ end
16
+
17
+ def install(options = {})
18
+ options[:pkg] = "git"
19
+ @node.apt.install(options)
20
+ end
21
+
22
+ def remove(options = {})
23
+ options[:pkg] = "git"
24
+ @node.apt.remove(options)
25
+ end
26
+
27
+ def clone(options = {})
28
+ error "repo not specified" unless options[:repo]
29
+
30
+ options[:dest] ||= ""
31
+ options[:cmd] = "git clone #{options[:repo]} #{options[:dest]}"
32
+ @node.run(options)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Mysql < Mybot::Lib
4
+
5
+ def initialize(node)
6
+ @node = node
7
+ @node.use [
8
+ "core/fs",
9
+ "core/ubuntu/apt",
10
+ "core/ubuntu/service"
11
+ ]
12
+ end
13
+
14
+ def installed?(options = {})
15
+ options[:file] = "/etc/init.d/mysql"
16
+ @node.fs.exists?(options)
17
+ end
18
+
19
+ def install(options = {})
20
+ error "root_password is required" unless options[:root_password]
21
+
22
+ options[:pkg] = "mysql-server"
23
+ @node.apt.install(options)
24
+
25
+ options[:service] = "mysql"
26
+ @node.service.restart(options)
27
+
28
+ options[:cmd] = "mysql_secure_installation"
29
+ @node.run(options) do |cmd|
30
+ cmd.on "Enter current password for root (enter for none):" do
31
+ cmd.write ""
32
+ end
33
+
34
+ cmd.on "Set root password? [Y/n]" do
35
+ cmd.write "Y"
36
+ end
37
+
38
+ cmd.on "Change the root password? [Y/n]" do
39
+ cmd.write "Y"
40
+ end
41
+
42
+ cmd.on "New password:" do
43
+ cmd.write options[:root_password]
44
+ end
45
+
46
+ cmd.on "Re-enter new password:" do
47
+ cmd.write options[:root_password]
48
+ end
49
+
50
+ cmd.on "Remove anonymous users? [Y/n]" do
51
+ cmd.write "Y"
52
+ end
53
+
54
+ cmd.on "Disallow root login remotely? [Y/n]" do
55
+ cmd.write "Y"
56
+ end
57
+
58
+ cmd.on "Remove test database and access to it? [Y/n]" do
59
+ cmd.write "Y"
60
+ end
61
+
62
+ cmd.on "Reload privilege tables now? [Y/n]" do
63
+ cmd.write "Y"
64
+ end
65
+ end
66
+ end
67
+
68
+ def remove(options = {})
69
+ options[:service] = "mysql"
70
+ @node.service.stop(options)
71
+
72
+ options[:pkg] = "mysql-server"
73
+ @node.apt.remove(options)
74
+
75
+ options[:dir] = "/etc/mysql"
76
+ @node.fs.remove(options)
77
+
78
+ options[:dir] = "/var/lib/mysql"
79
+ @node.fs.remove(options)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,55 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Passenger < Mybot::Lib
4
+ def initialize(node)
5
+ @node = node
6
+ @node.use [
7
+ "core/ubuntu/ruby",
8
+ "core/ubuntu/apache"
9
+ ]
10
+ end
11
+
12
+ def installed?(options = {})
13
+ error "ruby_version is required" unless options[:ruby_version]
14
+
15
+ options[:gem_name] = "passenger"
16
+ @node.ruby.rbenv_gem_installed?(options)
17
+ end
18
+
19
+ def install(options = {})
20
+ error "server is required" unless options[:server]
21
+ unless options[:server] == "apache" || options[:server] == "nginx"
22
+ error "invalid server, allowed are: 'apache' and 'nginx'"
23
+ end
24
+
25
+ options[:pkg] = "libcurl4-openssl-dev"
26
+ @node.apt.install(options)
27
+
28
+ options[:pkg] = "apache2-prefork-dev"
29
+ @node.apt.install(options)
30
+
31
+ options[:pkg] = "libapr1-dev"
32
+ @node.apt.install(options)
33
+
34
+ options[:pkg] = "libaprutil1-dev"
35
+ @node.apt.install(options)
36
+
37
+ options[:gem_name] = "passenger"
38
+ @node.ruby.rbenv_gem_install(options)
39
+
40
+ if options[:server] == "apache"
41
+ options[:cmd] = "passenger-install-apache2-module -a"
42
+ else
43
+ options[:cmd] = "passenger-install-nginx-module -a"
44
+ end
45
+
46
+ @node.ruby.rbenv_exec(options)
47
+ end
48
+
49
+ def remove(options = {})
50
+ options[:gem_name] = "passenger"
51
+ @node.ruby.rbenv_gem_remove(options)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,165 @@
1
+ module Core
2
+ module Ubuntu
3
+ class Ruby < Mybot::Lib
4
+ RBENV_ROOT = "/usr/local/rbenv"
5
+
6
+ def initialize(node)
7
+ @node = node
8
+ @node.use [
9
+ "core/fs",
10
+ "core/ubuntu/apt"
11
+ ]
12
+ end
13
+
14
+ def system_installed?(options = {})
15
+ options[:file] = "/usr/bin/ruby"
16
+ @node.fs.exists?(options)
17
+ end
18
+
19
+ def system_install(options = {})
20
+ options[:pkg] = "ruby"
21
+ @node.apt.install(options)
22
+ end
23
+
24
+ def system_remove(options = {})
25
+ options[:pkg] = "ruby"
26
+ @node.apt.remove(options)
27
+ end
28
+
29
+ def rbenv_installed?(options = {})
30
+ options[:file] = "/usr/bin/rbenv"
31
+ @node.fs.exists?(options)
32
+ end
33
+
34
+ def rbenv_install(options = {})
35
+ options[:pkg] = "rbenv"
36
+ @node.apt.install(options)
37
+
38
+ options[:pkg] = "ruby-build"
39
+ @node.apt.install(options)
40
+
41
+ options[:dir] = RBENV_ROOT
42
+ @node.fs.create(options)
43
+ end
44
+
45
+ def rbenv_remove(options = {})
46
+ options[:pkg] = "rbenv"
47
+ @node.apt.remove(options)
48
+
49
+ options[:pkg] = "ruby-build"
50
+ @node.apt.remove(options)
51
+
52
+ options[:dir] = RBENV_ROOT
53
+ @node.fs.remove(options)
54
+ end
55
+
56
+ def rbenv_version_list(options = {})
57
+ options[:env] ||= {
58
+ "RBENV_ROOT" => RBENV_ROOT
59
+ }
60
+ options[:cmd] = "rbenv versions"
61
+ versions = @node.run(options)
62
+ versions.split("\r\n").map { |v| v.strip }
63
+ end
64
+
65
+ def rbenv_version_installed?(options = {})
66
+ error "ruby_version is required" unless options[:ruby_version]
67
+
68
+ rbenv_version_list(options).include?(options[:ruby_version])
69
+ end
70
+
71
+ def rbenv_version_install(options = {})
72
+ error "ruby_version is required" unless options[:ruby_version]
73
+
74
+ options[:env] ||= {
75
+ "RBENV_ROOT" => RBENV_ROOT
76
+ }
77
+
78
+ if options[:ruby_version].include?("1.8.7")
79
+ options[:env]["CFLAGS"] = "-O2 "
80
+ options[:env]["CFLAGS"] += "-fno-tree-dce "
81
+ options[:env]["CFLAGS"] += "-fno-optimize-sibling-calls"
82
+ end
83
+
84
+ options[:cmd] = "rbenv install #{options[:ruby_version]}"
85
+ @node.run(options)
86
+ end
87
+
88
+ def rbenv_version_remove(options = {})
89
+ error "ruby_version is required" unless options[:ruby_version]
90
+
91
+ options[:dir] = "#{RBENV_ROOT}/versions/#{options[:ruby_version]}"
92
+ @node.fs.remove(options)
93
+ end
94
+
95
+ def rbenv_exec(options = {})
96
+ error "ruby_version is required" unless options[:ruby_version]
97
+ error "cmd is required" unless options[:cmd]
98
+
99
+ options[:env] ||= {
100
+ "RBENV_ROOT" => RBENV_ROOT,
101
+ "RBENV_VERSION" => options[:ruby_version]
102
+ }
103
+
104
+ options[:cmd] = "rbenv exec #{options[:cmd]}"
105
+ @node.run(options)
106
+ end
107
+
108
+ def rbenv_gem_list(options = {})
109
+ options[:cmd] = "gem list"
110
+ gems = rbenv_exec(options)
111
+ gems = gems.split("\r\n").reject do |g|
112
+ g == "" || g == "*** LOCAL GEMS ***"
113
+ end.map do |g|
114
+ parts = g.split("(")
115
+ {
116
+ :gem_name => parts[0].strip,
117
+ :gem_versions => parts[1].split(",").map do |v|
118
+ v.gsub(")", "").strip
119
+ end
120
+ }
121
+ end
122
+ end
123
+
124
+ def rbenv_gem_installed?(options = {})
125
+ error "gem_name is required" unless options[:gem_name]
126
+
127
+ rbenv_gem_list(options).each do |g|
128
+ if g[:gem_name] == options[:gem_name]
129
+ if options[:gem_version]
130
+ if g[:gem_versions].include?(options[:gem_version])
131
+ return true
132
+ end
133
+ else
134
+ return true
135
+ end
136
+ end
137
+ end
138
+
139
+ false
140
+ end
141
+
142
+ def rbenv_gem_install(options = {})
143
+ error "gem_name is required" unless options[:gem_name]
144
+
145
+ options[:cmd] = "gem install #{options[:gem_name]} --no-ri --no-rdoc"
146
+ if options[:gem_version]
147
+ options[:cmd] += " -v=#{options[:gem_version]}"
148
+ end
149
+
150
+ rbenv_exec(options)
151
+ end
152
+
153
+ def rbenv_gem_remove(options = {})
154
+ error "gem is required" unless options[:gem_name]
155
+
156
+ options[:cmd] = "gem uninstall #{options[:gem]} -Iax"
157
+ if options[:gem_version]
158
+ options[:cmd] += " -v=#{options[:gem_version]}"
159
+ end
160
+
161
+ rbenv_exec(options)
162
+ end
163
+ end
164
+ end
165
+ end