zypper-upgraderepo 1.4.0 → 1.6.1

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: d4760ab0872714ea6449ab9f0ece3864e26c8c240f9b11633006fb12dd817499
4
- data.tar.gz: 20adbb9f4e555758247171702c7adbd3513f94025cb4f02259b9c9fd2ed58de4
3
+ metadata.gz: d7760c0dd8fcc4192e55ad7f9334decff5dd9535ed3b04aa0158d57b4cc41b70
4
+ data.tar.gz: b908c0f8079154ca9a35fb6f961a8d5bd8cf33a7da9587a825a52897d3fed8d4
5
5
  SHA512:
6
- metadata.gz: 8450283c28d80056aa8f9bc7c97f40e7778a728b200b04dacf38cd3697ab76da59332314f4de5d23328e11283d9365088d9d212cb5cfdab837b2954d306cb87e
7
- data.tar.gz: 478fdd3fa080ae63049b077bc8ddf73a5d1d87655da3a1c17f0588c944766b09aba44b5f6b62ecbdd62cc641e7dcf0486a4a45ae25e04773502c3c99acc8546f
6
+ metadata.gz: 74cbaff92a3951970ed4ba52f51bc4b0345c419f82f5cd4d25a8345dbf3bd27b79300752232ce549cbdce912b88ae2829c6fa1e8da8a7ea5a8d8687d4210e246
7
+ data.tar.gz: 2ebe8a63c1e2c5255a80c5ec99b2079f8b86f0ae9f892d9e48e22dac22d84f146391a0ade675108948d53ec4125d4127f5bc8e1f0f788a2a63dfe7121a0cda1f
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.4.0)
4
+ zypper-upgraderepo (1.6.1)
5
5
  iniparse
6
6
  minitar
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- diff-lcs (1.4.4)
11
+ diff-lcs (1.5.0)
12
12
  iniparse (1.5.0)
13
13
  minitar (0.9)
14
- rake (13.0.1)
15
- rspec (3.9.0)
16
- rspec-core (~> 3.9.0)
17
- rspec-expectations (~> 3.9.0)
18
- rspec-mocks (~> 3.9.0)
19
- rspec-core (3.9.2)
20
- rspec-support (~> 3.9.3)
21
- rspec-expectations (3.9.2)
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.9.0)
24
- rspec-mocks (3.9.1)
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.9.0)
27
- rspec-support (3.9.3)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-support (3.10.3)
28
28
 
29
29
  PLATFORMS
30
30
  ruby
@@ -36,4 +36,4 @@ DEPENDENCIES
36
36
  zypper-upgraderepo!
37
37
 
38
38
  BUNDLED WITH
39
- 2.1.4
39
+ 2.2.19
@@ -26,6 +26,8 @@ module Zypper
26
26
  options.exit_on_fail = false
27
27
  options.overrides_filename = nil
28
28
  options.only_invalid = false
29
+ options.only_protocols = nil
30
+ options.allow_unstable = false
29
31
 
30
32
  opt_parser = OptionParser.new do |opt|
31
33
 
@@ -48,21 +50,25 @@ module Zypper
48
50
  options.operation = :check_current
49
51
  end
50
52
 
51
- opt.on('-N', '--check-next', 'Check the repositories for the next version') do |o|
53
+ opt.on('-n', '--check-next', 'Check the repositories for the next version') do |o|
52
54
  options.operation = :check_next
53
55
  end
54
56
 
55
- opt.on('-C', '--check-to <VERSION>', 'Check for a custom VERSION') do |v|
57
+ opt.on('-C', '--check-for <VERSION>', 'Check for a custom VERSION') do |v|
56
58
  options.version = v
57
- options.operation = :check_to
59
+ options.operation = :check_for
60
+ end
61
+
62
+ opt.on('-l', '--check-last', 'Check the repositories for the last version') do |o|
63
+ options.operation = :check_last
58
64
  end
59
65
 
60
66
  opt.on('-R', '--reset', 'Reset the repositories to the current OS version.') do |v|
61
67
  options.operation = :reset
62
68
  end
63
69
 
64
- opt.on('-u', '--upgrade', 'Upgrade to the last version available') do |o|
65
- options.operation = :upgrade
70
+ opt.on('-u', '--upgrade', 'Upgrade to the next version available') do |o|
71
+ options.operation = :upgrade_to_next
66
72
  end
