Skip to content

Commit 7cc5468

Browse files
committed
feat: different url for amd64 arch
url_of support arch opt from_sha256sum improve pref by break loop files_of return hash
1 parent 1cd67ec commit 7cc5468

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed

lib/rootfs/data.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ def from_sha256sum(str, keywords, ignores = [])
2727
next unless all_matched
2828

2929
keywords.each do |keyword|
30-
all_matched = false unless file.include?(keyword)
30+
unless file.include?(keyword)
31+
all_matched = false
32+
break
33+
end
3134
end
3235
results.push(file) if all_matched
3336
end

lib/rootfs/distro/ubuntu/file.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require_relative "../../http"
44
require_relative "../../data"
5-
require_relative "arch"
65

76
module RootFS
87
module Distro
@@ -47,11 +46,6 @@ def files_of(*argv, daily: false, **opts)
4746
arch = argv[2] || opts[:arch] || "amd64"
4847
devkit = argv[3] || opts[:devkit]
4948

50-
hash = RootFS::Distro::Ubuntu.parse_arch(arch)
51-
return unless hash
52-
53-
arch = hash[:arch]
54-
5549
keywords = [edition, arch]
5650
ignores = []
5751

@@ -63,10 +57,13 @@ def files_of(*argv, daily: false, **opts)
6357
ignores = %w[wsl lxd squashfs]
6458
end
6559

66-
url = RootFS::Distro::Ubuntu.url_of(edition, release, daily)
60+
url = RootFS::Distro::Ubuntu.url_of(edition, release, daily, arch: arch)
61+
return if url.nil?
62+
6763
resp = RootFS::HTTP.get(url)
6864
body = resp.body
69-
RootFS::Data.from_sha256sum(body, keywords, ignores)
65+
files = RootFS::Data.from_sha256sum(body, keywords, ignores)
66+
{ sha256sum: url, files: files }
7067
end
7168
end
7269
end

lib/rootfs/distro/ubuntu/file_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class MyClass
1212
p u.files_of
1313
p u.files_of("desktop", 20.04)
1414
p u.files_of("desktop", 23.04)
15+
p u.files_of("desktop", "lunar")
1516
p u.files_of("server", 20.04)
1617
p u.files_of("base", 20.04)
1718
p u.files_of("base", "focal")

lib/rootfs/distro/ubuntu/url.rb

+34-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative "edition"
4+
require_relative "arch"
45

56
module RootFS
67
module Distro
@@ -13,12 +14,24 @@ module Ubuntu
1314

1415
EDITION_URL = {
1516
desktop: {
16-
release: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS",
17-
daily: "http://cdimage.ubuntu.com/{codename}/daily-preinstalled/current/SHA256SUMS"
17+
release: {
18+
amd64: "http://releases.ubuntu.com/{version}/SHA256SUMS",
19+
others: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS"
20+
},
21+
daily: {
22+
amd64: "http://cdimage.ubuntu.com/{codename}/daily-live/current/SHA256SUMS",
23+
others: "http://cdimage.ubuntu.com/{codename}/daily-preinstalled/current/SHA256SUMS"
24+
}
1825
},
1926
server: {
20-
release: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS",
21-
daily: "http://cdimage.ubuntu.com/ubuntu-server/{codename}/daily-preinstalled/current/SHA256SUMS"
27+
release: {
28+
amd64: "http://releases.ubuntu.com/{version}/SHA256SUMS",
29+
others: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS"
30+
},
31+
daily: {
32+
amd64: "http://cdimage.ubuntu.com/ubuntu-server/{codename}/daily-live/current/SHA256SUMS",
33+
others: "http://cdimage.ubuntu.com/ubuntu-server/{codename}/daily-preinstalled/current/SHA256SUMS"
34+
}
2235
},
2336
base: {
2437
release: "http://cdimage.ubuntu.com/ubuntu-base/releases/{version}/release/SHA256SUMS",
@@ -34,7 +47,7 @@ module Ubuntu
3447
}
3548
}.freeze
3649

37-
def url_of(edi, rel, daily = false)
50+
def url_of(edi, rel, daily = false, arch: "amd64")
3851
hash = RootFS::Distro::Ubuntu.parse_edition(edi)
3952
return unless hash
4053

@@ -49,8 +62,22 @@ def url_of(edi, rel, daily = false)
4962
dev = hash[:dev]
5063
daily ||= type == "codename"
5164

52-
url_tmpl = !daily ? EDITION_URL[edition.to_sym][:release] : EDITION_URL[edition.to_sym][:daily]
53-
top_dir = url_tmpl.start_with?("http://cdimage.ubuntu.com") && dev && daily
65+
hash = RootFS::Distro::Ubuntu.parse_arch(arch)
66+
return unless hash
67+
68+
arch = hash[:arch]
69+
70+
url_tmpl = if %w[desktop server].include?(edition)
71+
if arch == "amd64"
72+
!daily ? EDITION_URL[edition.to_sym][:release][:amd64] : EDITION_URL[edition.to_sym][:daily][:amd64]
73+
else
74+
!daily ? EDITION_URL[edition.to_sym][:release][:others] : EDITION_URL[edition.to_sym][:daily][:others]
75+
end
76+
else
77+
!daily ? EDITION_URL[edition.to_sym][:release] : EDITION_URL[edition.to_sym][:daily]
78+
end
79+
80+
top_dir = url_tmpl.include?("cdimage.ubuntu.com") && dev && daily
5481
codename = "" if top_dir
5582

5683
url_tmpl.gsub("{version}", version).gsub("{codename}", codename.to_s)

lib/rootfs/distro/ubuntu/url_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ class MyClass
1010
u = MyClass.new
1111

1212
p u.url_of("desktop", 20.04)
13+
p u.url_of("desktop", 20.04, arch: "arm64")
14+
p u.url_of("desktop", 20.04, true, arch: "arm64")
15+
p u.url_of("desktop", "lunar", true, arch: "arm64")
1316
p u.url_of("desktop", 23.04, true)
17+
p u.url_of("desktop", 22.04, true)
1418
p u.url_of("server", 20.04)
19+
p u.url_of("server", 20.04, true)
20+
p u.url_of("server", 20.04, arch: "arm64")
21+
p u.url_of("server", 20.04, true, arch: "arm64")
1522
p u.url_of("base", 20.04)
1623
p u.url_of("base", "focal")
1724
p u.url_of("cloud", "focal")

0 commit comments

Comments
 (0)