kanrisuru 0.2.2 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc638e7e85cf76460cffecc7bcd885a7cc3f30c098c1d2fa0250daeb455e87a2
4
- data.tar.gz: 78d733e6299f3a49ce40a0be6bb73b50a8c6b9f184ceacf920bc55661653c393
3
+ metadata.gz: 8442dfb50e30ac79aacd58ed1dd80ac17858571c3d84790eed8d8efcad7e6f29
4
+ data.tar.gz: bab46330d7f3aca3dee667501d2a59a001f813665a071be8362b8a9a6b9e2a18
5
5
  SHA512:
6
- metadata.gz: 2706ac5496f456560795adedbe445ecfa1509e7d3d60dde5b5d4e85a59687b1477fdf035aeba0b31a5ade24cc25c962a8cbb559a75ba5899eaf90e4f02ada212
7
- data.tar.gz: 606de07f8ddd04465df2bc0f4bd3ffbfb1e362986613a31f2184076337ba9542ea05ac1874d36c24442d1609f176dfa1bd2cf8104835fa1233d9e4c68cd7f7a4
6
+ metadata.gz: 852303708004d232098e85ad7ea762caa69bb65b450d4b9cda0eb208c573e85d47f46981a3a281de35cbd84830ca9a52f71126486848962ad980acbb6940d48b
7
+ data.tar.gz: a9c234d9e6c112ce682fb444b3c77eaa76619fbc46b3d64ab86914beebead28268e460fb5305a5642c9f662c318d22836e8b2b1b7c11891b531b9615c5f2a5e4
data/README.md CHANGED
@@ -146,6 +146,9 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
146
146
  | Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
147
147
  | Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
148
148
  | Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
149
+ | **Packages** | | | | | | | | | | | |
150
+ | Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
151
+ | Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
149
152
 
150
153
  ## Development
151
154
 
data/kanrisuru.gemspec CHANGED
@@ -8,20 +8,20 @@ Gem::Specification.new do |gem|
8
8
  gem.author = 'Ryan Mammina'
9
9
  gem.email = 'ryan@avamia.com'
10
10
  gem.license = 'MIT'
11
- gem.summary = 'Manage remote servers with ruby.'
11
+ gem.summary = 'Manage remote servers over ssh with ruby.'
12
12
  gem.homepage = 'https://github.com/avamia/kanrisuru'
13
13
 
14
14
  gem.required_ruby_version = '>= 2.5.0'
15
15
  gem.required_rubygems_version = '>= 1.8.11'
16
16
 
17
- gem.add_development_dependency 'rspec'
18
- gem.add_development_dependency 'rubocop'
19
- gem.add_development_dependency 'rubocop-rspec'
20
- gem.add_development_dependency 'simplecov'
17
+ gem.add_development_dependency 'rspec', '>= 3.10.0'
18
+ gem.add_development_dependency 'rubocop', '>= 1.12.1'
19
+ gem.add_development_dependency 'rubocop-rspec', '>= 2.2.0'
20
+ gem.add_development_dependency 'simplecov', '>= 0.21.2'
21
21
 
22
- gem.add_runtime_dependency 'net-ping'
23
- gem.add_runtime_dependency 'net-scp'
24
- gem.add_runtime_dependency 'net-ssh'
22
+ gem.add_runtime_dependency 'net-ping', '>= 2.0.8'
23
+ gem.add_runtime_dependency 'net-scp', '>= 3.0.0'
24
+ gem.add_runtime_dependency 'net-ssh', '>= 6.1.0'
25
25
 
26
26
  gem.files = `git ls-files`.split("\n")
27
27
  gem.require_paths = ['lib']
@@ -14,6 +14,9 @@ require_relative 'core/stream'
14
14
  require_relative 'core/transfer'
15
15
  require_relative 'core/ip'
16
16
  require_relative 'core/socket'
17
+ require_relative 'core/apt'
18
+ require_relative 'core/yum'
19
+ require_relative 'core/zypper'
17
20
 
18
21
  module Kanrisuru
19
22
  module Remote
@@ -32,6 +35,9 @@ module Kanrisuru
32
35
  os_include Kanrisuru::Core::Transfer
33
36
  os_include Kanrisuru::Core::IP
34
37
  os_include Kanrisuru::Core::Socket
38
+ os_include Kanrisuru::Core::Apt
39
+ os_include Kanrisuru::Core::Yum
40
+ os_include Kanrisuru::Core::Zypper
35
41
  end
