zypper-upgraderepo 1.2.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +13 -0
- data/Gemfile.lock +19 -19
- data/lib/zypper/upgraderepo/cli.rb +66 -14
- data/lib/zypper/upgraderepo/os_release.rb +30 -2
- data/lib/zypper/upgraderepo/repository.rb +96 -12
- data/lib/zypper/upgraderepo/request.rb +17 -171
- data/lib/zypper/upgraderepo/requests/http.rb +131 -0
- data/lib/zypper/upgraderepo/requests/local.rb +94 -0
- data/lib/zypper/upgraderepo/traversable.rb +93 -0
- data/lib/zypper/upgraderepo/utils.rb +79 -1
- data/lib/zypper/upgraderepo/version.rb +1 -1
- data/lib/zypper/upgraderepo/view.rb +166 -8
- data/lib/zypper/upgraderepo.rb +47 -26
- data/zypper-upgraderepo.gemspec +19 -19
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16c361a53d2dfbdfec788a093bd3bf5b8bf0baaedbb2e3c744f1b8ccf9184af0
|
4
|
+
data.tar.gz: da0e38eef39182fa0049f3009bbb5ffb35d06cfb0395e8ac58db055e9148c62c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26cac0292f39db0f6662924a7bcc14632ff0799af489eb9444c2b08acb4c3efe50e6dd09820d6395f0bb0cd4539c8a08bcb21f9595984e4fffa2fd72a49efdbd
|
7
|
+
data.tar.gz: 061ec093eaa6049a19ad15484e617400de8c1901e25f5a418053e0e66c1c24156eb498bc5502dbe54b06706e34f3f213d4411ca218ebec059df2362e7374fe37
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: [fabiomux]
|
4
|
+
#patreon: # Replace with a single Patreon username
|
5
|
+
#open_collective: # Replace with a single Open Collective username
|
6
|
+
#ko_fi: # Replace with a single Ko-fi username
|
7
|
+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
#liberapay: # Replace with a single Liberapay username
|
10
|
+
#issuehunt: # Replace with a single IssueHunt username
|
11
|
+
#otechie: # Replace with a single Otechie username
|
12
|
+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
13
|
+
custom: ['https://www.buymeacoffee.com/DCkNYFg']
|
data/Gemfile.lock
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zypper-upgraderepo (1.
|
4
|
+
zypper-upgraderepo (1.6.0)
|
5
5
|
iniparse
|
6
6
|
minitar
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
diff-lcs (1.
|
12
|
-
iniparse (1.
|
13
|
-
minitar (0.
|
14
|
-
rake (
|
15
|
-
rspec (3.
|
16
|
-
rspec-core (~> 3.
|
17
|
-
rspec-expectations (~> 3.
|
18
|
-
rspec-mocks (~> 3.
|
19
|
-
rspec-core (3.
|
20
|
-
rspec-support (~> 3.
|
21
|
-
rspec-expectations (3.
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
iniparse (1.5.0)
|
13
|
+
minitar (0.9)
|
14
|
+
rake (13.0.6)
|
15
|
+
rspec (3.10.0)
|
16
|
+
rspec-core (~> 3.10.0)
|
17
|
+
rspec-expectations (~> 3.10.0)
|
18
|
+
rspec-mocks (~> 3.10.0)
|
19
|
+
rspec-core (3.10.1)
|
20
|
+
rspec-support (~> 3.10.0)
|
21
|
+
rspec-expectations (3.10.1)
|
22
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.
|
24
|
-
rspec-mocks (3.
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-mocks (3.10.2)
|
25
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.
|
27
|
-
rspec-support (3.
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-support (3.10.3)
|
28
28
|
|
29
29
|
PLATFORMS
|
30
30
|
ruby
|
31
31
|
|
32
32
|
DEPENDENCIES
|
33
|
-
bundler (~>
|
34
|
-
rake (~>
|
33
|
+
bundler (~> 2.0)
|
34
|
+
rake (~> 13.0)
|
35
35
|
rspec (~> 3.0)
|
36
36
|
zypper-upgraderepo!
|
37
37
|
|
38
38
|
BUNDLED WITH
|
39
|
-
|
39
|
+
2.2.19
|
@@ -23,6 +23,11 @@ module Zypper
|
|
23
23
|
options.view = :table
|
24
24
|
options.only_repo = nil
|
25
25
|
options.timeout = 10.0
|
26
|
+
options.exit_on_fail = false
|
27
|
+
options.overrides_filename = nil
|
28
|
+
options.only_invalid = false
|
29
|
+
options.only_protocols = nil
|
30
|
+
options.allow_unstable = false
|
26
31
|
|
27
32
|
opt_parser = OptionParser.new do |opt|
|
28
33
|
|
@@ -45,17 +50,25 @@ module Zypper
|
|
45
50
|
options.operation = :check_current
|
46
51
|
end
|
47
52
|
|
48
|
-
opt.on('-
|
53
|
+
opt.on('-n', '--check-next', 'Check the repositories for the next version') do |o|
|
49
54
|
options.operation = :check_next
|
50
55
|
end
|
51
56
|
|
52
|
-
opt.on('-C', '--check-
|
57
|
+
opt.on('-C', '--check-for <VERSION>', 'Check for a custom VERSION') do |v|
|
53
58
|
options.version = v
|
54
|
-
options.operation = :
|
59
|
+
options.operation = :check_for
|
55
60
|
end
|
56
61
|
|
57
|
-
opt.on('-
|
58
|
-
options.operation = :
|
62
|
+
opt.on('-l', '--check-last', 'Check the repositories for the last version') do |o|
|
63
|
+
options.operation = :check_last
|
64
|
+
end
|
65
|
+
|
66
|
+
opt.on('-R', '--reset', 'Reset the repositories to the current OS version.') do |v|
|
67
|
+
options.operation = :reset
|
68
|
+
end
|
69
|
+
|
70
|
+
opt.on('-u', '--upgrade', 'Upgrade to the next version available') do |o|
|
71
|
+
options.operation = :upgrade_to_next
|
59
72
|
end
|
60
73
|
|
61
74
|
opt.on('-U', '--upgrade-to <VERSION>', 'Upgrade to a specific VERSION') do |v|
|
@@ -63,15 +76,19 @@ module Zypper
|
|
63
76
|
options.operation = :upgrade_to
|
64
77
|
end
|
65
78
|
|
66
|
-
opt.
|
67
|
-
|
79
|
+
opt.on('-L', '--upgrade-to-last', 'Upgrade to the last version available') do |o|
|
80
|
+
options.operation = :upgrade_to_last
|
81
|
+
end
|
68
82
|
|
69
|
-
opt.on('
|
70
|
-
options.
|
83
|
+
opt.on('-s', '--status', 'Prints the version status of the current and available releases') do |o|
|
84
|
+
options.operation = :status
|
71
85
|
end
|
72
86
|
|
73
|
-
opt.
|
74
|
-
|
87
|
+
opt.separator ''
|
88
|
+
opt.separator 'Options:'
|
89
|
+
|
90
|
+
opt.on('--allow-unstable', 'Consider the unstable version as a valid release version') do |o|
|
91
|
+
options.allow_unstable = true
|
75
92
|
end
|
76
93
|
|
77
94
|
opt.on('--no-name', 'Don\'t upgrade the name') do |o|
|
@@ -82,18 +99,45 @@ module Zypper
|
|
82
99
|
options.alias = false
|
83
100
|
end
|
84
101
|
|
85
|
-
opt.on('--no-hint', 'Don\'t find a working
|
102
|
+
opt.on('--no-hint', 'Don\'t find a working URL when the current is invalid') do |o|
|
86
103
|
options.hint = false
|
87
104
|
end
|
88
105
|
|
89
|
-
opt.on('--override-url <NUMBER>,<URL>', Array, 'Overwrite the repository
|
106
|
+
opt.on('--override-url <NUMBER>,<URL>', Array, 'Overwrite the repository NUMBER with URL') do |r|
|
90
107
|
options.overrides[r[0].to_i] = r[1]
|
91
108
|
end
|
92
109
|
|
110
|
+
opt.on('--load-overrides <FILENAME>', 'Check the URLs in the exported FILENAME') do |f|
|
111
|
+
options.overrides_filename = f
|
112
|
+
end
|
113
|
+
|
114
|
+
opt.on('--exit-on-fail', 'Exit with error when a repository upgrade check fails') do |o|
|
115
|
+
options.exit_on_fail = true
|
116
|
+
end
|
117
|
+
|
93
118
|
opt.on('--timeout <SECONDS>', "Adjust the waiting SECONDS used to catch an HTTP Timeout Error (Default: #{options.timeout})") do |o|
|
94
119
|
options.timeout = o.to_f
|
95
120
|
end
|
96
121
|
|
122
|
+
opt.separator ''
|
123
|
+
opt.separator 'Filter options:'
|
124
|
+
|
125
|
+
opt.on('--only-enabled', 'Include only the enabled repositories') do |o|
|
126
|
+
options.only_enabled = true
|
127
|
+
end
|
128
|
+
|
129
|
+
opt.on('--only-repo <NUMBER>[,NUMBER2,...]', 'Include only the repositories specified by NUMBER') do |o|
|
130
|
+
options.only_repo = o.split(',').map(&:to_i)
|
131
|
+
end
|
132
|
+
|
133
|
+
opt.on('--only-invalid', 'Show only invalid repositories') do |o|
|
134
|
+
options.only_invalid = true
|
135
|
+
end
|
136
|
+
|
137
|
+
opt.on('--only-protocols <PROTOCOL>[,<PROTOCOL2>,...]', Array, "Show only from protocols (supported: #{Request.protocols.join(',')})") do |o|
|
138
|
+
options.only_protocols = o
|
139
|
+
end
|
140
|
+
|
97
141
|
opt.separator ''
|
98
142
|
opt.separator 'View options:'
|
99
143
|
|
@@ -109,6 +153,14 @@ module Zypper
|
|
109
153
|
options.sort_by = :priority
|
110
154
|
end
|
111
155
|
|
156
|
+
opt.on('--ini', 'Output the result in Ini format') do |o|
|
157
|
+
options.view = :ini
|
158
|
+
end
|
159
|
+
|
160
|
+
opt.on('--quiet', 'Quiet mode, show only error messages') do |o|
|
161
|
+
options.view = :quiet
|
162
|
+
end
|
163
|
+
|
112
164
|
opt.on('--report', 'View the data as report') do |o|
|
113
165
|
options.view = :report
|
114
166
|
end
|
@@ -150,7 +202,7 @@ module Zypper
|
|
150
202
|
Upgraderepo::Builder.new(options).send(options.operation)
|
151
203
|
rescue => e
|
152
204
|
Messages.error e
|
153
|
-
exit
|
205
|
+
exit e.error_code
|
154
206
|
end
|
155
207
|
end
|
156
208
|
end
|
@@ -6,12 +6,20 @@ module Zypper
|
|
6
6
|
|
7
7
|
class OsRelease
|
8
8
|
|
9
|
-
attr_reader :custom
|
9
|
+
attr_reader :custom, :unstable
|
10
10
|
|
11
|
-
OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1']
|
11
|
+
OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1', '15.2', '15.3']
|
12
12
|
|
13
|
+
UNSTABLE_VERSION = '15.4'
|
13
14
|
|
14
15
|
def initialize(options)
|
16
|
+
|
17
|
+
if options.allow_unstable
|
18
|
+
raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
|
19
|
+
OS_VERSIONS << UNSTABLE_VERSION
|
20
|
+
@unstable = true
|
21
|
+
end
|
22
|
+
|
15
23
|
fname = if File.exist? '/etc/os-release'
|
16
24
|
'/etc/os-release'
|
17
25
|
elsif File.exist? '/etc/SuSE-release'
|
@@ -32,6 +40,10 @@ module Zypper
|
|
32
40
|
OS_VERSIONS[@current_idx]
|
33
41
|
end
|
34
42
|
|
43
|
+
def last
|
44
|
+
OS_VERSIONS[-1]
|
45
|
+
end
|
46
|
+
|
35
47
|
def next
|
36
48
|
unless last?
|
37
49
|
OS_VERSIONS[@current_idx.next]
|
@@ -48,6 +60,22 @@ module Zypper
|
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
63
|
+
def fullname
|
64
|
+
@release['__anonymous__']['PRETTY_NAME'].gsub(/"/, '')
|
65
|
+
end
|
66
|
+
|
67
|
+
def seniority
|
68
|
+
OS_VERSIONS.count - @current_idx.next
|
69
|
+
end
|
70
|
+
|
71
|
+
def newer
|
72
|
+
if seniority > 0
|
73
|
+
OS_VERSIONS[@current_idx.next..-1]
|
74
|
+
else
|
75
|
+
[]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
51
79
|
def last?
|
52
80
|
@current_idx == (OS_VERSIONS.count - 1)
|
53
81
|
end
|
@@ -14,32 +14,91 @@ module Zypper
|
|
14
14
|
@alias = options.alias
|
15
15
|
@name = options.name
|
16
16
|
@only_repo = options.only_repo
|
17
|
+
@only_enabled = options.only_enabled
|
18
|
+
@only_invalid = options.only_invalid
|
19
|
+
@only_protocols = options.only_protocols
|
20
|
+
@overrides = options.overrides
|
21
|
+
@upgrade_options = {alias: options.alias, name: options.name}
|
17
22
|
@list = []
|
18
23
|
|
19
24
|
Dir.glob(File.join(REPOSITORY_PATH, '*.repo')).each do |i|
|
20
|
-
r =
|
21
|
-
next if options.only_enabled && (!r.enabled?)
|
25
|
+
r = Request.build(Repository.new(i), options.timeout)
|
22
26
|
@list << r
|
23
27
|
end
|
24
|
-
@max_col = @list.max_by { |
|
28
|
+
@max_col = @list.max_by { |r| r.name.length }.name.length
|
25
29
|
|
26
|
-
@list.sort_by
|
27
|
-
|
30
|
+
@list = @list.sort_by { |r| r.alias }.map.with_index(1) { |r, i| { num: i, repo: r } }
|
31
|
+
|
32
|
+
@list.sort_by! { |x| x[:repo].send(options.sort_by) } if options.sort_by != :alias
|
33
|
+
|
34
|
+
load_overrides(options.filename) if options.filename
|
35
|
+
end
|
36
|
+
|
37
|
+
def only_enabled?
|
38
|
+
@only_enabled
|
28
39
|
end
|
29
40
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
41
|
+
def upgrade!(version)
|
42
|
+
each_with_number(only_invalid: false) do |repo, num|
|
43
|
+
repo.upgrade! version, @upgrade_options.merge(url_override: @overrides[num])
|
44
|
+
repo.cache!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_with_number(options = {})
|
49
|
+
only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
|
50
|
+
only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
|
51
|
+
only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
|
52
|
+
only_protocols = options[:only_protocols].nil? ? @only_protocols : options[:only_protocols]
|
53
|
+
|
54
|
+
@list.each do |x|
|
55
|
+
next if only_repo && !only_repo.include?(x[:num])
|
56
|
+
next if only_enabled && !x[:repo].enabled?
|
57
|
+
next if only_invalid && x[:repo].available?
|
58
|
+
next if only_protocols && (!only_protocols.include?(x[:repo].protocol))
|
33
59
|
|
34
|
-
yield repo,
|
60
|
+
yield x[:repo], x[:num] if block_given?
|
35
61
|
end
|
36
62
|
end
|
37
63
|
|
64
|
+
def resolve_variables!(version)
|
65
|
+
each_with_number do |r|
|
66
|
+
if r.url =~ /\$/
|
67
|
+
r.url = r.url.gsub(/\$releasever_major/, version.split('.')[0])
|
68
|
+
.gsub(/\$releasever_minor/, version.split('.')[1])
|
69
|
+
.gsub(/\$releasever/, version)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
38
76
|
def save
|
39
77
|
@list.each do |i|
|
40
|
-
i.save
|
78
|
+
i[:repo].save
|
41
79
|
end
|
42
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def load_overrides(filename)
|
86
|
+
raise FileNotFound, filename unless File.exist?(filename)
|
87
|
+
ini = IniParse.parse(File.read(filename))
|
88
|
+
each_with_number(only_invalid: false) do |repo, num|
|
89
|
+
if x = ini["repository_#{num}"]
|
90
|
+
repo.enable!(x['enabled'])
|
91
|
+
raise UnmatchingOverrides, { num: num, ini: x, repo: repo } if repo.url != x['old_url']
|
92
|
+
if (@repos.only_enabled?)
|
93
|
+
raise MissingOverride, { num: num, ini: x } unless x['url'] || x['enabled'] =~ /no|false|0/i
|
94
|
+
else
|
95
|
+
raise MissingOverride, { num: num, ini: x } unless x['url']
|
96
|
+
end
|
97
|
+
@overrides[num] = x['url'] if x['url']
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
43
102
|
end
|
44
103
|
|
45
104
|
|
@@ -59,6 +118,10 @@ module Zypper
|
|
59
118
|
@repo[@key]['enabled'].to_i == 1
|
60
119
|
end
|
61
120
|
|
121
|
+
def enable!(value = true)
|
122
|
+
@repo[@key]['enabled'] = (value.to_s =~ /true|1|yes/i) ? 1 : 0
|
123
|
+
end
|
124
|
+
|
62
125
|
def type
|
63
126
|
@repo[@key]['type']
|
64
127
|
end
|
@@ -83,6 +146,18 @@ module Zypper
|
|
83
146
|
@repo[@key]['baseurl'] = value
|
84
147
|
end
|
85
148
|
|
149
|
+
def protocol
|
150
|
+
URI(url.to_s).scheme
|
151
|
+
end
|
152
|
+
|
153
|
+
def unversioned?
|
154
|
+
(url =~ /\d\d\.\d/).nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
def versioned?
|
158
|
+
!unversioned?
|
159
|
+
end
|
160
|
+
|
86
161
|
def alias
|
87
162
|
@key
|
88
163
|
end
|
@@ -92,7 +167,7 @@ module Zypper
|
|
92
167
|
@key = get_key
|
93
168
|
end
|
94
169
|
|
95
|
-
def upgrade(version, args = {})
|
170
|
+
def upgrade!(version, args = {})
|
96
171
|
@old_url ||= self.url
|
97
172
|
@old_alias ||= self.alias
|
98
173
|
@old_name ||= self.name
|
@@ -112,13 +187,22 @@ module Zypper
|
|
112
187
|
end
|
113
188
|
|
114
189
|
def save
|
115
|
-
raise
|
190
|
+
raise InvalidWritePermissions, @filename unless File.writable? @filename
|
191
|
+
process, pid = libzypp_process
|
192
|
+
raise SystemUpdateRunning, { pid: pid, process: process } if pid
|
116
193
|
@repo.save(@filename)
|
117
194
|
end
|
118
195
|
|
119
196
|
|
120
197
|
private
|
121
198
|
|
199
|
+
def libzypp_process
|
200
|
+
libpath = `ldd /usr/bin/zypper | grep "libzypp.so"`.split(' => ')[1].split(' ').shift
|
201
|
+
process = `sudo lsof #{libpath} | tail -n 1`
|
202
|
+
process, pid = process.split(' ')
|
203
|
+
[process, pid]
|
204
|
+
end
|
205
|
+
|
122
206
|
def get_key
|
123
207
|
@repo.to_hash.keys.delete_if {|k| k == '0'}.pop
|
124
208
|
end
|
@@ -1,196 +1,42 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
|
2
|
+
require_relative 'traversable.rb'
|
3
|
+
require_relative 'requests/local.rb'
|
4
|
+
require_relative 'requests/http.rb'
|
3
5
|
|
4
6
|
module Zypper
|
5
7
|
module Upgraderepo
|
6
8
|
|
7
9
|
|
8
|
-
class
|
10
|
+
class Request
|
9
11
|
|
10
|
-
|
12
|
+
def self.build(repo, timeout)
|
13
|
+
@@registry ||= self.load_requests
|
11
14
|
|
12
|
-
|
15
|
+
raise InvalidProtocol, repo unless @@registry.include? repo.protocol
|
13
16
|
|
14
|
-
|
15
|
-
super obj
|
16
|
-
@timeout = timeout
|
17
|
+
Object.const_get(@@registry[repo.protocol]).new(repo, timeout)
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
20
|
+
def self.protocols
|
21
|
+
self.load_requests.keys
|
21
22
|
end
|
22
23
|
|
23
|
-
def redirected?
|
24
|
-
ping.is_a?(Net::HTTPRedirection)
|
25
|
-
end
|
26
|
-
|
27
|
-
def redirected_to
|
28
|
-
ping['location']
|
29
|
-
end
|
30
|
-
|
31
|
-
def not_found?
|
32
|
-
ping.is_a?(Net::HTTPNotFound)
|
33
|
-
end
|
34
|
-
|
35
|
-
def forbidden?
|
36
|
-
ping.is_a?(Net::HTTPForbidden)
|
37
|
-
end
|
38
|
-
|
39
|
-
def timeout?
|
40
|
-
ping.is_a?(Net::HTTPRequestTimeOut)
|
41
|
-
end
|
42
|
-
|
43
|
-
def status
|
44
|
-
ping.class.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def get_request(uri, head)
|
51
|
-
uri ||= repodata_uri
|
52
|
-
|
53
|
-
if head
|
54
|
-
request = Net::HTTP::Head.new(uri.request_uri)
|
55
|
-
else
|
56
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
57
|
-
end
|
58
|
-
|
59
|
-
request['User-Agent'] = USER_AGENT
|
60
|
-
|
61
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
-
http.use_ssl = (uri.scheme == "https")
|
63
|
-
http.open_timeout = @timeout
|
64
|
-
|
65
|
-
http.request(request)
|
66
|
-
end
|
67
|
-
|
68
|
-
def ping(uri = nil, head = true)
|
69
|
-
begin
|
70
|
-
if @page.nil? || uri
|
71
|
-
@page = get_request(uri, head)
|
72
|
-
end
|
73
|
-
rescue SocketError
|
74
|
-
raise NoConnection
|
75
|
-
rescue Net::OpenTimeout
|
76
|
-
@page = Net::HTTPRequestTimeOut.new('1.1', '', '')
|
77
|
-
end
|
78
|
-
@page
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
class RepositoryRequest < PageRequest
|
85
|
-
|
86
|
-
def evaluate_alternative(version)
|
87
|
-
|
88
|
-
if not_found?
|
89
|
-
return traverse_url(URI(url), version)
|
90
|
-
elsif redirected?
|
91
|
-
return { url: redirected_to, message: 'Redirected to:' }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
24
|
private
|
97
25
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
elsif available? && uri.to_s =~ /#{version}/
|
104
|
-
res = traverse_url_forward(uri, version)
|
105
|
-
else
|
106
|
-
res = traverse_url_backward(uri, version)
|
107
|
-
end
|
108
|
-
|
109
|
-
res || { url: '', message: 'Can\'t find a valid alternative, try manually!' }
|
110
|
-
end
|
111
|
-
|
112
|
-
def traverse_url_backward(uri, version)
|
113
|
-
uri.path = File.dirname(uri.path)
|
114
|
-
|
115
|
-
return nil if uri.path == '/' || uri.path == '.'
|
116
|
-
|
117
|
-
uri.path += '/' if uri.path[-1] != '/'
|
118
|
-
ping(uri, false)
|
119
|
-
|
120
|
-
if not_found?
|
121
|
-
return traverse_url_backward(uri, version)
|
122
|
-
elsif available?
|
123
|
-
|
124
|
-
if uri.path =~ /#{version}/ && repodata?
|
125
|
-
return {url: uri.to_s, message: 'Override with this one' }
|
126
|
-
elsif res = traverse_url_forward(uri, version, !(uri.path =~ /#{version}/))
|
127
|
-
return res
|
128
|
-
else
|
129
|
-
return traverse_url_backward(uri, version)
|
130
|
-
end
|
131
|
-
|
132
|
-
elsif forbidden?
|
133
|
-
return { url: uri.to_s, message: 'Try to replace with this one' } if repodata?(uri)
|
134
|
-
|
135
|
-
return traverse_url_backward(uri, version)
|
136
|
-
end
|
137
|
-
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
|
141
|
-
def traverse_url_forward(uri, version, check_version = false)
|
142
|
-
uri.path += '/' if uri.path[-1] != '/'
|
143
|
-
ping(uri, false)
|
144
|
-
|
145
|
-
subfolders(version, check_version).each do |dir|
|
146
|
-
u = URI(uri.to_s)
|
147
|
-
u.path += dir
|
148
|
-
|
149
|
-
if repodata?(u)
|
150
|
-
return {url: u.to_s, message: 'Override with this one' }
|
151
|
-
else
|
152
|
-
res = traverse_url_forward(u, version)
|
153
|
-
return res if res.class == Hash
|
26
|
+
def self.load_requests
|
27
|
+
res = {}
|
28
|
+
Requests.constants.each do |klass|
|
29
|
+
Object.const_get("Zypper::Upgraderepo::Requests::#{klass}").register_protocol.each do |protocol|
|
30
|
+
res[protocol] = "Zypper::Upgraderepo::Requests::#{klass}"
|
154
31
|
end
|
155
32
|
end
|
156
33
|
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
|
160
|
-
def repodata_uri(uri = nil)
|
161
|
-
if uri
|
162
|
-
uri = URI(uri.to_s)
|
163
|
-
else
|
164
|
-
uri = URI(url)
|
165
|
-
end
|
166
|
-
|
167
|
-
uri.path = uri.path.gsub(/\/$/, '') + '/repodata/repomd.xml'
|
168
|
-
|
169
|
-
uri
|
170
|
-
end
|
171
|
-
|
172
|
-
def repodata?(uri = nil)
|
173
|
-
if uri.nil?
|
174
|
-
return ping.body.to_s.scan(Regexp.new("href=\"repodata/")).empty?
|
175
|
-
else
|
176
|
-
ping(repodata_uri(uri))
|
177
|
-
return available?
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def subfolders(version, check_version)
|
182
|
-
res = ping.body.to_s.scan(Regexp.new('href=[\'\"][^\/\"]+\/[\'\"]')).delete_if do |x|
|
183
|
-
x =~ /^\// || x =~ /^\.\./ || x =~ /\:\/\// || x =~ /href=[\"\'](media\.1|boot|EFI)\/[\"\']/
|
184
|
-
end.uniq.map do |d|
|
185
|
-
d.scan(/href=[\"\']([^"]+)[\'\"]/).pop.pop
|
186
|
-
end
|
187
|
-
|
188
|
-
res = res.delete_if { |x| !(x =~ /#{version}/) } if check_version
|
189
|
-
|
190
34
|
res
|
191
35
|
end
|
36
|
+
|
192
37
|
end
|
193
38
|
|
194
39
|
|
40
|
+
|
195
41
|
end
|
196
42
|
end
|