67
73
 
68
74
  opt.on('-U', '--upgrade-to <VERSION>', 'Upgrade to a specific VERSION') do |v|
@@ -70,9 +76,21 @@ module Zypper
70
76
  options.operation = :upgrade_to
71
77
  end
72
78
 
79
+ opt.on('-L', '--upgrade-to-last', 'Upgrade to the last version available') do |o|
80
+ options.operation = :upgrade_to_last
81
+ end
82
+
83
+ opt.on('-s', '--status', 'Prints the version status of the current and available releases') do |o|
84
+ options.operation = :status
85
+ end
86
+
73
87
  opt.separator ''
74
88
  opt.separator 'Options:'
75
89
 
90
+ opt.on('--allow-unstable', 'Consider the unstable version as a valid release version') do |o|
91
+ options.allow_unstable = true
92
+ end
93
+
76
94
  opt.on('--no-name', 'Don\'t upgrade the name') do |o|
77
95
  options.name = false
78
96
  end
@@ -116,6 +134,10 @@ module Zypper
116
134
  options.only_invalid = true
117
135
  end
118
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
+
119
141
  opt.separator ''
120
142
  opt.separator 'View options:'
121
143
 
@@ -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', '15.2']
11
+ OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1', '15.2', '15.3', '15.4']
12
12
 
13
+ UNSTABLE_VERSION = '15.5'
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
@@ -16,12 +16,13 @@ module Zypper
16
16
  @only_repo = options.only_repo
17
17
  @only_enabled = options.only_enabled
18
18
  @only_invalid = options.only_invalid
19
+ @only_protocols = options.only_protocols
19
20
  @overrides = options.overrides
20
21
  @upgrade_options = {alias: options.alias, name: options.name}
21
22
  @list = []
22
23
 
23
24
  Dir.glob(File.join(REPOSITORY_PATH, '*.repo')).each do |i|
24
- r = RepositoryRequest.new(Repository.new(i), options.timeout)
25
+ r = Request.build(Repository.new(i), options.timeout)
25
26
  @list << r
26
27
  end
27
28
  @max_col = @list.max_by { |r| r.name.length }.name.length
@@ -48,19 +49,33 @@ module Zypper
48
49
  only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
49
50
  only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
50
51
  only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
52
+ only_protocols = options[:only_protocols].nil? ? @only_protocols : options[:only_protocols]
51
53
 
52
54
  @list.each do |x|
53
55
  next if only_repo && !only_repo.include?(x[:num])
54
56
  next if only_enabled && !x[:repo].enabled?
55
57
  next if only_invalid && x[:repo].available?
58
+ next if only_protocols && (!only_protocols.include?(x[:repo].protocol))
56
59
 
57
60
  yield x[:repo], x[:num] if block_given?
58
61
  end
59
62
  end
60
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
+
61
76
  def save
62
77
  @list.each do |i|
63
- i.save
78
+ i[:repo].save
64
79
  end
65
80
  end
66
81
 
@@ -131,6 +146,18 @@ module Zypper
131
146
  @repo[@key]['baseurl'] = value
132
147
  end
133
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
+
134
161
  def alias
135
162
  @key
136
163
  end
@@ -1,200 +1,42 @@
1
1
  require 'delegate'
2
- require 'net/http'
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 PageRequest < SimpleDelegator
10
+ class Request
9
11
 
10
- attr_reader :page
12
+ def self.build(repo, timeout)
13
+ @@registry ||= self.load_requests
11
14
 
12
- USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0'
15
+ raise InvalidProtocol, repo unless @@registry.include? repo.protocol
13
16
 
14
- def initialize(obj, timeout = 60)
15
- super obj
16
- @timeout = timeout
17
+ Object.const_get(@@registry[repo.protocol]).new(repo, timeout)
17
18
  end
18
19
 