36
42
 
37
43
  class Cluster
@@ -48,6 +54,9 @@ module Kanrisuru
48
54
  os_collection Kanrisuru::Core::Transfer
49
55
  os_collection Kanrisuru::Core::IP
50
56
  os_collection Kanrisuru::Core::Socket
57
+ os_collection Kanrisuru::Core::Apt
58
+ os_collection Kanrisuru::Core::Yum
59
+ os_collection Kanrisuru::Core::Zypper
51
60
  end
52
61
  end
53
62
  end
@@ -0,0 +1,324 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module Apt
6
+ extend OsPackage::Define
7
+
8
+ os_define :debian, :apt
9
+
10
+ AptSource = Struct.new(:url, :dist, :architecture)
11
+ AptPackageOverview = Struct.new(:package, :version, :suites, :architecture, :installed, :upgradeable, :automatic)
12
+ AptPackageDetail = Struct.new(
13
+ :package,
14
+ :version,
15
+ :priority,
16
+ :section,
17
+ :origin,
18
+ :maintainer,
19
+ :original_maintainer,
20
+ :bugs,
21
+ :install_size,
22
+ :dependencies,
23
+ :recommends,
24
+ :provides,
25
+ :suggests,
26
+ :breaks,
27
+ :conflicts,
28
+ :replaces,
29
+ :homepage,
30
+ :task,
31
+ :supported,
32
+ :download_size,
33
+ :apt_manual_installed,
34
+ :apt_sources,
35
+ :description,
36
+ :summary
37
+ )
38
+
39
+ def apt(action, opts = {})
40
+ case action
41
+ when 'list'
42
+ apt_list(opts)
43
+ when 'update'
44
+ apt_update(opts)
45
+ when 'upgrade'
46
+ apt_upgrade(opts)
47
+ when 'full-upgrade', 'full_upgrade'
48
+ apt_full_upgrade(opts)
49
+ when 'install'
50
+ apt_install(opts)
51
+ when 'remove'
52
+ apt_remove(opts)
53
+ when 'purge'
54
+ apt_purge(opts)
55
+ when 'autoremove'
56
+ apt_autoremove(opts)
57
+ when 'search'
58
+ apt_search(opts)
59
+ when 'show'
60
+ apt_show(opts)
61
+ when 'clean'
62
+ apt_clean(opts)
63
+ when 'autoclean'
64
+ apt_autoclean(opts)
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def apt_autoclean(_opts)
71
+ command = Kanrisuru::Command.new('apt-get autoclean')
72
+ execute_shell(command)
73
+ Kanrisuru::Result.new(command)
74
+ end
75
+
76
+ def apt_clean(_opts)
77
+ command = Kanrisuru::Command.new('apt-get clean')
78
+ execute_shell(command)
79
+ Kanrisuru::Result.new(command)
80
+ end
81
+
82
+ def apt_search(opts)
83
+ command = Kanrisuru::Command.new('apt search')
84
+ command << opts[:query]
85
+
86
+ execute_shell(command)
87
+
88
+ Kanrisuru::Result.new(command) do |cmd|
89
+ lines = cmd.to_a
90
+ lines.shift
91
+ lines.shift
92
+
93
+ result = []
94
+
95
+ lines.each do |line|
96
+ next unless line.include?('/')
97
+
98
+ item = parse_apt_line(line)
99
+ next unless item
100
+
101
+ result << item
102
+ end
103
+
104
+ result
105
+ end
106
+ end
107
+
108
+ def apt_list(opts)
109
+ command = Kanrisuru::Command.new('apt list')
110
+ command.append_flag('--installed', opts[:installed])
111
+ command.append_flag('--upgradeable', opts[:upgradeable])
112
+ command.append_flag('--all-versions', opts[:all_versions])
113
+ command.append_arg('-a', opts[:package_name])
114
+
115
+ execute_shell(command)
116
+
117
+ Kanrisuru::Result.new(command) do |cmd|
118
+ lines = cmd.to_a
119
+ lines.shift
120
+
121
+ result = []
122
+ lines.each do |line|
123
+ item = parse_apt_line(line)
124
+ next unless item
125
+
126
+ result << item
127
+ end
128
+
129
+ result
130
+ end
131
+ end
132
+
133
+ def apt_autoremove(_opts)
134
+ command = Kanrisuru::Command.new('apt-get autoremove')
135
+ command.append_flag('-y')
136
+
137
+ execute_shell(command)
138
+ Kanrisuru::Result.new(command)
139
+ end
140
+
141
+ def apt_purge(opts)
142
+ command = Kanrisuru::Command.new('apt-get purge')
143
+ command.append_flag('-y')
144
+
145
+ packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
146
+ command << packages
147
+
148
+ execute_shell(command)
149
+ Kanrisuru::Result.new(command)
150
+ end
151
+
152
+ def apt_remove(opts)
153
+ command = Kanrisuru::Command.new('apt-get remove')
154
+ command.append_flag('-y')
155
+
156
+ packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
157
+ command << packages
158
+
159
+ execute_shell(command)
160
+ Kanrisuru::Result.new(command)
161
+ end
162
+
163
+ def apt_install(opts)
164
+ command = Kanrisuru::Command.new('apt-get install')
165
+ command.append_flag('-y')
166
+
167
+ command.append_flag('--no-upgrade', opts[:no_upgrade])
168
+ command.append_flag('--only-upgrade', opts[:only_upgrade])
169
+ command.append_flag('--reinstall', opts[:reinstall])
170
+
171
+ packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
172
+ command << packages
173
+
174
+ execute_shell(command)
175
+ Kanrisuru::Result.new(command)
176
+ end
177
+
178
+ def apt_full_upgrade(_opts)
179
+ command = Kanrisuru::Command.new('apt full-upgrade')
180
+ command.append_flag('-y')
181
+ execute_shell(command)
182
+ Kanrisuru::Result.new(command)
183
+ end
184
+
185
+ def apt_upgrade(_opts)
186
+ command = Kanrisuru::Command.new('apt-get upgrade')
187
+ command.append_flag('-y')
188
+ execute_shell(command)
189
+ Kanrisuru::Result.new(command)
190
+ end
191
+
192
+ def apt_update(_opts)
193
+ command = Kanrisuru::Command.new('apt-get update')
194
+ command.append_flag('-y')
195
+ execute_shell(command)
196
+ Kanrisuru::Result.new(command)
197
+ end
198
+
199
+ def apt_show(opts)
200
+ command = Kanrisuru::Command.new('apt show')
201
+ command.append_flag('-a')
202
+
203
+ packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
204
+ command << packages
205
+
206
+ execute_shell(command)
207
+
208
+ Kanrisuru::Result.new(command) do |cmd|
209
+ lines = cmd.to_a
210
+ rows = []
211
+
212
+ current_row = nil
213
+ description = ''
214
+
215
+ lines.each do |line|
216
+ next if line == 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
217
+ next if ['', nil, '.'].include?(line)
218
+
219
+ case line
220
+ when /^Package:/
221
+ unless current_row.nil?
222
+ current_row.description = description.strip
223
+ description = ''
224
+ rows << current_row
225
+ end
226
+
227
+ current_row = AptPackageDetail.new
228
+ current_row.package = extract_single_line(line)
229
+ when /^Version:/
230
+ current_row.version = extract_single_line(line)
231
+ when /^Priority:/
232
+ current_row.priority = extract_single_line(line)
233
+ when /^Section:/
234
+ current_row.section = extract_single_line(line)
235
+ when /^Origin:/
236
+ current_row.origin = extract_single_line(line)
237
+ when /^Maintainer:/
238
+ current_row.maintainer = extract_single_line(line)
239
+ when /^Original-Maintainer:/
240
+ current_row.original_maintainer = extract_single_line(line)
241
+ when /^Bugs:/
242
+ current_row.bugs = extract_single_line(line)
243
+ when /^Installed-Size:/
244
+ size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
245
+ current_row.install_size = size
246
+ when /^Download-Size:/
247
+ size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
248
+ current_row.download_size = size
249
+ when /^Depends:/
250
+ current_row.dependencies = parse_comma_values(extract_single_line(line))
251
+ when /^Provides:/
252
+ current_row.provides = parse_comma_values(extract_single_line(line))
253
+ when /^Recommends:/
254
+ current_row.recommends = parse_comma_values(extract_single_line(line))
255
+ when /^Suggests:/
256
+ current_row.suggests = parse_comma_values(extract_single_line(line))
257
+ when /^Breaks:/
258
+ current_row.breaks = parse_comma_values(extract_single_line(line))
259
+ when /^Conflicts:/
260
+ current_row.conflicts = parse_comma_values(extract_single_line(line))
261
+ when /^Replaces:/
262
+ current_row.replaces = parse_comma_values(extract_single_line(line))
263
+ when /^Homepage:/
264
+ current_row.homepage = extract_single_line(line)
265
+ when /^Task:/
266
+ current_row.task = parse_comma_values(extract_single_line(line))
267
+ when /^Supported:/
268
+ current_row.supported = extract_single_line(line)
269
+ when /^APT-Sources:/
270
+ current_row.apt_sources = parse_apt_sources(extract_single_line(line))
271
+ when /^APT-Manual-Installed:/
272
+ current_row.apt_manual_installed = extract_single_line(line) == 'yes'
273
+ when /^Description:/
274
+ current_row.summary = extract_single_line(line)
275
+ else
276
+ description += " #{line.strip}"
277
+ end
278
+ end
279
+
280
+ current_row.description = description.strip
281
+ rows << current_row
282
+ rows
283
+ end
284
+ end
285
+
286
+ def extract_single_line(line)
287
+ line.split(': ')[1]
288
+ end
289
+
290
+ def parse_comma_values(string)
291
+ string.split(', ')
292
+ end
293
+
294
+ def parse_apt_sources(string)
295
+ url, dist, architecture, = string.split
296
+ AptSource.new(url, dist, architecture)
297
+ end
298
+
299
+ def parse_apt_line(line)
300
+ values = line.split('/')
301
+ return if values.length < 2
302
+
303
+ package = values[0]
304
+
305
+ values = values[1].split
306
+ suites = values[0].split(',')
307
+ version = values[1]
308
+ architecture = values[2]
309
+
310
+ installed = false
311
+ upgradeable = false
312
+ automatic = false
313
+
314
+ if values.length > 3
315
+ installed = values[3].include?('installed')
316
+ upgradeable = values[3].include?('upgradeable')
317
+ automatic = values[3].include?('automatic')
318
+ end
319
+
320
+ AptPackageOverview.new(package, version, suites, architecture, installed, upgradeable, automatic)
321
+ end
322
+ end
323
+ end
324
+ end
@@ -233,7 +233,7 @@ module Kanrisuru
233
233
  end
