kanrisuru 0.3.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/lib/kanrisuru/command.rb +8 -3
- data/lib/kanrisuru/core.rb +6 -0
- data/lib/kanrisuru/core/apt.rb +6 -6
- data/lib/kanrisuru/core/dmi.rb +533 -0
- data/lib/kanrisuru/core/path.rb +0 -1
- data/lib/kanrisuru/core/socket.rb +16 -16
- data/lib/kanrisuru/core/system.rb +80 -0
- data/lib/kanrisuru/core/yum.rb +8 -8
- data/lib/kanrisuru/core/zypper.rb +1094 -0
- data/lib/kanrisuru/remote/cpu.rb +4 -0
- data/lib/kanrisuru/remote/fstab.rb +3 -3
- data/lib/kanrisuru/remote/host.rb +2 -2
- data/lib/kanrisuru/util.rb +1 -0
- data/lib/kanrisuru/util/bits.rb +3 -3
- data/lib/kanrisuru/util/dmi_type.rb +1366 -0
- data/lib/kanrisuru/util/os_family.rb +1 -1
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/apt_spec.rb +97 -158
- data/spec/functional/core/dmi_spec.rb +37 -0
- data/spec/functional/core/file_spec.rb +5 -12
- data/spec/functional/core/system_spec.rb +21 -0
- data/spec/functional/core/yum_spec.rb +38 -80
- data/spec/functional/core/zypper_spec.rb +193 -0
- data/spec/functional/remote/fstab_spec.rb +1 -1
- data/spec/functional/remote/os_spec.rb +1 -1
- data/spec/helper/test_hosts.rb +7 -1
- data/spec/unit/core/apt_spec.rb +42 -0
- data/spec/unit/core/archive_spec.rb +11 -0
- data/spec/unit/core/disk_spec.rb +21 -0
- data/spec/unit/core/dmi_spec.rb +271 -0
- data/spec/unit/core/file_spec.rb +9 -0
- data/spec/unit/core/find_spec.rb +9 -0
- data/spec/unit/core/group_spec.rb +10 -0
- data/spec/unit/core/ip_spec.rb +59 -0
- data/spec/unit/core/path_spec.rb +16 -0
- data/spec/unit/core/socket_spec.rb +38 -0
- data/spec/unit/core/stat_spec.rb +14 -0
- data/spec/unit/core/system_spec.rb +79 -0
- data/spec/unit/core/transfer_spec.rb +15 -0
- data/spec/unit/core/user_spec.rb +11 -0
- data/spec/unit/core/yum_spec.rb +47 -0
- data/spec/unit/core/zypper_spec.rb +121 -0
- data/spec/unit/util_spec.rb +224 -0
- metadata +23 -2
data/lib/kanrisuru/core/path.rb
CHANGED
@@ -9,13 +9,13 @@ module Kanrisuru
|
|
9
9
|
|
10
10
|
os_define :linux, :ss
|
11
11
|
|
12
|
-
|
12
|
+
Statistics = Struct.new(
|
13
13
|
:netid, :state, :receive_queue, :send_queue,
|
14
14
|
:local_address, :local_port, :peer_address, :peer_port,
|
15
15
|
:memory
|
16
16
|
)
|
17
17
|
|
18
|
-
|
18
|
+
StatisticsMemory = Struct.new(
|
19
19
|
:rmem_alloc, :rcv_buf, :wmem_alloc, :snd_buf,
|
20
20
|
:fwd_alloc, :wmem_queued, :ropt_mem, :back_log, :sock_drop
|
21
21
|
)
|
@@ -81,19 +81,19 @@ module Kanrisuru
|
|
81
81
|
values = line.split
|
82
82
|
next if values.length < 5
|
83
83
|
|
84
|
-
socket_stats =
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
84
|
+
socket_stats = Statistics.new
|
85
|
+
socket_stats.netid =
|
86
|
+
if headers.include?('Netid')
|
87
|
+
values.shift
|
88
|
+
elsif opts[:tcp]
|
89
|
+
'tcp'
|
90
|
+
elsif opts[:udp]
|
91
|
+
'udp'
|
92
|
+
elsif opts[:raw]
|
93
|
+
'raw'
|
94
|
+
else
|
95
|
+
''
|
96
|
+
end
|
97
97
|
|
98
98
|
socket_stats.state = if headers.include?('State')
|
99
99
|
TCP_STATE_ABBR[values.shift]
|
@@ -130,7 +130,7 @@ module Kanrisuru
|
|
130
130
|
_, string = string.split(/skmem:\((\S+)\)/)
|
131
131
|
values = string.split(',')
|
132
132
|
|
133
|
-
memory =
|
133
|
+
memory = StatisticsMemory.new
|
134
134
|
memory.rmem_alloc = values[0].split(/(\d+)/)[1].to_i
|
135
135
|
memory.rcv_buf = values[1].split(/(\d+)/)[1].to_i
|
136
136
|
memory.wmem_alloc = values[2].split(/(\d+)/)[1].to_i
|
@@ -15,6 +15,8 @@ module Kanrisuru
|
|
15
15
|
os_define :linux, :ps
|
16
16
|
os_define :linux, :kill
|
17
17
|
|
18
|
+
os_define :linux, :kernel_statistics
|
19
|
+
|
18
20
|
os_define :linux, :uptime
|
19
21
|
|
20
22
|
os_define :linux, :w
|
@@ -60,6 +62,33 @@ module Kanrisuru
|
|
60
62
|
:flags
|
61
63
|
)
|
62
64
|
|
65
|
+
KernelStatisticCpu = Struct.new(
|
66
|
+
:user,
|
67
|
+
:nice,
|
68
|
+
:system,
|
69
|
+
:idle,
|
70
|
+
:iowait,
|
71
|
+
:irq,
|
72
|
+
:softirq,
|
73
|
+
:steal,
|
74
|
+
:guest,
|
75
|
+
:guest_nice
|
76
|
+
)
|
77
|
+
|
78
|
+
KernelStatistic = Struct.new(
|
79
|
+
:cpu_total,
|
80
|
+
:cpus,
|
81
|
+
:interrupt_total,
|
82
|
+
:interrupts,
|
83
|
+
:ctxt,
|
84
|
+
:btime,
|
85
|
+
:processes,
|
86
|
+
:procs_running,
|
87
|
+
:procs_blocked,
|
88
|
+
:softirq_total,
|
89
|
+
:softirqs
|
90
|
+
)
|
91
|
+
|
63
92
|
ProcessInfo = Struct.new(
|
64
93
|
:uid, :user, :gid, :group, :ppid, :pid,
|
65
94
|
:cpu_usage, :memory_usage, :stat, :priority,
|
@@ -272,6 +301,57 @@ module Kanrisuru
|
|
272
301
|
Kanrisuru::Result.new(command)
|
273
302
|
end
|
274
303
|
|
304
|
+
def kernel_statistics
|
305
|
+
command = Kanrisuru::Command.new('cat /proc/stat')
|
306
|
+
|
307
|
+
execute_shell(command)
|
308
|
+
|
309
|
+
Kanrisuru::Result.new(command) do |cmd|
|
310
|
+
lines = cmd.to_a
|
311
|
+
|
312
|
+
result = KernelStatistic.new
|
313
|
+
result.cpus = []
|
314
|
+
|
315
|
+
lines.each do |line|
|
316
|
+
values = line.split
|
317
|
+
field = values[0]
|
318
|
+
values = values[1..-1].map(&:to_i)
|
319
|
+
|
320
|
+
case field
|
321
|
+
when /^cpu/
|
322
|
+
cpu_stat = KernelStatisticCpu.new
|
323
|
+
cpu_stat.user = values[0]
|
324
|
+
cpu_stat.nice = values[1]
|
325
|
+
cpu_stat.system = values[2]
|
326
|
+
cpu_stat.idle = values[3]
|
327
|
+
cpu_stat.iowait = values[4]
|
328
|
+
cpu_stat.irq = values[5]
|
329
|
+
cpu_stat.softirq = values[6]
|
330
|
+
cpu_stat.steal = values[7]
|
331
|
+
cpu_stat.guest = values[8]
|
332
|
+
cpu_stat.guest_nice = values[9]
|
333
|
+
|
334
|
+
case field
|
335
|
+
when /^cpu$/
|
336
|
+
result.cpu_total = cpu_stat
|
337
|
+
when /^cpu\d+/
|
338
|
+
result.cpus << cpu_stat
|
339
|
+
end
|
340
|
+
when 'intr'
|
341
|
+
result.interrupt_total = values[0]
|
342
|
+
result.interrupts = values[1..-1]
|
343
|
+
when 'softirq'
|
344
|
+
result.softirq_total = values[0]
|
345
|
+
result.softirqs = values[1..-1]
|
346
|
+
else
|
347
|
+
result[field] = values[0]
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
result
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
275
355
|
def uptime
|
276
356
|
## Ported from https://github.com/djberg96/sys-uptime
|
277
357
|
command = Kanrisuru::Command.new('cat /proc/uptime')
|
data/lib/kanrisuru/core/yum.rb
CHANGED
@@ -9,9 +9,9 @@ module Kanrisuru
|
|
9
9
|
|
10
10
|
os_define :fedora, :yum
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
PackageOverview = Struct.new(:package, :architecture, :version, :installed)
|
13
|
+
PackageSearchResult = Struct.new(:package, :architecture, :summary)
|
14
|
+
PackageDetail = Struct.new(
|
15
15
|
:package,
|
16
16
|
:version,
|
17
17
|
:release,
|
@@ -26,7 +26,7 @@ module Kanrisuru
|
|
26
26
|
:description
|
27
27
|
)
|
28
28
|
|
29
|
-
|
29
|
+
Repolist = Struct.new(
|
30
30
|
:id,
|
31
31
|
:name,
|
32
32
|
:status,
|
@@ -217,7 +217,7 @@ module Kanrisuru
|
|
217
217
|
name, architecture = full_name.split('.')
|
218
218
|
summary = values[1]
|
219
219
|
|
220
|
-
result <<
|
220
|
+
result << PackageSearchResult.new(name, architecture, summary)
|
221
221
|
end
|
222
222
|
|
223
223
|
result
|
@@ -246,7 +246,7 @@ module Kanrisuru
|
|
246
246
|
current_row = nil
|
247
247
|
end
|
248
248
|
|
249
|
-
current_row =
|
249
|
+
current_row = Repolist.new
|
250
250
|
current_row.id = extract_single_yum_line(line)
|
251
251
|
when /^Repo-name/
|
252
252
|
current_row.name = extract_single_yum_line(line)
|
@@ -309,7 +309,7 @@ module Kanrisuru
|
|
309
309
|
rows << current_row
|
310
310
|
end
|
311
311
|
|
312
|
-
current_row =
|
312
|
+
current_row = PackageDetail.new
|
313
313
|
current_row.package = extract_single_yum_line(line)
|
314
314
|
when /^Arch/, /^Architecture/
|
315
315
|
current_row.architecture = extract_single_yum_line(line)
|
@@ -365,7 +365,7 @@ module Kanrisuru
|
|
365
365
|
|
366
366
|
name, architecture = full_name.split('.')
|
367
367
|
|
368
|
-
|
368
|
+
PackageOverview.new(name, architecture, version)
|
369
369
|
end
|
370
370
|
|
371
371
|
## Bug reported on the output of the yum command
|
@@ -0,0 +1,1094 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module Kanrisuru
|
6
|
+
module Core
|
7
|
+
module Zypper
|
8
|
+
extend OsPackage::Define
|
9
|
+
|
10
|
+
os_define :sles, :zypper
|
11
|
+
|
12
|
+
PACKAGE_TYPES = %w[package patch pattern product srcpackage application].freeze
|
13
|
+
PATCH_CATEGORIES = %w[security recommended optional feature document yast].freeze
|
14
|
+
PATCH_SEVERITIES = %w[critical important moderate low unspecified].freeze
|
15
|
+
SOLVER_FOCUS_MODES = %w[job installed update].freeze
|
16
|
+
MEDIUM_TYPES = %w[dir file cd dvd nfs iso http https ftp cifs smb hd].freeze
|
17
|
+
|
18
|
+
EXIT_INF_UPDATE_NEEDED = 100
|
19
|
+
EXIT_INF_SEC_UPDATE_NEEDED = 101
|
20
|
+
EXIT_INF_REBOOT_NEEDED = 102
|
21
|
+
EXIT_INF_RESTART_NEEDED = 103
|
22
|
+
EXIT_INF_CAP_NOT_FOUND = 104
|
23
|
+
|
24
|
+
Repo = Struct.new(
|
25
|
+
:number,
|
26
|
+
:alias,
|
27
|
+
:name,
|
28
|
+
:enabled,
|
29
|
+
:gpg_check,
|
30
|
+
:refresh,
|
31
|
+
:priority,
|
32
|
+
:type,
|
33
|
+
:uri,
|
34
|
+
:service
|
35
|
+
)
|
36
|
+
|
37
|
+
Service = Struct.new(
|
38
|
+
:number,
|
39
|
+
:alias,
|
40
|
+
:name,
|
41
|
+
:enabled,
|
42
|
+
:gpg_check,
|
43
|
+
:refresh,
|
44
|
+
:priority,
|
45
|
+
:type,
|
46
|
+
:uri
|
47
|
+
)
|
48
|
+
|
49
|
+
SearchResult = Struct.new(
|
50
|
+
:repository,
|
51
|
+
:package,
|
52
|
+
:status,
|
53
|
+
:type,
|
54
|
+
:version,
|
55
|
+
:architecture
|
56
|
+
)
|
57
|
+
|
58
|
+
PackageDetail = Struct.new(
|
59
|
+
:repository,
|
60
|
+
:package,
|
61
|
+
:version,
|
62
|
+
:architecture,
|
63
|
+
:vendor,
|
64
|
+
:support_level,
|
65
|
+
:install_size,
|
66
|
+
:installed,
|
67
|
+
:status,
|
68
|
+
:source_package,
|
69
|
+
:summary,
|
70
|
+
:description
|
71
|
+
)
|
72
|
+
|
73
|
+
PackageUpdate = Struct.new(
|
74
|
+
:repository,
|
75
|
+
:package,
|
76
|
+
:current_version,
|
77
|
+
:available_version,
|
78
|
+
:architecture
|
79
|
+
)
|
80
|
+
|
81
|
+
PatchUpdate = Struct.new(
|
82
|
+
:repository,
|
83
|
+
:patch,
|
84
|
+
:category,
|
85
|
+
:severity,
|
86
|
+
:interactive,
|
87
|
+
:status,
|
88
|
+
:summary
|
89
|
+
)
|
90
|
+
|
91
|
+
PatchCount = Struct.new(
|
92
|
+
:category,
|
93
|
+
:updatestack,
|
94
|
+
:patches
|
95
|
+
)
|
96
|
+
|
97
|
+
Lock = Struct.new(
|
98
|
+
:number,
|
99
|
+
:name,
|
100
|
+
:matches,
|
101
|
+
:type,
|
102
|
+
:repository
|
103
|
+
)
|
104
|
+
|
105
|
+
def zypper(action, opts = {})
|
106
|
+
case action
|
107
|
+
when 'repos', 'lr'
|
108
|
+
zypper_list_repos(opts)
|
109
|
+
when 'refresh', 'ref'
|
110
|
+
zypper_refresh_repos(opts)
|
111
|
+
when 'modifyrepo', 'mr'
|
112
|
+
zypper_modify_repo(opts)
|
113
|
+
when 'addrepo', 'ar'
|
114
|
+
zypper_add_repo(opts)
|
115
|
+
when 'removerepo', 'rr'
|
116
|
+
zypper_remove_repo(opts)
|
117
|
+
when 'renamerepo', 'nr'
|
118
|
+
zypper_rename_repo(opts)
|
119
|
+
|
120
|
+
when 'addservice', 'as'
|
121
|
+
zypper_add_service(opts)
|
122
|
+
when 'removeservice', 'rs'
|
123
|
+
zypper_remove_service(opts)
|
124
|
+
when 'modifyservice', 'ms'
|
125
|
+
zypper_modify_service(opts)
|
126
|
+
when 'services', 'ls'
|
127
|
+
zypper_list_services(opts)
|
128
|
+
when 'refresh-services', 'refs'
|
129
|
+
zypper_refresh_services(opts)
|
130
|
+
|
131
|
+
when 'addlock', 'al'
|
132
|
+
zypper_add_lock(opts)
|
133
|
+
when 'locks', 'll'
|
134
|
+
zypper_list_locks(opts)
|
135
|
+
when 'removelock', 'rl'
|
136
|
+
zypper_remove_lock(opts)
|
137
|
+
when 'cleanlocks', 'cl'
|
138
|
+
zypper_clean_locks(opts)
|
139
|
+
|
140
|
+
when 'info', 'if'
|
141
|
+
zypper_info(opts)
|
142
|
+
when 'install', 'in'
|
143
|
+
zypper_install(opts)
|
144
|
+
when 'source-install', 'si'
|
145
|
+
zypper_source_install(opts)
|
146
|
+
when 'verify', 've'
|
147
|
+
zypper_verify(opts)
|
148
|
+
when 'install-new-recommends', 'inr'
|
149
|
+
zypper_install_new_recommends(opts)
|
150
|
+
when 'remove', 'rm'
|
151
|
+
zypper_remove(opts)
|
152
|
+
when 'purge-kernels'
|
153
|
+
zypper_purge_kernels(opts)
|
154
|
+
when 'search', 'se'
|
155
|
+
zypper_search(opts)
|
156
|
+
when 'clean', 'cc'
|
157
|
+
zypper_clean_cache(opts)
|
158
|
+
when 'list-updates', 'lu'
|
159
|
+
zypper_list_updates(opts)
|
160
|
+
when 'list-patches', 'lp'
|
161
|
+
zypper_list_patches(opts)
|
162
|
+
|
163
|
+
when 'patch-check', 'pchk'
|
164
|
+
zypper_patch_check(opts)
|
165
|
+
when 'patch'
|
166
|
+
zypper_patch(opts)
|
167
|
+
when 'dist-upgrade', 'dup'
|
168
|
+
zypper_dist_upgrade(opts)
|
169
|
+
when 'update', 'up'
|
170
|
+
zypper_update(opts)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
def zypper_clean_cache(opts)
|
177
|
+
command = Kanrisuru::Command.new('zypper')
|
178
|
+
zypper_global_opts(command, opts)
|
179
|
+
|
180
|
+
command << 'clean'
|
181
|
+
command.append_flag('--metadata', opts[:metadata])
|
182
|
+
command.append_flag('--raw-metadata', opts[:raw_metadata])
|
183
|
+
command.append_flag('--all', opts[:all])
|
184
|
+
|
185
|
+
command << opts[:repos]
|
186
|
+
|
187
|
+
execute_shell(command)
|
188
|
+
|
189
|
+
Kanrisuru::Result.new(command)
|
190
|
+
end
|
191
|
+
|
192
|
+
def zypper_list_repos(opts)
|
193
|
+
command = Kanrisuru::Command.new('zypper')
|
194
|
+
zypper_global_opts(command, opts)
|
195
|
+
|
196
|
+
command << 'repos'
|
197
|
+
command.append_flag('--details')
|
198
|
+
|
199
|
+
execute_shell(command)
|
200
|
+
|
201
|
+
Kanrisuru::Result.new(command) do |cmd|
|
202
|
+
lines = cmd.to_a
|
203
|
+
|
204
|
+
rows = []
|
205
|
+
lines.each do |line|
|
206
|
+
next unless line.match(/^\d/)
|
207
|
+
|
208
|
+
values = line.split('|')
|
209
|
+
values = values.map(&:strip)
|
210
|
+
|
211
|
+
rows << Repo.new(
|
212
|
+
values[0].to_i,
|
213
|
+
values[1],
|
214
|
+
values[2],
|
215
|
+
values[3] == 'Yes',
|
216
|
+
values[4].include?('Yes'),
|
217
|
+
values[5] == 'Yes',
|
218
|
+
values[6].to_i,
|
219
|
+
values[7],
|
220
|
+
values[8],
|
221
|
+
values.length == 10 ? values[9] : nil
|
222
|
+
)
|
223
|
+
end
|
224
|
+
rows
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def zypper_refresh_repos(opts)
|
229
|
+
command = Kanrisuru::Command.new('zypper')
|
230
|
+
zypper_global_opts(command, opts)
|
231
|
+
|
232
|
+
command << 'refresh'
|
233
|
+
|
234
|
+
command.append_flag('--force', opts[:force])
|
235
|
+
command.append_flag('--force-build', opts[:force_build])
|
236
|
+
command.append_flag('--force-download', opts[:force_download])
|
237
|
+
command.append_flag('--build-only', opts[:build_only])
|
238
|
+
command.append_flag('--download-only', opts[:download_only])
|
239
|
+
|
240
|
+
execute_shell(command)
|
241
|
+
|
242
|
+
Kanrisuru::Result.new(command)
|
243
|
+
end
|
244
|
+
|
245
|
+
def zypper_modify_repo(opts)
|
246
|
+
command = Kanrisuru::Command.new('zypper')
|
247
|
+
zypper_global_opts(command, opts)
|
248
|
+
|
249
|
+
command << 'modifyrepo'
|
250
|
+
|
251
|
+
command.append_arg('--name', opts[:name])
|
252
|
+
command.append_arg('--priority', opts[:priority])
|
253
|
+
|
254
|
+
command.append_flag('--enable', opts[:enable])
|
255
|
+
command.append_flag('--disable', opts[:disable])
|
256
|
+
command.append_flag('--refresh', opts[:refresh])
|
257
|
+
command.append_flag('--no-refresh', opts[:no_refresh])
|
258
|
+
command.append_flag('--keep-packages', opts[:keep_packages])
|
259
|
+
command.append_flag('--no-keep-packages', opts[:no_keep_packages])
|
260
|
+
|
261
|
+
command.append_flag('--gpgcheck', opts[:gpgcheck])
|
262
|
+
command.append_flag('--gpgcheck-strict', opts[:gpgcheck_strict])
|
263
|
+
command.append_flag('--gpgcheck-allow-unsigned', opts[:gpgcheck_allow_unsigned])
|
264
|
+
command.append_flag('--gpgcheck-allow-unsigned-repo', opts[:gpgcheck_allow_unsigned_repo])
|
265
|
+
command.append_flag('--gpgcheck-allow-unsigned-package', opts[:gpgcheck_allow_unsigned_package])
|
266
|
+
command.append_flag('--no-gpgcheck', opts[:no_gpgcheck])
|
267
|
+
command.append_flag('--default-gpgcheck', opts[:default_gpgcheck])
|
268
|
+
|
269
|
+
command.append_flag('--all', opts[:all])
|
270
|
+
command.append_flag('--local', opts[:local])
|
271
|
+
command.append_flag('--remote', opts[:remote])
|
272
|
+
|
273
|
+
if Kanrisuru::Util.present?(opts[:medium_type])
|
274
|
+
raise ArgumentError, 'Invalid medium type' unless MEDIUM_TYPES.include?(opts[:medium_type])
|
275
|
+
|
276
|
+
command.append_arg('--medium-type', opts[:medium_type])
|
277
|
+
end
|
278
|
+
|
279
|
+
repos = opts[:repos]
|
280
|
+
if Kanrisuru::Util.present?(repos)
|
281
|
+
repos = repos.instance_of?(String) ? [repos] : repos
|
282
|
+
command << repos.join(' ')
|
283
|
+
end
|
284
|
+
|
285
|
+
execute_shell(command)
|
286
|
+
|
287
|
+
Kanrisuru::Result.new(command)
|
288
|
+
end
|
289
|
+
|
290
|
+
def zypper_add_repo(opts)
|
291
|
+
command = Kanrisuru::Command.new('zypper')
|
292
|
+
zypper_global_opts(command, opts)
|
293
|
+
|
294
|
+
command << 'addrepo'
|
295
|
+
|
296
|
+
command.append_flag('--check', opts[:check])
|
297
|
+
command.append_flag('--no-check', opts[:no_check])
|
298
|
+
command.append_flag('--enable', opts[:enable])
|
299
|
+
command.append_flag('--disable', opts[:disable])
|
300
|
+
command.append_flag('--refresh', opts[:refresh])
|
301
|
+
command.append_flag('--no-refresh', opts[:no_refresh])
|
302
|
+
command.append_flag('--keep-packages', opts[:keep_packages])
|
303
|
+
command.append_flag('--no-keep-packages', opts[:no_keep_packages])
|
304
|
+
command.append_flag('--gpgcheck', opts[:gpgcheck])
|
305
|
+
command.append_flag('--gpgcheck-strict', opts[:gpgcheck_strict])
|
306
|
+
command.append_flag('--gpgcheck-allow-unsigned', opts[:gpgcheck_allow_unsigned])
|
307
|
+
command.append_flag('--gpgcheck-allow-unsigned-repo', opts[:gpgcheck_allow_unsigned_repo])
|
308
|
+
command.append_flag('--gpgcheck-allow-unsigned-package', opts[:gpgcheck_allow_unsigned_package])
|
309
|
+
command.append_flag('--no-gpgcheck', opts[:no_gpgcheck])
|
310
|
+
command.append_flag('--default-gpgcheck', opts[:default_gpgcheck])
|
311
|
+
|
312
|
+
command.append_arg('--priority', opts[:priority])
|
313
|
+
|
314
|
+
zypper_repos_opt(command, opts)
|
315
|
+
|
316
|
+
execute_shell(command)
|
317
|
+
|
318
|
+
Kanrisuru::Result.new(command)
|
319
|
+
end
|
320
|
+
|
321
|
+
def zypper_remove_repo(opts)
|
322
|
+
command = Kanrisuru::Command.new('zypper')
|
323
|
+
zypper_global_opts(command, opts)
|
324
|
+
|
325
|
+
command << 'removerepo'
|
326
|
+
|
327
|
+
command.append_flag('--loose-auth', opts[:loose_auth])
|
328
|
+
command.append_flag('--loose-query', opts[:loose_query])
|
329
|
+
command.append_flag('--all', opts[:all])
|
330
|
+
command.append_flag('--local', opts[:local])
|
331
|
+
command.append_flag('--remote', opts[:remote])
|
332
|
+
|
333
|
+
if Kanrisuru::Util.present?(opts[:media_type])
|
334
|
+
raise ArgumentError, 'Invalid media type' unless ZYPPER_MEDIA_TYPES.include?(opts[:media_type])
|
335
|
+
|
336
|
+
command.append_arg('--media-type', opts[:media_type])
|
337
|
+
end
|
338
|
+
|
339
|
+
repos = opts[:repos]
|
340
|
+
if Kanrisuru::Util.present?(repos)
|
341
|
+
repos = repos.instance_of?(String) ? [repos] : repos
|
342
|
+
command << repos.join(' ')
|
343
|
+
end
|
344
|
+
|
345
|
+
execute_shell(command)
|
346
|
+
|
347
|
+
Kanrisuru::Result.new(command)
|
348
|
+
end
|
349
|
+
|
350
|
+
def zypper_rename_repo(opts)
|
351
|
+
command = Kanrisuru::Command.new('zypper')
|
352
|
+
zypper_global_opts(command, opts)
|
353
|
+
|
354
|
+
command << 'renamerepo'
|
355
|
+
command << opts[:repo]
|
356
|
+
command << opts[:alias]
|
357
|
+
|
358
|
+
execute_shell(command)
|
359
|
+
|
360
|
+
Kanrisuru::Result.new(command)
|
361
|
+
end
|
362
|
+
|
363
|
+
def zypper_add_service(opts)
|
364
|
+
command = Kanrisuru::Command.new('zypper')
|
365
|
+
zypper_global_opts(command, opts)
|
366
|
+
command << 'addservice'
|
367
|
+
|
368
|
+
command.append_arg('--name', opts[:name])
|
369
|
+
|
370
|
+
command.append_flag('--enable', opts[:enable])
|
371
|
+
command.append_flag('--disable', opts[:disable])
|
372
|
+
command.append_flag('--refresh', opts[:refresh])
|
373
|
+
command.append_flag('--no-refresh', opts[:no_refresh])
|
374
|
+
|
375
|
+
services = opts[:services]
|
376
|
+
if Kanrisuru::Util.present?(services)
|
377
|
+
services = services.instance_of?(Array) ? services : [services]
|
378
|
+
command << services.join(' ')
|
379
|
+
end
|
380
|
+
|
381
|
+
execute_shell(command)
|
382
|
+
|
383
|
+
Kanrisuru::Result.new(command)
|
384
|
+
end
|
385
|
+
|
386
|
+
def zypper_remove_service(opts)
|
387
|
+
command = Kanrisuru::Command.new('zypper')
|
388
|
+
zypper_global_opts(command, opts)
|
389
|
+
command << 'removeservice'
|
390
|
+
command.append_flag('--loose-auth', opts[:loose_auth])
|
391
|
+
command.append_flag('--loose-query', opts[:loose_query])
|
392
|
+
|
393
|
+
services = opts[:services]
|
394
|
+
if Kanrisuru::Util.present?(services)
|
395
|
+
services = services.instance_of?(String) ? [services] : services
|
396
|
+
command << services.join(' ')
|
397
|
+
end
|
398
|
+
|
399
|
+
execute_shell(command)
|
400
|
+
|
401
|
+
Kanrisuru::Result.new(command)
|
402
|
+
end
|
403
|
+
|
404
|
+
def zypper_modify_service(opts)
|
405
|
+
command = Kanrisuru::Command.new('zypper')
|
406
|
+
zypper_global_opts(command, opts)
|
407
|
+
|
408
|
+
command << 'modifyservice'
|
409
|
+
command.append_arg('--name', opts[:name])
|
410
|
+
|
411
|
+
command.append_flag('--enable', opts[:enable])
|
412
|
+
command.append_flag('--disable', opts[:disable])
|
413
|
+
command.append_flag('--refresh', opts[:refresh])
|
414
|
+
command.append_flag('--no-refresh', opts[:no_refresh])
|
415
|
+
command.append_flag('--all', opts[:all])
|
416
|
+
command.append_flag('--local', opts[:local])
|
417
|
+
command.append_flag('--remote', opts[:remote])
|
418
|
+
|
419
|
+
command.append_arg('--ar-to-enable', opts[:ar_to_enable])
|
420
|
+
command.append_arg('--ar-to-disable', opts[:ar_to_disable])
|
421
|
+
command.append_arg('--rr-to-enable', opts[:rr_to_enable])
|
422
|
+
command.append_arg('--rr-to-disable', opts[:rr_to_disable])
|
423
|
+
command.append_arg('--cl-to-enable', opts[:cl_to_enable])
|
424
|
+
command.append_arg('--cl-to-disable', opts[:cl_to_disable])
|
425
|
+
|
426
|
+
if Kanrisuru::Util.present?(opts[:medium_type])
|
427
|
+
raise ArgumentError, 'Invalid medium type' unless MEDIUM_TYPES.include?(opts[:medium_type])
|
428
|
+
|
429
|
+
command.append_arg('--medium-type', opts[:medium_type])
|
430
|
+
end
|
431
|
+
|
432
|
+
execute_shell(command)
|
433
|
+
|
434
|
+
Kanrisuru::Result.new(command)
|
435
|
+
end
|
436
|
+
|
437
|
+
def zypper_list_services(opts)
|
438
|
+
command = Kanrisuru::Command.new('zypper')
|
439
|
+
zypper_global_opts(command, opts)
|
440
|
+
|
441
|
+
command << 'services'
|
442
|
+
command.append_flag('--details')
|
443
|
+
|
444
|
+
execute_shell(command)
|
445
|
+
|
446
|
+
Kanrisuru::Result.new(command) do |cmd|
|
447
|
+
lines = cmd.to_a
|
448
|
+
|
449
|
+
rows = []
|
450
|
+
lines.each do |line|
|
451
|
+
next unless line.match(/^\d/)
|
452
|
+
|
453
|
+
values = line.split('|')
|
454
|
+
values = values.map(&:strip)
|
455
|
+
|
456
|
+
rows << Service.new(
|
457
|
+
values[0].to_i,
|
458
|
+
values[1],
|
459
|
+
values[2],
|
460
|
+
values[3] == 'Yes',
|
461
|
+
values[4].include?('Yes'),
|
462
|
+
values[5] == 'Yes',
|
463
|
+
values[6].to_i,
|
464
|
+
values[7],
|
465
|
+
values[8]
|
466
|
+
)
|
467
|
+
end
|
468
|
+
rows
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
def zypper_refresh_services(opts)
|
473
|
+
command = Kanrisuru::Command.new('zypper')
|
474
|
+
zypper_global_opts(command, opts)
|
475
|
+
|
476
|
+
command << 'refresh-services'
|
477
|
+
command.append_flag('--force', opts[:force])
|
478
|
+
command.append_flag('--with-repos', opts[:with_repos])
|
479
|
+
command.append_flag('--restore-status', opts[:restore_status])
|
480
|
+
|
481
|
+
execute_shell(command)
|
482
|
+
|
483
|
+
Kanrisuru::Result.new(command)
|
484
|
+
end
|
485
|
+
|
486
|
+
def zypper_add_lock(opts)
|
487
|
+
command = Kanrisuru::Command.new('zypper')
|
488
|
+
zypper_global_opts(command, opts)
|
489
|
+
command << 'addlock'
|
490
|
+
|
491
|
+
command.append_arg('--repo', opts[:repo])
|
492
|
+
zypper_package_type_opt(command, opts)
|
493
|
+
|
494
|
+
command << opts[:lock]
|
495
|
+
|
496
|
+
execute_shell(command)
|
497
|
+
|
498
|
+
Kanrisuru::Result.new(command)
|
499
|
+
end
|
500
|
+
|
501
|
+
def zypper_remove_lock(opts)
|
502
|
+
command = Kanrisuru::Command.new('zypper')
|
503
|
+
zypper_global_opts(command, opts)
|
504
|
+
command << 'removelock'
|
505
|
+
|
506
|
+
command.append_arg('--repo', opts[:repo])
|
507
|
+
zypper_package_type_opt(command, opts)
|
508
|
+
|
509
|
+
command << opts[:lock]
|
510
|
+
|
511
|
+
execute_shell(command)
|
512
|
+
|
513
|
+
Kanrisuru::Result.new(command)
|
514
|
+
end
|
515
|
+
|
516
|
+
def zypper_list_locks(opts)
|
517
|
+
command = Kanrisuru::Command.new('zypper')
|
518
|
+
zypper_global_opts(command, opts)
|
519
|
+
command.append_flag('--quiet')
|
520
|
+
command << 'locks'
|
521
|
+
|
522
|
+
command.append_flag('--matches')
|
523
|
+
|
524
|
+
execute_shell(command)
|
525
|
+
|
526
|
+
Kanrisuru::Result.new(command) do |cmd|
|
527
|
+
lines = cmd.to_a
|
528
|
+
|
529
|
+
rows = []
|
530
|
+
lines.each do |line|
|
531
|
+
next if line == ''
|
532
|
+
|
533
|
+
values = line.split(' | ')
|
534
|
+
next if values.length != 5
|
535
|
+
next if values[0] == '#' && values[4] == 'Repository'
|
536
|
+
|
537
|
+
values = values.map(&:strip)
|
538
|
+
|
539
|
+
rows << Lock.new(
|
540
|
+
values[0].to_i,
|
541
|
+
values[1],
|
542
|
+
values[2].to_i,
|
543
|
+
values[3],
|
544
|
+
values[4]
|
545
|
+
)
|
546
|
+
end
|
547
|
+
|
548
|
+
rows
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
def zypper_clean_locks(opts)
|
553
|
+
command = Kanrisuru::Command.new('zypper')
|
554
|
+
zypper_global_opts(command, opts)
|
555
|
+
command << 'cleanlocks'
|
556
|
+
|
557
|
+
execute_shell(command)
|
558
|
+
|
559
|
+
Kanrisuru::Result.new(command)
|
560
|
+
end
|
561
|
+
|
562
|
+
def zypper_info(opts)
|
563
|
+
command = Kanrisuru::Command.new('zypper')
|
564
|
+
zypper_global_opts(command, opts)
|
565
|
+
command << 'info'
|
566
|
+
|
567
|
+
zypper_repos_opt(command, opts)
|
568
|
+
zypper_package_type_opt(command, opts)
|
569
|
+
|
570
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
571
|
+
command << packages
|
572
|
+
|
573
|
+
execute_shell(command)
|
574
|
+
|
575
|
+
Kanrisuru::Result.new(command) do |cmd|
|
576
|
+
lines = cmd.to_a
|
577
|
+
|
578
|
+
rows = []
|
579
|
+
current_row = nil
|
580
|
+
description = ''
|
581
|
+
skip_description = false
|
582
|
+
|
583
|
+
lines.each do |line|
|
584
|
+
case line
|
585
|
+
when /^Repository/
|
586
|
+
repository = extract_single_zypper_line(line)
|
587
|
+
next if repository == ''
|
588
|
+
|
589
|
+
unless current_row.nil?
|
590
|
+
skip_description = false
|
591
|
+
current_row.description = description.strip
|
592
|
+
description = ''
|
593
|
+
rows << current_row
|
594
|
+
end
|
595
|
+
|
596
|
+
current_row = PackageDetail.new
|
597
|
+
current_row.repository = repository
|
598
|
+
when /^Name/
|
599
|
+
current_row.package = extract_single_zypper_line(line)
|
600
|
+
when /^Version/
|
601
|
+
current_row.version = extract_single_zypper_line(line)
|
602
|
+
when /^Arch/
|
603
|
+
current_row.architecture = extract_single_zypper_line(line)
|
604
|
+
when /^Vendor/
|
605
|
+
current_row.vendor = extract_single_zypper_line(line)
|
606
|
+
when /^Support Level/
|
607
|
+
current_row.support_level = extract_single_zypper_line(line)
|
608
|
+
when /^Installed Size/
|
609
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_zypper_line(line))
|
610
|
+
current_row.install_size = size
|
611
|
+
when /^Installed/
|
612
|
+
value = extract_single_zypper_line(line)
|
613
|
+
current_row.installed = value == 'Yes'
|
614
|
+
when /^Status/
|
615
|
+
current_row.status = extract_single_zypper_line(line)
|
616
|
+
when /^Source package/
|
617
|
+
current_row.source_package = extract_single_zypper_line(line)
|
618
|
+
when /^Summary/
|
619
|
+
current_row.summary = extract_single_zypper_line(line)
|
620
|
+
when /^Description/
|
621
|
+
description = extract_single_zypper_line(line)
|
622
|
+
when /^Builds binary package/, /^Contents/
|
623
|
+
skip_description = true
|
624
|
+
else
|
625
|
+
next if line == ''
|
626
|
+
next if line.include?('Information for package')
|
627
|
+
next if line.include?('---------------------------')
|
628
|
+
|
629
|
+
description += " #{line.strip}" unless skip_description
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
if current_row
|
634
|
+
current_row.description = description.strip
|
635
|
+
rows << current_row
|
636
|
+
end
|
637
|
+
|
638
|
+
rows
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
642
|
+
def zypper_install(opts)
|
643
|
+
command = Kanrisuru::Command.new('zypper')
|
644
|
+
zypper_global_opts(command, opts)
|
645
|
+
command << 'install'
|
646
|
+
|
647
|
+
zypper_repos_opt(command, opts)
|
648
|
+
zypper_package_type_opt(command, opts)
|
649
|
+
|
650
|
+
command.append_arg('-n', opts[:name])
|
651
|
+
command.append_arg('-f', opts[:force])
|
652
|
+
command.append_flag('--oldpackage', opts[:oldpackage])
|
653
|
+
command.append_arg('--from', opts[:from])
|
654
|
+
command.append_arg('--capability', opts[:capability])
|
655
|
+
command.append_flag('--auto-agree-with-licenses', opts[:auto_agree_with_licenses])
|
656
|
+
command.append_flag('--auto-agree-with-product-licenses', opts[:auto_agree_with_product_licenses])
|
657
|
+
command.append_flag('--replacefiles', opts[:replacefiles])
|
658
|
+
|
659
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
660
|
+
command.append_flag('--allow-unsigned-rpm', opts[:allow_unsigned_rpm])
|
661
|
+
|
662
|
+
zypper_solver_opts(command, opts)
|
663
|
+
zypper_download_and_install_opts(command, opts)
|
664
|
+
zypper_expert_opts(command, opts)
|
665
|
+
|
666
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
667
|
+
command << packages
|
668
|
+
|
669
|
+
execute_shell(command)
|
670
|
+
|
671
|
+
Kanrisuru::Result.new(command)
|
672
|
+
end
|
673
|
+
|
674
|
+
def zypper_verify(opts)
|
675
|
+
command = Kanrisuru::Command.new('zypper')
|
676
|
+
zypper_global_opts(command, opts)
|
677
|
+
command << 'verify'
|
678
|
+
|
679
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
680
|
+
|
681
|
+
zypper_repos_opt(command, opts)
|
682
|
+
zypper_solver_opts(command, opts)
|
683
|
+
zypper_expert_opts(command, opts)
|
684
|
+
|
685
|
+
execute_shell(command)
|
686
|
+
|
687
|
+
Kanrisuru::Result.new(command)
|
688
|
+
end
|
689
|
+
|
690
|
+
def zypper_source_install(opts)
|
691
|
+
command = Kanrisuru::Command.new('zypper')
|
692
|
+
zypper_global_opts(command, opts)
|
693
|
+
command << 'sourceinstall'
|
694
|
+
|
695
|
+
zypper_repos_opt(command, opts)
|
696
|
+
command.append_flag('--build-deps-only', opts[:build_deps_only])
|
697
|
+
command.append_flag('--no-build-deps', opts[:no_build_deps])
|
698
|
+
command.append_flag('--download-only', opts[:download_only])
|
699
|
+
|
700
|
+
execute_shell(command)
|
701
|
+
|
702
|
+
Kanrisuru::Result.new(command)
|
703
|
+
end
|
704
|
+
|
705
|
+
def zypper_remove(opts)
|
706
|
+
command = Kanrisuru::Command.new('zypper')
|
707
|
+
zypper_global_opts(command, opts)
|
708
|
+
command << 'remove'
|
709
|
+
|
710
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
711
|
+
command.append_flag('--capability', opts[:capability])
|
712
|
+
|
713
|
+
zypper_repos_opt(command, opts)
|
714
|
+
zypper_package_type_opt(command, opts)
|
715
|
+
zypper_solver_opts(command, opts)
|
716
|
+
|
717
|
+
execute_shell(command)
|
718
|
+
Kanrisuru::Result.new(command)
|
719
|
+
end
|
720
|
+
|
721
|
+
def zypper_install_new_recommends(opts)
|
722
|
+
command = Kanrisuru::Command.new('zypper')
|
723
|
+
zypper_global_opts(command, opts)
|
724
|
+
command << 'install-new-recommends'
|
725
|
+
|
726
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
727
|
+
|
728
|
+
zypper_repos_opt(command, opts)
|
729
|
+
zypper_solver_opts(command, opts)
|
730
|
+
zypper_expert_opts(command, opts)
|
731
|
+
|
732
|
+
execute_shell(command)
|
733
|
+
|
734
|
+
Kanrisuru::Result.new(command)
|
735
|
+
end
|
736
|
+
|
737
|
+
def zypper_purge_kernels(opts)
|
738
|
+
command = Kanrisuru::Command.new('zypper')
|
739
|
+
zypper_global_opts(command, opts)
|
740
|
+
command << 'purge-kernels'
|
741
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
742
|
+
|
743
|
+
execute_shell(command)
|
744
|
+
|
745
|
+
Kanrisuru::Result.new(command)
|
746
|
+
end
|
747
|
+
|
748
|
+
def zypper_search(opts)
|
749
|
+
command = Kanrisuru::Command.new('zypper')
|
750
|
+
zypper_global_opts(command, opts)
|
751
|
+
command << 'search'
|
752
|
+
|
753
|
+
command.append_flag('--details')
|
754
|
+
command.append_flag('--match-substrings', opts[:match_substrings])
|
755
|
+
command.append_flag('--match-words', opts[:match_words])
|
756
|
+
command.append_flag('--match-exact', opts[:match_exact])
|
757
|
+
command.append_flag('--provides', opts[:provides])
|
758
|
+
command.append_flag('--requires', opts[:requires])
|
759
|
+
command.append_flag('--recommends', opts[:recommends])
|
760
|
+
command.append_flag('--suggests', opts[:suggests])
|
761
|
+
command.append_flag('--conflicts', opts[:conflicts])
|
762
|
+
command.append_flag('--obsoletes', opts[:obsoletes])
|
763
|
+
command.append_flag('--supplements', opts[:supplements])
|
764
|
+
command.append_flag('--provides-pkg', opts[:provides_pkg])
|
765
|
+
command.append_flag('--requires-pkg', opts[:requires_pkg])
|
766
|
+
command.append_flag('--recommends-pkg', opts[:recommends_pkg])
|
767
|
+
command.append_flag('--supplements-pkg', opts[:supplements_pkg])
|
768
|
+
command.append_flag('--conflicts-pkg', opts[:conflicts_pkg])
|
769
|
+
command.append_flag('--obsoletes-pkg', opts[:obsoletes_pkg])
|
770
|
+
command.append_flag('--suggests-pkg', opts[:suggests_pkg])
|
771
|
+
command.append_flag('--name', opts[:name])
|
772
|
+
command.append_flag('--file-list', opts[:file_list])
|
773
|
+
command.append_flag('--search-descriptions', opts[:search_descriptions])
|
774
|
+
command.append_flag('--case-sensitive', opts[:case_sensitive])
|
775
|
+
command.append_flag('--installed-only', opts[:installed_only])
|
776
|
+
command.append_flag('--not-installed-only', opts[:not_installed_only])
|
777
|
+
command.append_flag('--sort-by-name', opts[:sort_by_name])
|
778
|
+
command.append_flag('--sort-by-repo', opts[:sort_by_repo])
|
779
|
+
|
780
|
+
zypper_repos_opt(command, opts)
|
781
|
+
zypper_package_type_opt(command, opts)
|
782
|
+
|
783
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
784
|
+
command << packages
|
785
|
+
|
786
|
+
execute_shell(command)
|
787
|
+
|
788
|
+
Kanrisuru::Result.new(command) do |cmd|
|
789
|
+
lines = cmd.to_a
|
790
|
+
|
791
|
+
rows = []
|
792
|
+
lines.each do |line|
|
793
|
+
next if line == ''
|
794
|
+
|
795
|
+
values = line.split('|')
|
796
|
+
next if values.length != 6
|
797
|
+
|
798
|
+
values = values.map(&:strip)
|
799
|
+
next if values[0] == 'S' && values[5] == 'Repository'
|
800
|
+
|
801
|
+
rows << SearchResult.new(
|
802
|
+
values[5],
|
803
|
+
values[1],
|
804
|
+
values[0],
|
805
|
+
values[2],
|
806
|
+
values[3],
|
807
|
+
values[4]
|
808
|
+
)
|
809
|
+
end
|
810
|
+
|
811
|
+
rows
|
812
|
+
end
|
813
|
+
end
|
814
|
+
|
815
|
+
def zypper_update(opts)
|
816
|
+
command = Kanrisuru::Command.new('zypper')
|
817
|
+
zypper_global_opts(command, opts)
|
818
|
+
command << 'update'
|
819
|
+
|
820
|
+
zypper_repos_opt(command, opts)
|
821
|
+
zypper_package_type_opt(command, opts)
|
822
|
+
|
823
|
+
command.append_flag('--replacefiles', opts[:replacefiles])
|
824
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
825
|
+
command.append_flag('--best-effort', opts[:best_effort])
|
826
|
+
|
827
|
+
zypper_solver_opts(command, opts)
|
828
|
+
zypper_expert_opts(command, opts)
|
829
|
+
|
830
|
+
execute_shell(command)
|
831
|
+
|
832
|
+
Kanrisuru::Result.new(command)
|
833
|
+
end
|
834
|
+
|
835
|
+
def zypper_list_updates(opts)
|
836
|
+
return zypper_list_patches(opts) if opts[:type] == 'patch'
|
837
|
+
|
838
|
+
command = Kanrisuru::Command.new('zypper')
|
839
|
+
zypper_global_opts(command, opts)
|
840
|
+
command.append_flag('--quiet')
|
841
|
+
command << 'list-updates'
|
842
|
+
|
843
|
+
zypper_repos_opt(command, opts)
|
844
|
+
zypper_package_type_opt(command, opts)
|
845
|
+
|
846
|
+
command.append_flag('--all', opts[:all])
|
847
|
+
command.append_flag('--best-effort', opts[:best_effort])
|
848
|
+
|
849
|
+
zypper_expert_opts(command, opts)
|
850
|
+
|
851
|
+
execute_shell(command)
|
852
|
+
|
853
|
+
Kanrisuru::Result.new(command) do |cmd|
|
854
|
+
lines = cmd.to_a
|
855
|
+
lines.shift
|
856
|
+
|
857
|
+
rows = []
|
858
|
+
lines.each do |line|
|
859
|
+
values = line.split(' | ')
|
860
|
+
values = values.map(&:strip)
|
861
|
+
|
862
|
+
rows << PackageUpdate.new(
|
863
|
+
values[1],
|
864
|
+
values[2],
|
865
|
+
values[3],
|
866
|
+
values[4],
|
867
|
+
values[5]
|
868
|
+
)
|
869
|
+
end
|
870
|
+
|
871
|
+
rows
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
def zypper_list_patches(opts)
|
876
|
+
command = Kanrisuru::Command.new('zypper')
|
877
|
+
zypper_global_opts(command, opts)
|
878
|
+
command.append_flag('--quiet')
|
879
|
+
command << 'list-patches'
|
880
|
+
|
881
|
+
command.append_arg('--bugzilla', opts[:bugzilla])
|
882
|
+
command.append_arg('--cve', opts[:cve])
|
883
|
+
command.append_arg('--date', opts[:date])
|
884
|
+
|
885
|
+
zypper_patch_category_opt(command, opts)
|
886
|
+
zypper_patch_severity_opt(command, opts)
|
887
|
+
|
888
|
+
command.append_flag('--issues', opts[:issues])
|
889
|
+
command.append_flag('--all', opts[:all])
|
890
|
+
command.append_flag('--with-optional', opts[:with_optional])
|
891
|
+
command.append_flag('--without-optional', opts[:without_optional])
|
892
|
+
|
893
|
+
zypper_repos_opt(command, opts)
|
894
|
+
|
895
|
+
execute_shell(command)
|
896
|
+
|
897
|
+
Kanrisuru::Result.new(command) do |cmd|
|
898
|
+
lines = cmd.to_a
|
899
|
+
lines.shift
|
900
|
+
lines.shift
|
901
|
+
|
902
|
+
rows = []
|
903
|
+
lines.each do |line|
|
904
|
+
next if line == ''
|
905
|
+
|
906
|
+
values = line.split(' | ')
|
907
|
+
next if values.length != 7
|
908
|
+
|
909
|
+
values = values.map(&:strip)
|
910
|
+
next if values[0] == 'Repository' && values[6] == 'Summary'
|
911
|
+
|
912
|
+
rows << PatchUpdate.new(
|
913
|
+
values[0],
|
914
|
+
values[1],
|
915
|
+
values[2],
|
916
|
+
values[3],
|
917
|
+
values[4] == '---' ? '' : values[4],
|
918
|
+
values[5],
|
919
|
+
values[6]
|
920
|
+
)
|
921
|
+
end
|
922
|
+
|
923
|
+
rows
|
924
|
+
end
|
925
|
+
end
|
926
|
+
|
927
|
+
def zypper_patch_check(opts)
|
928
|
+
command = Kanrisuru::Command.new('zypper')
|
929
|
+
command.append_valid_exit_code(EXIT_INF_UPDATE_NEEDED)
|
930
|
+
command.append_valid_exit_code(EXIT_INF_SEC_UPDATE_NEEDED)
|
931
|
+
|
932
|
+
zypper_global_opts(command, opts)
|
933
|
+
command.append_flag('--quiet')
|
934
|
+
command << 'patch-check'
|
935
|
+
|
936
|
+
command.append_flag('--updatestack-only', opts[:updatestack_only])
|
937
|
+
command.append_flag('--with-optional', opts[:with_optional])
|
938
|
+
command.append_flag('--without-optional', opts[:without_optional])
|
939
|
+
|
940
|
+
zypper_repos_opt(command, opts)
|
941
|
+
|
942
|
+
execute_shell(command)
|
943
|
+
|
944
|
+
Kanrisuru::Result.new(command) do |cmd|
|
945
|
+
lines = cmd.to_a
|
946
|
+
|
947
|
+
rows = []
|
948
|
+
lines.each do |line|
|
949
|
+
next if line == ''
|
950
|
+
|
951
|
+
values = line.split(' | ')
|
952
|
+
next if values.length != 3
|
953
|
+
|
954
|
+
values = values.map(&:strip)
|
955
|
+
next if values[0] == 'Category'
|
956
|
+
|
957
|
+
rows << PatchCount.new(
|
958
|
+
values[0],
|
959
|
+
values[1].to_i,
|
960
|
+
values[2].to_i
|
961
|
+
)
|
962
|
+
end
|
963
|
+
|
964
|
+
rows
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
def zypper_patch(opts)
|
969
|
+
command = Kanrisuru::Command.new('zypper')
|
970
|
+
command.append_valid_exit_code(EXIT_INF_REBOOT_NEEDED)
|
971
|
+
command.append_valid_exit_code(EXIT_INF_RESTART_NEEDED)
|
972
|
+
zypper_global_opts(command, opts)
|
973
|
+
|
974
|
+
command << 'patch'
|
975
|
+
|
976
|
+
command.append_flag('--updatestack-only', opts[:updatestack_only])
|
977
|
+
command.append_flag('--with-update', opts[:with_update])
|
978
|
+
command.append_flag('--with-optional', opts[:with_optional])
|
979
|
+
command.append_flag('--without-optional', opts[:without_optional])
|
980
|
+
command.append_flag('--replacefiles', opts[:replacefiles])
|
981
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
982
|
+
|
983
|
+
command.append_flag('--auto-agree-with-licenses', opts[:auto_agree_with_licenses])
|
984
|
+
command.append_flag('--auto-agree-with-product-licenses', opts[:auto_agree_with_product_licenses])
|
985
|
+
|
986
|
+
command.append_arg('--bugzilla', opts[:bugzilla])
|
987
|
+
command.append_arg('--cve', opts[:cve])
|
988
|
+
command.append_arg('--date', opts[:date])
|
989
|
+
|
990
|
+
zypper_patch_category_opt(command, opts)
|
991
|
+
zypper_patch_severity_opt(command, opts)
|
992
|
+
zypper_repos_opt(command, opts)
|
993
|
+
zypper_solver_opts(command, opts)
|
994
|
+
zypper_expert_opts(command, opts)
|
995
|
+
|
996
|
+
execute_shell(command)
|
997
|
+
|
998
|
+
Kanrisuru::Result.new(command)
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def zypper_dist_upgrade(opts)
|
1002
|
+
command = Kanrisuru::Command.new('zypper')
|
1003
|
+
zypper_global_opts(command, opts)
|
1004
|
+
command << 'dist-upgrade'
|
1005
|
+
|
1006
|
+
command.append_flag('--auto-agree-with-licenses', opts[:auto_agree_with_licenses])
|
1007
|
+
command.append_flag('--auto-agree-with-product-licenses', opts[:auto_agree_with_product_licenses])
|
1008
|
+
command.append_flag('--dry-run', opts[:dry_run])
|
1009
|
+
|
1010
|
+
zypper_repos_opt(command, opts)
|
1011
|
+
zypper_solver_opts(command, opts)
|
1012
|
+
zypper_expert_opts(command, opts)
|
1013
|
+
|
1014
|
+
execute_shell(command)
|
1015
|
+
|
1016
|
+
Kanrisuru::Result.new(command)
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
def zypper_global_opts(command, opts)
|
1020
|
+
command.append_flag('--non-interactive')
|
1021
|
+
command.append_flag('--ignore-unknown')
|
1022
|
+
command.append_flag('--no-color')
|
1023
|
+
command.append_flag('--no-abbrev')
|
1024
|
+
command.append_arg('--config', opts[:config_file])
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
def zypper_solver_opts(command, opts)
|
1028
|
+
command.append_flag('--debug-solver', opts[:debug_solver])
|
1029
|
+
command.append_flag('--force-resolution', opts[:force_resolution])
|
1030
|
+
command.append_flag('--no-force-resolution', opts[:no_force_resolution])
|
1031
|
+
|
1032
|
+
solver_focus_mode = opts[:solver_focus_mode]
|
1033
|
+
if Kanrisuru::Util.present?(solver_focus_mode) && SOLVER_FOCUS_MODES.include?(solver_focus_mode)
|
1034
|
+
command.append_arg('--solver-focus', solver_focus_mode)
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
command.append_flag('--clean-deps', opts[:clean_deps])
|
1038
|
+
command.append_flag('--no-clean-deps', opts[:no_clean_deps])
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
def zypper_download_and_install_opts(command, opts)
|
1042
|
+
command.append_flag('--download-only', opts[:download_only])
|
1043
|
+
command.append_flag('--download-in-advance', opts[:download_in_advance])
|
1044
|
+
command.append_flag('--download-in-heaps', opts[:download_in_heaps])
|
1045
|
+
command.append_flag('--download-as-needed', opts[:download_as_needed])
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
def zypper_expert_opts(command, opts)
|
1049
|
+
command.append_flag('--allow-downgrade', opts[:allow_downgrade])
|
1050
|
+
command.append_flag('--no-allow-downgrade', opts[:no_allow_downgrade])
|
1051
|
+
command.append_flag('--allow-name-change', opts[:allow_name_change])
|
1052
|
+
command.append_flag('--no-allow-name-change', opts[:no_allow_name_change])
|
1053
|
+
command.append_flag('--allow-arch-change', opts[:allow_arch_change])
|
1054
|
+
command.append_flag('--no-allow-arch-change', opts[:no_allow_arch_change])
|
1055
|
+
command.append_flag('--allow-vendor-change', opts[:allow_vendor_change])
|
1056
|
+
command.append_flag('--no-allow-vendor-change', opts[:no_allow_vendor_change])
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
def zypper_repos_opt(command, opts)
|
1060
|
+
zypper_array_opt(command, opts[:repos], '--repo')
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
def zypper_patch_category_opt(command, opts)
|
1064
|
+
zypper_array_opt(command, opts[:category], '--category', PATCH_CATEGORIES)
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def zypper_patch_severity_opt(command, opts)
|
1068
|
+
zypper_array_opt(command, opts[:severity], '--severity', PATCH_SEVERITIES)
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
def zypper_array_opt(command, value, opt_value, array = nil)
|
1072
|
+
return unless Kanrisuru::Util.present?(value)
|
1073
|
+
|
1074
|
+
values = value.instance_of?(String) ? [value] : value
|
1075
|
+
values.each do |v|
|
1076
|
+
next if Kanrisuru::Util.present?(array) && !array.include?(v)
|
1077
|
+
|
1078
|
+
command.append_arg(opt_value, v)
|
1079
|
+
end
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
def zypper_package_type_opt(command, opts)
|
1083
|
+
type = opts[:type]
|
1084
|
+
|
1085
|
+
command.append_arg('-t', type) if Kanrisuru::Util.present?(type) && PACKAGE_TYPES.include?(type)
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
def extract_single_zypper_line(line)
|
1089
|
+
values = line.split(': ', 2)
|
1090
|
+
values.length == 2 ? values[1] : ''
|
1091
|
+
end
|
1092
|
+
end
|
1093
|
+
end
|
1094
|
+
end
|