19
- def available?
20
- ping.is_a?(Net::HTTPSuccess)
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
- def cache!
48
- @page = nil
49
- end
50
-
51
-
52
- private
53
-
54
- def get_request(uri, head)
55
- uri ||= repodata_uri
56
-
57
- if head
58
- request = Net::HTTP::Head.new(uri.request_uri)
59
- else
60
- request = Net::HTTP::Get.new(uri.request_uri)
61
- end
62
-
63
- request['User-Agent'] = USER_AGENT
64
-
65
- http = Net::HTTP.new(uri.host, uri.port)
66
- http.use_ssl = (uri.scheme == "https")
67
- http.open_timeout = @timeout
68
-
69
- http.request(request)
70
- end
71
-
72
- def ping(uri = nil, head = true)
73
- begin
74
- if @page.nil? || uri
75
- @page = get_request(uri, head)
76
- end
77
- rescue SocketError
78
- raise NoConnection
79
- rescue Net::OpenTimeout
80
- @page = Net::HTTPRequestTimeOut.new('1.1', '', '')
81
- end
82
- @page
83
- end
84
-
85
- end
86
-
87
-
88
- class RepositoryRequest < PageRequest
89
-
90
- def evaluate_alternative(version)
91
-
92
- if not_found?
93
- return traverse_url(URI(url), version)
94
- elsif redirected?
95
- return { url: redirected_to, message: 'Redirected to:' }
96
- end
97
- end
98
-
99
-
100
24
  private
101
25
 