234
234
 
235
235
  def touch(paths, opts = {})
236
- date = opts[:date]
236
+ date = opts[:date]
237
237
 
238
238
  paths = [paths] if paths.instance_of?(String)
239
239
  command = Kanrisuru::Command.new("touch #{paths.join(' ')}")
@@ -211,7 +211,7 @@ module Kanrisuru
211
211
 
212
212
  command.append_arg('dev', opts[:dev])
213
213
  command.append_arg('scope', opts[:scope])
214
- comamnd.append_arg('to', opts[:prefix])
214
+ command.append_arg('to', opts[:prefix])
215
215
  command.append_arg('label', opts[:label])
216
216
 
217
217
  command.append_flag('dynamic', opts[:dynamic])
@@ -415,14 +415,14 @@ module Kanrisuru
415
415
 
416
416
  command.append_arg('type', opts[:type])
417
417
  command.append_arg('from', opts[:from])
418
- comamnd.append_arg('to', opts[:to])
418
+ command.append_arg('to', opts[:to])
419
419
  command.append_arg('iif', opts[:iif])
420
- comamnd.append_arg('tos', opts[:tos])
420
+ command.append_arg('tos', opts[:tos])
421
421
  command.append_arg('dsfield', opts[:dsfield])
422
- comamnd.append_arg('fwmark', opts[:fwmark])
423
- comamnd.append_arg('priority', opts[:priority])
424
- comamnd.append_arg('table', opts[:table])
425
- comamnd.append_arg('realms', opts[:realms])
422
+ command.append_arg('fwmark', opts[:fwmark])
423
+ command.append_arg('priority', opts[:priority])
424
+ command.append_arg('table', opts[:table])
425
+ command.append_arg('realms', opts[:realms])
426
426
  command.append_arg('nat', opts[:nat])
427
427
  end
428
428
 
@@ -44,7 +44,6 @@ module Kanrisuru
44
44
  date = DateTime.parse("#{values[6]} #{values[7]} #{values[8]}")
45
45
 
46
46
  type = values[1].include?('d') ? 'directory' : 'file'
47
-
48
47
  items <<
49
48
  if id
50
49
  FileInfoId.new(