mybot 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Botfile +7 -61
- data/CHANGELOG.md +2 -25
- data/README.md +72 -189
- data/lib/mybot.rb +20 -21
- data/lib/mybot/base.rb +6 -2
- data/lib/mybot/cli.rb +45 -5
- data/lib/mybot/command.rb +37 -28
- data/lib/mybot/fmt.rb +143 -52
- data/lib/mybot/helpers.rb +24 -0
- data/lib/mybot/installer.rb +31 -0
- data/lib/mybot/lib.rb +20 -59
- data/lib/mybot/libs.rb +31 -28
- data/lib/mybot/loader.rb +25 -0
- data/lib/mybot/node.rb +100 -47
- data/lib/mybot/nodes.rb +16 -0
- data/lib/mybot/tasks.rb +47 -11
- data/lib/mybot/template.rb +8 -8
- data/lib/mybot/templates.rb +15 -0
- data/lib/mybot/version.rb +1 -1
- data/vendor/lib/{core/.gitkeep → .gitkeep} +0 -0
- data/vendor/{recipes → plugins}/.gitkeep +0 -0
- data/vendor/{tpl/core → tasks}/.gitkeep +0 -0
- data/vendor/tpl/.gitkeep +0 -0
- metadata +11 -34
- data/lib/mybot/aws.rb +0 -54
- data/lib/mybot/commands.rb +0 -108
- data/lib/mybot/core-ext/array.rb +0 -9
- data/lib/mybot/core-ext/class.rb +0 -53
- data/lib/mybot/core-ext/kernel.rb +0 -21
- data/lib/mybot/messages.rb +0 -30
- data/lib/mybot/recipes.rb +0 -25
- data/lib/mybot/result.rb +0 -26
- data/lib/mybot/utils.rb +0 -7
- data/vendor/lib/core/fs.rb +0 -191
- data/vendor/lib/core/osx/git.rb +0 -31
- data/vendor/lib/core/osx/rails.rb +0 -31
- data/vendor/lib/core/osx/static.rb +0 -31
- data/vendor/lib/core/ubuntu/apache.rb +0 -42
- data/vendor/lib/core/ubuntu/apt.rb +0 -57
- data/vendor/lib/core/ubuntu/git.rb +0 -48
- data/vendor/lib/core/ubuntu/mysql.rb +0 -214
- data/vendor/lib/core/ubuntu/nginx.rb +0 -43
- data/vendor/lib/core/ubuntu/passenger.rb +0 -55
- data/vendor/lib/core/ubuntu/php.rb +0 -76
- data/vendor/lib/core/ubuntu/rails.rb +0 -105
- data/vendor/lib/core/ubuntu/ruby.rb +0 -166
- data/vendor/lib/core/ubuntu/service.rb +0 -30
- data/vendor/lib/core/ubuntu/static.rb +0 -50
- data/vendor/lib/core/ubuntu/users.rb +0 -76
- data/vendor/lib/core/ubuntu/vim.rb +0 -31
- data/vendor/tpl/core/ubuntu/apache/apache2.conf.erb +0 -80
- data/vendor/tpl/core/ubuntu/nginx/nginx.conf.erb +0 -72
- data/vendor/tpl/core/ubuntu/php/php.ini.erb +0 -1818
data/lib/mybot/utils.rb
DELETED
data/vendor/lib/core/fs.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
module Core
|
2
|
-
class Fs < Mybot::Lib
|
3
|
-
def initialize(node)
|
4
|
-
@node = node
|
5
|
-
end
|
6
|
-
|
7
|
-
def exists?(options = {})
|
8
|
-
unless options[:file] || options[:dir]
|
9
|
-
error "file or dir is required"
|
10
|
-
end
|
11
|
-
|
12
|
-
if options[:file]
|
13
|
-
options[:cmd] = "test -e #{options[:file]} && echo EXISTS"
|
14
|
-
elsif options[:dir]
|
15
|
-
options[:cmd] = "test -e #{options[:dir]} && echo EXISTS"
|
16
|
-
end
|
17
|
-
@node.run(options).stdout.include?("EXISTS") ? true : false
|
18
|
-
end
|
19
|
-
|
20
|
-
def create(options = {})
|
21
|
-
unless options[:file] || options[:dir]
|
22
|
-
error "file or dir is required"
|
23
|
-
end
|
24
|
-
|
25
|
-
if options[:file]
|
26
|
-
options[:pattern] = "/tmp/mybot.XXXXX"
|
27
|
-
tmp = mktemp(options)
|
28
|
-
|
29
|
-
options[:content] ||= ""
|
30
|
-
@node.sftp.file.open(tmp, "w") { |f| f.write options[:content] }
|
31
|
-
options[:cmd] = "mv #{tmp} #{options[:file]}"
|
32
|
-
@node.run(options)
|
33
|
-
else
|
34
|
-
options[:cmd] = "mkdir -p #{options[:dir]}"
|
35
|
-
@node.run(options)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def mktemp(options = {})
|
40
|
-
error "pattern required" unless options[:pattern]
|
41
|
-
|
42
|
-
options[:cmd] = "mktemp #{options[:pattern]}"
|
43
|
-
sudo = options[:sudo]
|
44
|
-
options[:sudo] = false
|
45
|
-
tmp = @node.run(options).stdout
|
46
|
-
options[:sudo] = sudo
|
47
|
-
tmp.strip
|
48
|
-
end
|
49
|
-
|
50
|
-
def remove(options = {})
|
51
|
-
unless options[:file] || options[:dir]
|
52
|
-
error "file or dir is required"
|
53
|
-
end
|
54
|
-
|
55
|
-
if options[:file]
|
56
|
-
options[:cmd] = "rm -f #{options[:file]}"
|
57
|
-
else
|
58
|
-
options[:cmd] = "rm -rf #{options[:dir]}"
|
59
|
-
end
|
60
|
-
|
61
|
-
@node.run(options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def read(options = {})
|
65
|
-
error "file is required" unless options[:file]
|
66
|
-
|
67
|
-
options[:cmd] = "cat #{options[:file]}"
|
68
|
-
@node.run(options) do |cmd|
|
69
|
-
cmd.on "No such file or directory" do
|
70
|
-
@node.fmt.error "read: file '#{options[:file]}' does not exists"
|
71
|
-
return ""
|
72
|
-
end
|
73
|
-
end.stdout
|
74
|
-
end
|
75
|
-
|
76
|
-
def upload(options = {})
|
77
|
-
error "from is required" unless options[:from]
|
78
|
-
error "to is required" unless options[:to]
|
79
|
-
@node.fmt.upload(options[:from], options[:to])
|
80
|
-
|
81
|
-
@node.sftp.upload!(options[:from],
|
82
|
-
options[:to]) do |event, uploader, *args|
|
83
|
-
case event
|
84
|
-
when :put
|
85
|
-
n = (args[1].to_f * 100 / args[0].size.to_f).to_i
|
86
|
-
@node.fmt.progress(n)
|
87
|
-
when :finish
|
88
|
-
@node.fmt.progress(100)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def download(options = {})
|
94
|
-
error "from is required" unless options[:from]
|
95
|
-
error "to is required" unless options[:to]
|
96
|
-
@node.fmt.download(options[:from], options[:to])
|
97
|
-
|
98
|
-
@node.sftp.download!(options[:from],
|
99
|
-
options[:to]) do |event, uploader, *args|
|
100
|
-
case event
|
101
|
-
when :get
|
102
|
-
size = 0
|
103
|
-
if args[0].size
|
104
|
-
size = args[0].size
|
105
|
-
else
|
106
|
-
size = @node.sftp.stat!(options[:from]).size
|
107
|
-
end
|
108
|
-
n = (args[1].to_f * 100 / size.to_f).to_i
|
109
|
-
@node.fmt.progress(n)
|
110
|
-
when :finish
|
111
|
-
@node.fmt.progress(100)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def compress(options = {})
|
117
|
-
error "from is required" unless options[:from]
|
118
|
-
error "to is required" unless options[:to]
|
119
|
-
|
120
|
-
options[:compressor] ||= "gz"
|
121
|
-
|
122
|
-
unless ["gz", "bzip2"].include?(options[:compressor])
|
123
|
-
error "invalid compressor"
|
124
|
-
end
|
125
|
-
|
126
|
-
options[:cmd] = "tar c"
|
127
|
-
|
128
|
-
if options[:compressor] == "gz"
|
129
|
-
options[:cmd] += "z"
|
130
|
-
elsif options[:compressor] == "bzip2"
|
131
|
-
options[:cmd] += "j"
|
132
|
-
end
|
133
|
-
|
134
|
-
from = options[:from].split("/")
|
135
|
-
from_name = from.pop
|
136
|
-
from_path = from.join("/")
|
137
|
-
|
138
|
-
options[:cmd] += "f #{options[:to]} #{from_name}"
|
139
|
-
options[:cwd] = from_path
|
140
|
-
@node.run(options)
|
141
|
-
end
|
142
|
-
|
143
|
-
def extract(options = {})
|
144
|
-
error "from is required" unless options[:from]
|
145
|
-
error "to is required" unless options[:to]
|
146
|
-
|
147
|
-
options[:compressor] ||= "gz"
|
148
|
-
|
149
|
-
unless ["gz", "bzip2"].include?(options[:compressor])
|
150
|
-
error "invalid compressor"
|
151
|
-
end
|
152
|
-
|
153
|
-
options[:cmd] = "tar x"
|
154
|
-
|
155
|
-
if options[:compressor] == "gz"
|
156
|
-
options[:cmd] += "z"
|
157
|
-
elsif options[:compressor] == "bzip2"
|
158
|
-
options[:cmd] += "j"
|
159
|
-
end
|
160
|
-
|
161
|
-
options[:cmd] += "f #{options[:from]} -C #{options[:to]}"
|
162
|
-
@node.run(options)
|
163
|
-
end
|
164
|
-
|
165
|
-
def link(options = {})
|
166
|
-
error "from is required" unless options[:from]
|
167
|
-
error "to is required" unless options[:to]
|
168
|
-
|
169
|
-
options[:cmd] = "ln -s #{options[:from]} #{options[:to]}"
|
170
|
-
@node.run(options)
|
171
|
-
end
|
172
|
-
|
173
|
-
def chown(options = {})
|
174
|
-
error "dir is required" unless options[:dir]
|
175
|
-
error "user is required" unless options[:user]
|
176
|
-
error "group is required" unless options[:group]
|
177
|
-
|
178
|
-
options[:cmd] = "chown -R #{options[:user]}:#{options[:group]} "
|
179
|
-
options[:cmd] += "#{options[:dir]}"
|
180
|
-
|
181
|
-
@node.run(options)
|
182
|
-
end
|
183
|
-
|
184
|
-
def touch(options = {})
|
185
|
-
error "file is required" unless options[:file]
|
186
|
-
|
187
|
-
options[:cmd] = "touch #{options[:file]}"
|
188
|
-
@node.run(options)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
data/vendor/lib/core/osx/git.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Core
|
2
|
-
module Osx
|
3
|
-
class Rails < Mybot::Lib
|
4
|
-
def initialize(node)
|
5
|
-
@node = node
|
6
|
-
@node.use [
|
7
|
-
"core/fs",
|
8
|
-
"core/osx/git"
|
9
|
-
]
|
10
|
-
end
|
11
|
-
|
12
|
-
def prepare_release(options = {})
|
13
|
-
error "repo is required" unless options[:repo]
|
14
|
-
error "release is required" unless options[:release]
|
15
|
-
|
16
|
-
options[:dir] = "/tmp/#{options[:release]}"
|
17
|
-
@node.fs.remove(options)
|
18
|
-
|
19
|
-
options[:file] = "/tmp/#{options[:release]}.tar.gz"
|
20
|
-
@node.fs.remove(options)
|
21
|
-
|
22
|
-
options[:dest] = "/tmp/#{options[:release]}"
|
23
|
-
@node.git.clone(options)
|
24
|
-
|
25
|
-
options[:from] = "/tmp/#{options[:release]}"
|
26
|
-
options[:to] = "/tmp/#{options[:release]}.tar.gz"
|
27
|
-
@node.fs.compress(options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Core
|
2
|
-
module Osx
|
3
|
-
class Static < Mybot::Lib
|
4
|
-
def initialize(node)
|
5
|
-
@node = node
|
6
|
-
@node.use [
|
7
|
-
"core/fs",
|
8
|
-
"core/osx/git"
|
9
|
-
]
|
10
|
-
end
|
11
|
-
|
12
|
-
def prepare_release(options = {})
|
13
|
-
error "repo is required" unless options[:repo]
|
14
|
-
error "release is required" unless options[:release]
|
15
|
-
|
16
|
-
options[:dir] = "/tmp/#{options[:release]}"
|
17
|
-
@node.fs.remove(options)
|
18
|
-
|
19
|
-
options[:file] = "/tmp/#{options[:release]}.tar.gz"
|
20
|
-
@node.fs.remove(options)
|
21
|
-
|
22
|
-
options[:dest] = "/tmp/#{options[:release]}"
|
23
|
-
@node.git.clone(options)
|
24
|
-
|
25
|
-
options[:from] = "/tmp/#{options[:release]}"
|
26
|
-
options[:to] = "/tmp/#{options[:release]}.tar.gz"
|
27
|
-
@node.fs.compress(options)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
|
@@ -1,57 +0,0 @@
|
|
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) do |cmd|
|
13
|
-
cmd.on "dpkg was interrupted" do
|
14
|
-
dpkg_reconfigure(options)
|
15
|
-
end
|
16
|
-
|
17
|
-
cmd.on "Could not get lock" do
|
18
|
-
error "Cannot update"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def upgrade(options = {})
|
24
|
-
options[:cmd] = "#{DF} apt-get upgrade -y"
|
25
|
-
@node.run(options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def dist_upgrade(options = {})
|
29
|
-
options[:cmd] = "#{DF} apt-get dist-upgrade -y"
|
30
|
-
@node.run(options)
|
31
|
-
end
|
32
|
-
|
33
|
-
def install(options = {})
|
34
|
-
error "pkg not specified" unless options[:pkg]
|
35
|
-
|
36
|
-
options[:cmd] = "#{DF} apt-get install -y #{options[:pkg]}"
|
37
|
-
@node.run(options) do |cmd|
|
38
|
-
cmd.on "dpkg was interrupted" do
|
39
|
-
dpkg_reconfigure(options)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def remove(options = {})
|
45
|
-
error "pkg not specified" unless options[:pkg]
|
46
|
-
|
47
|
-
options[:cmd] = "#{DF} apt-get --purge autoremove -y #{options[:pkg]}"
|
48
|
-
@node.run(options)
|
49
|
-
end
|
50
|
-
|
51
|
-
def dpkg_reconfigure(options = {})
|
52
|
-
options[:cmd] = "#{DF} dpkg --configure -a"
|
53
|
-
@node.run(options)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,48 +0,0 @@
|
|
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
|
-
|
35
|
-
def init(options = {})
|
36
|
-
error "repo not specified" unless options[:repo]
|
37
|
-
|
38
|
-
options[:cmd] = "git init #{options[:repo]}"
|
39
|
-
|
40
|
-
if options[:bare]
|
41
|
-
options[:cmd] += " --bare"
|
42
|
-
end
|
43
|
-
|
44
|
-
@node.run(options)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|