102
- def traverse_url(uri, version)
103
- ping(uri)
104
-
105
- if forbidden?
106
- res = { url: url, message: 'Can\'t navigate through the repository!' }
107
- elsif available? && uri.to_s =~ /#{version}/
108
- res = traverse_url_forward(uri, version)
109
- else
110
- res = traverse_url_backward(uri, version)
111
- end
112
-
113
- res || { url: '', message: 'Can\'t find a valid alternative, try manually!' }
114
- end
115
-
116
- def traverse_url_backward(uri, version)
117
- uri.path = File.dirname(uri.path)
118
-
119
- return nil if uri.path == '/' || uri.path == '.'
120
-
121
- uri.path += '/' if uri.path[-1] != '/'
122
- ping(uri, false)
123
-
124
- if not_found?
125
- return traverse_url_backward(uri, version)
126
- elsif available?
127
-
128
- if uri.path =~ /#{version}/ && repodata?
129
- return {url: uri.to_s, message: 'Override with this one' }
130
- elsif res = traverse_url_forward(uri, version, !(uri.path =~ /#{version}/))
131
- return res
132
- else
133
- return traverse_url_backward(uri, version)
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}"
134
31
  end
135
-
136
- elsif forbidden?
137
- return { url: uri.to_s, message: 'Try to replace with this one' } if repodata?(uri)
138
-
139
- return traverse_url_backward(uri, version)
140
32
  end
141
33
 
142
- nil
143
- end
144
-
145
- def traverse_url_forward(uri, version, check_version = false)
146
- uri.path += '/' if uri.path[-1] != '/'
147
- ping(uri, false)
148
-
149
- subfolders(version, check_version).each do |dir|
150
- u = URI(uri.to_s)
151
- u.path += dir
152
-
153
- if repodata?(u)
154
- return {url: u.to_s, message: 'Override with this one' }
155
- else
156
- res = traverse_url_forward(u, version)
157
- return res if res.class == Hash
158
- end
159
- end
160
-
161
- nil
162
- end
163
-
164
- def repodata_uri(uri = nil)
165
- if uri
166
- uri = URI(uri.to_s)
167
- else
168
- uri = URI(url)
169
- end
170
-
171
- uri.path = uri.path.gsub(/\/$/, '') + '/repodata/repomd.xml'
172
-
173
- uri
174
- end
175
-
176
- def repodata?(uri = nil)
177
- if uri.nil?
178
- return ping.body.to_s.scan(Regexp.new("href=\"repodata/")).empty?
179
- else
180
- ping(repodata_uri(uri))
181
- return available?
182
- end
183
- end
184
-
185
- def subfolders(version, check_version)
186
- res = ping.body.to_s.scan(Regexp.new('href=[\'\"][^\/\"]+\/[\'\"]')).delete_if do |x|
187
- x =~ /^\// || x =~ /^\.\./ || x =~ /\:\/\// || x =~ /href=[\"\'](media\.1|boot|EFI)\/[\"\']/
188
- end.uniq.map do |d|
189
- d.scan(/href=[\"\']([^"]+)[\'\"]/).pop.pop
190
- end
191
-
192
- res = res.delete_if { |x| !(x =~ /#{version}/) } if check_version
193
-
194
34
  res
195
35
  end
36
+
196
37
  end
197
38
 
198
39
 
40
+
199
41
  end
200
42
  end
@@ -0,0 +1,131 @@
1
+ require 'delegate'
2
+ require 'net/http'
3
+
4
+ module Zypper
5
+ module Upgraderepo
6
+
7
+ class PageRequest < SimpleDelegator
8
+
9
+ attr_reader :page
10
+
11
+ USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0'
12
+
13
+ def initialize(obj, timeout = 60)
14
+ super obj
15
+ @timeout = timeout
16
+ end
17
+
18
+ def available?
19
+ ping.is_a?(Net::HTTPSuccess)
20
+ end
21
+
22
+ def redirected?
23
+ ping.is_a?(Net::HTTPRedirection)
24
+ end
25
+
26
+ def redirected_to
27
+ ping['location']
28
+ end
29
+
30
+ def not_found?
31
+ ping.is_a?(Net::HTTPNotFound)
32
+ end
33
+
34
+ def forbidden?
35
+ ping.is_a?(Net::HTTPForbidden)
36
+ end
37
+
38
+ def timeout?
39
+ ping.is_a?(Net::HTTPRequestTimeOut)
40
+ end
41
+
42
+ def status
43
+ ping.class.to_s
44
+ end
45
+
46
+ def cache!
47
+ @page = nil
48
+ end
49
+
50
+
51
+ private
52
+
53
+ def get_request(uri, head)
54
+
55
+ if head
56
+ request = Net::HTTP::Head.new(uri.request_uri)
57
+ else
58
+ request = Net::HTTP::Get.new(uri.request_uri)
59
+ end
60
+
61
+ request['User-Agent'] = USER_AGENT
62
+
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = (uri.scheme == 'https')
65
+ http.open_timeout = @timeout
66
+
67
+ http.request(request)
68
+ end
69
+
70
+ def ping(uri = nil, head = true)
71
+ begin
72
+ if @page.nil? || uri
73
+ @page = get_request(uri, head)
74
+ end
75
+ rescue SocketError
76
+ raise NoConnection
77
+ rescue Net::OpenTimeout
78
+ @page = Net::HTTPRequestTimeOut.new('1.1', '', '')
79
+ end
80
+ @page
81
+ end
82
+
83
+ end
84
+
85
+
86
+ module Requests
87
+
88
+ class HttpRequest < PageRequest
89
+
90
+ include Traversable
91
+
92
+ def max_drop_back; 0; end
93
+
94
+ def self.register_protocol; ['https', 'http'] end
95
+
96
+ def evaluate_alternative(version)
97
+ if not_found?
98
+ return traverse_url(URI(url), version)
99
+ elsif redirected?
100
+ return { url: redirected_to, message: 'Redirected to:' }
101
+ end
102
+ end
103
+
104
+
105
+ private
106
+
107
+ def get_request(uri, head)
108
+ #super uri || URI(url), head
109
+ super uri || repodata_uri, head
110
+ end
111
+
112
+ def has_repodata?(uri)
113
+ ping(repodata_uri(uri))
114
+ available?
115
+ end
116
+
117
+ def subfolders
118
+ res = ping.body.to_s.scan(Regexp.new('href=[\'\"][^\/\"]+\/[\'\"]')).delete_if do |x|
119
+ x =~ /^\// || x =~ /^\.\./ || x =~ /\:\/\// || x =~ /href=[\"\'](media\.1|boot|EFI)\/[\"\']/
120
+ end.uniq.map do |d|
121
+ d.scan(/href=[\"\']([^"]+)[\'\"]/).pop.pop
122
+ end
123
+
124
+ res
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,94 @@
1
+ require 'delegate'
2
+
3
+ module Zypper
4
+ module Upgraderepo
5
+
6
+
7
+ class DirRequest < SimpleDelegator
8
+
9
+ attr_reader :dir_path
10
+
11
+ def initialize(obj, timeout)
12
+ super obj
13
+ end
14
+
15
+ def available?
16
+ Dir.exist? ping
17
+ end
18
+
19
+ def redirected?
20
+ File.symlink? ping
21
+ end
22
+
23
+ def redirected_to
24
+ File.realpath ping
25
+ end
26
+
27
+ def not_found?
28
+ !available?
29
+ end
30
+
31
+ def forbidden?
32
+ File.readable? ping
33
+ end
34
+
35
+ def timeout?
36
+ false
37
+ end
38
+
39
+ def status
40
+ File.stat ping
41
+ end
42
+
43
+ def cache!
44
+ @dir_path = nil
45
+ end
46
+
47
+
48
+ private
49
+
50
+ def ping(uri = nil, head = true)
51
+ @dir_path ||= URI(url).path
52
+
53
+ @dir_path = uri.to_s =~ /^\// ? uri.to_s : URI(uri.to_s).path if uri
54
+
55
+ URI.unescape(@dir_path)
56
+ end
57
+
58
+ end
59
+
60
+
61
+ module Requests
62
+
63
+ class LocalRequest < DirRequest
64
+
65
+ include Traversable
66
+
67
+ def max_drop_back; 1 end
68
+
69
+ def self.register_protocol; ['dir'] end
70
+
71
+ def evaluate_alternative(version)
72
+ if not_found?
73
+ return traverse_url(URI(url), version)
74
+ elsif redirected?
75
+ return { url: redirected_to, message: 'Linked to' }
76
+ end
77
+ end
78
+
79
+
80
+ private
81
+
82
+ def has_repodata?(uri)
83
+ File.exist? URI.unescape(repodata_uri(uri).path)
84
+ end
85
+
86
+ def subfolders
87
+ Dir.glob(ping.gsub(/\/$/, '') + '/*/').map { |x| URI.escape(x.gsub(/\/$/, '').gsub(ping, '').gsub(/^\//, '')) }
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,93 @@
1
+ module Zypper
2
+ module Upgraderepo
3
+
4
+ module Traversable
5
+
6
+ def traverse_url(uri, version)
7
+ ping(uri)
8
+
9
+ if forbidden?
10
+ res = { url: url, message: 'Can\'t navigate through the repository!' }
11
+ elsif available? && uri.to_s =~ /#{version}/
12
+ res = traverse_url_forward(uri, version)
13
+ else
14
+ res = traverse_url_backward(uri, version)
15
+ end
16
+
17
+ res || { url: '', message: 'Can\'t find a valid alternative, try manually!' }
18
+ end
19
+
20
+
21
+ private
22
+
23
+ def traverse_url_backward(uri, version)
24
+ uri.path = File.dirname(uri.path)
25
+
26
+ return nil if uri.path == '/' || uri.path == '.' || (versioned? && (drop_back_level(uri) > max_drop_back))
27
+
28
+ uri.path += '/' if uri.path[-1] != '/'
29
+ ping(uri, false)
30
+
31
+ if not_found?
32
+ return traverse_url_backward(uri, version)
33
+ elsif available?
34
+ if res = traverse_url_forward(uri, version)
35
+ return res
36
+ else
37
+ return traverse_url_backward(uri, version)
38
+ end
39
+ elsif forbidden?
40
+ return { url: uri.to_s, message: 'Try to replace with this one' } if has_repodata?(uri)
41
+
42
+ return traverse_url_backward(uri, version)
43
+ end
44
+
45
+ nil
46
+ end
47
+
48
+ def traverse_url_forward(uri, version)
49
+ uri.path += '/' if uri.path[-1] != '/'
50
+ ping(uri, false)
51
+
52
+ subfolders.each do |dir|
53
+ u = URI(uri.to_s)
54
+ u.path += dir
55
+
56
+ if has_repodata?(u)
57
+ if (versioned?) && (u.to_s =~ /#{version}/)
58
+ return { url: u.to_s, message: 'Override with this one' }
59
+ end
60
+ else
61
+ res = traverse_url_forward(u, version)
62
+ return res if res.class == Hash
63
+ end
64
+ end
65
+
66
+ nil
67
+ end
68
+
69
+ def repodata_uri(uri = nil)
70
+ if uri
71
+ uri = URI(uri.to_s)
72
+ else
73
+ uri = URI(url)
74
+ end
75
+
76
+ uri.path = uri.path.gsub(/\/$/, '') + '/repodata/repomd.xml'
77
+
78
+ uri
79
+ end
80
+
81
+ def drop_back_level(uri)
82
+ URI(url).path.split('/').index { |x| x =~ /\d\d.\d/ } - uri.path.split('/').count
83
+ end
84
+
85
+ # to implement on each repository type class
86
+ #
87
+ # def has_repodata?(uri)
88
+ #
89
+ # def subfolders
90
+
91
+ end
92
+ end
93
+ end
@@ -65,6 +65,12 @@ module Zypper
65
65
  end
66
66
  end
67
67
 
68
+ class InvalidProtocol < StandardError
69
+ def initialize(repo)
70
+ super "The repository #{repo.name} has an unknown protocol: #{repo.protocol}; disable it to continue."
71
+ end
72
+ end
73
+
68
74
  class InvalidVersion < StandardError
69
75
  def initialize(version)
70
76
  super "The version #{version} is not valid"
@@ -131,6 +137,16 @@ module Zypper
131
137
  end
132
138
  end
133
139
 
140
+ class NoUnstableVersionAvailable < StandardError
141
+ def initialize
142
+ super 'No unstable version is available, remove the --allow-unstable switch to continue'
143
+ end
144
+
145
+ def error_code
146
+ 11
147
+ end
148
+ end
149
+
134
150
  class NoConnection < StandardError
135
151
  def initialize
136
152
  super 'Internet connection has some trouble'
@@ -1,5 +1,5 @@
1
1
  module Zypper
2
2
  module Upgraderepo
3
- VERSION = "1.4.0"
3
+ VERSION = "1.6.1"
4
4
  end
5
5
  end
@@ -7,6 +7,7 @@ module Zypper
7
7
 
8
8
  def self.available(num, repo, max_col)
9
9
  puts " #{num.to_s.rjust(2).bold.green} | Status: #{'Ok'.bold.green}"
10
+ puts " #{' ' * 2} | Hint: Unversioned repository" if repo.unversioned? && repo.old_url
10
11
  self.info(repo)
11
12
  end
12
13
 
@@ -55,6 +56,17 @@ module Zypper
55
56
  self.separator
56
57
  end
57
58
 
59
+ def self.status(os_release)
60
+ color = os_release.seniority == 0 ? :green : :yellow
61
+ puts '----------------------------------------------'
62
+ puts "Full name | #{os_release.fullname.bold}"
63
+ puts '----------------------------------------------'
64
+ puts "Current release | #{os_release.current.send(color)}"
65
+ puts "Next release | #{os_release.seniority > 0 ? os_release.next.bold.green : '-'}"
66
+ puts "Last release | #{os_release.last.send(os_release.unstable ? :red : :clean)} (#{os_release.unstable ? 'Unstable'.bold.red : 'Stable'.bold.green})"
67
+ puts "Available | #{os_release.seniority > 0 ? os_release.newer.map{ |i| i.bold }.join(', ') : '-' }"
68
+ puts '----------------------------------------------'
69
+ end
58
70
 
59
71
  private
60
72
 
@@ -73,7 +85,11 @@ module Zypper
73
85
  class Table
74
86
 
75
87
  def self.available(num, repo, max_col)
76
- Messages.ok("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} |")
88
+ if repo.unversioned? && repo.old_url
89
+ Messages.ok("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} | Unversioned repository")
90
+ else
91
+ Messages.ok("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} |")
92
+ end
77
93
  end
78
94
 
79
95
  def self.redirected(num, repo, max_col, redirected)
@@ -114,6 +130,17 @@ module Zypper
114
130
  def self.footer
115
131
  self.separator
116
132
  end
133
+
134
+ def self.status(os_release)
135
+ puts "---------------------------------------------------"
136
+ puts " System releases based on #{os_release.fullname.bold}"
137
+ puts "---------------------------------------------------"
138
+ puts " Current | Next | Last | Available"
139
+ puts "--------------------------------------------------"
140
+ puts " #{os_release.current} | #{os_release.seniority > 0 ? os_release.next.bold.green : ' - ' } | #{os_release.last.send(os_release.unstable ? :red : :clean)} | #{os_release.seniority > 0 ? os_release.newer.join(', ') : '-'}"
141
+ puts "--------------------------------------------------"
142
+ Messages.warning "The #{'last'.bold.red} version should be considered #{'Unstable'.bold.red}" if os_release.unstable
143
+ end
117
144
  end
118
145
 
119
146
 
@@ -149,6 +176,10 @@ module Zypper
149
176
  def self.footer
150
177
  end
151
178
 
179
+ def self.status(os_release)
180
+ puts os_release.seniority.to_s + ' ' + os_release.newer.join(' ')
181
+ end
182
+
152
183
  end
153
184
 
154
185
 
@@ -195,6 +226,15 @@ module Zypper
195
226
  def self.footer
196
227
  end
197
228
 
229
+ def self.status(os_release)
230
+ puts '[os_release]'
231
+ puts "name=#{os_release.fullname}"
232
+ puts "current=#{os_release.current}"
233
+ puts "next=#{os_release.next}"
234
+ puts "last=#{os_release.last}"
235
+ puts "available=#{os_release.newer.join(' ')}"
236
+ puts "allow_unstable=#{os_release.unstable}"
237
+ end
198
238
 
199
239
  private
200
240
 
@@ -203,8 +243,16 @@ module Zypper
203
243
  puts "[repository_#{num}]"
204
244
  puts "name=#{repo.name}"
205
245
  puts "alias=#{repo.alias}"
206
- puts "old_url=#{repo.old_url}"
246
+ puts "old_url=#{repo.old_url}" if repo.upgraded?
207
247
  if valid
248
+ if repo.unversioned? && repo.old_url
249
+ puts <<-'HEADER'.gsub(/^ +/, '')
250
+ # The repository is unversioned: its packages should be perfectly
251
+ # working regardless the distribution version, that because all the
252
+ # required dependencies are included in the repository itself and
253
+ # automatically picked up.
254
+ HEADER
255
+ end
208
256
  puts "url=#{repo.url}"
209
257
  elsif repo.enabled?
210
258
  puts <<-'HEADER'.gsub(/^ +/, '')
@@ -13,7 +13,7 @@ module Zypper
13
13
  class Builder
14
14
  def initialize(options)
15
15
  @os_release = OsRelease.new(options)
16
- @repos = RepositoryList.new(options)
16
+ @repos = RepositoryList.new(options).resolve_variables!(@os_release.current)
17
17
  @print_hint = options.hint
18
18
  @view_class = Zypper::Upgraderepo::View.const_get options.view.to_s.capitalize
19
19
 
@@ -42,12 +42,18 @@ module Zypper
42
42
  check_repos(@os_release.next)
43
43
  end
44
44
 
45
- def check_to
45
+ def check_for
46
46
  @repos.upgrade!(@os_release.custom)
47
47
  check_repos(@os_release.custom)
48
48
  end
49
49
 
50
- def upgrade
50
+ def check_last
51
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
52
+ @repos.upgrade!(@os_release.last)
53
+ check_repos(@os_release.last)
54
+ end
55
+
56
+ def upgrade_to_next
51
57
  raise AlreadyUpgraded, 'latest' if @os_release.last?
52
58
  @repos.upgrade!(@os_release.next)
53
59
  upgrade_repos(@os_release.next)
@@ -59,10 +65,19 @@ module Zypper
59
65
  upgrade_repos(@os_release.custom)
60
66
  end
61
67
 
68
+ def upgrade_to_last
69
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
70
+ @repos.upgrade!(@os_release.last)
71
+ upgrade_repos(@os_release.last)
72
+ end
73
+
62
74
  def reset
63
75
  upgrade_repos(@os_release.current)
64
76
  end
65
77
 
78
+ def status
79
+ @view_class.status(@os_release)
80
+ end
66
81
 
67
82
  private
68
83
 
@@ -1,40 +1,40 @@
1
1
 
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "zypper/upgraderepo/version"
4
+ require 'zypper/upgraderepo/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "zypper-upgraderepo"
7
+ spec.name = 'zypper-upgraderepo'
8
8
  spec.version = Zypper::Upgraderepo::VERSION
9
- spec.authors = ["Fabio Mucciante"]
10
- spec.email = ["fabio.mucciante@gmail.com"]
9
+ spec.authors = ['Fabio Mucciante']
10
+ spec.email = ['fabio.mucciante@gmail.com']
11
11
 
12
12
  spec.summary = %q{Zypper addon to check and upgrade local repositories.}
13
13
  spec.description = %q{This is just a complement to zypper command which helps to upgrade the local repositories before executing zypper dup.}
14
- spec.homepage = "https://github.com/fabiomux/zypper-upgraderepo"
15
- spec.license = "GPL-3.0"
14
+ spec.homepage = 'https://github.com/fabiomux/zypper-upgraderepo'
15
+ spec.license = 'GPL-3.0'
16
16
 
17
17
  spec.metadata = {
18
- "bug_tracker_uri" => "https://github.com/fabiomux/zypper-upgraderepo/issues",
19
- #"changelog_uri" => "",
18
+ "bug_tracker_uri" => 'https://github.com/fabiomux/zypper-upgraderepo/issues',
19
+ "changelog_uri" => 'https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog',
20
20
  "documentation_uri" => "https://www.rubydoc.info/gems/zypper-upgraderepo/#{spec.version}",
21
- "homepage_uri" => "https://github.com/fabiomux/zypper-upgraderepo",
22
- #"mailing_list_uri" => "",
23
- "source_code_uri" => "https://github.com/fabiomux/zypper-upgraderepo",
24
- "wiki_uri" => "https://github.com/fabiomux/zypper-upgraderepo/wiki"
21
+ "homepage_uri" => 'https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html',
22
+ #"mailing_list_uri" => '',
23
+ "source_code_uri" => 'https://github.com/fabiomux/zypper-upgraderepo',
24
+ "wiki_uri" => 'https://github.com/fabiomux/zypper-upgraderepo/wiki'
25
25
  }
26
26
 
27
27
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features)/})
28
+ f.match(%r{^(test|spec|features|.github)/|(.gitignore|.travis.yml|CODE_OF_CONDUCT.md)$})
29
29
  end
30
- spec.bindir = "exe"
30
+ spec.bindir = 'exe'
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
32
+ spec.require_paths = ['lib']
33
33
 
34
- spec.add_development_dependency "bundler", "~> 2.0"
35
- spec.add_development_dependency "rake", "~> 13.0"
36
- spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency 'bundler', '~> 2.0'
35
+ spec.add_development_dependency 'rake', '~> 13.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
37
 
38
- spec.add_runtime_dependency "iniparse"
39
- spec.add_runtime_dependency "minitar"
38
+ spec.add_runtime_dependency 'iniparse'
39
+ spec.add_runtime_dependency 'minitar'
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zypper-upgraderepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Mucciante
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2022-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,11 +89,7 @@ executables:
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - ".github/FUNDING.yml"
93
- - ".gitignore"
94
92
  - ".rspec"
95
- - ".travis.yml"
96
- - CODE_OF_CONDUCT.md
97
93
  - Gemfile
98
94
  - Gemfile.lock
99
95
  - LICENSE
@@ -107,6 +103,9 @@ files:
107
103
  - lib/zypper/upgraderepo/os_release.rb
108
104
  - lib/zypper/upgraderepo/repository.rb
109
105
  - lib/zypper/upgraderepo/request.rb
106
+ - lib/zypper/upgraderepo/requests/http.rb
107
+ - lib/zypper/upgraderepo/requests/local.rb
108
+ - lib/zypper/upgraderepo/traversable.rb
110
109
  - lib/zypper/upgraderepo/utils.rb
111
110
  - lib/zypper/upgraderepo/version.rb
112
111
  - lib/zypper/upgraderepo/view.rb
@@ -116,8 +115,9 @@ licenses:
116
115
  - GPL-3.0
117
116
  metadata:
118
117
  bug_tracker_uri: https://github.com/fabiomux/zypper-upgraderepo/issues
119
- documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.4.0
120
- homepage_uri: https://github.com/fabiomux/zypper-upgraderepo
118
+ changelog_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog
119
+ documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.6.1
120
+ homepage_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html
121
121
  source_code_uri: https://github.com/fabiomux/zypper-upgraderepo
122
122
  wiki_uri: https://github.com/fabiomux/zypper-upgraderepo/wiki
123
123
  post_install_message:
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.0.8
138
+ rubygems_version: 3.2.19
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Zypper addon to check and upgrade local repositories.
data/.github/FUNDING.yml DELETED
@@ -1,13 +0,0 @@
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/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.5
5
- before_install: gem install bundler -v 1.16.1
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at fabio.mucciante@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/