Skip to content

Commit c1707fc

Browse files
committed
feat: use SHA256SUMS to get Ubuntu release
Add URL template, replace {val} will get URL TODO: define URL func use HEAD to check link valid
1 parent d48a895 commit c1707fc

File tree

4 files changed

+76
-33
lines changed

4 files changed

+76
-33
lines changed

lib/rootfs/distro/ubuntu.rb

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@
77
module RootFS
88
module Distro
99
module Ubuntu
10+
Methods = {
11+
arch?: ARCH,
12+
edition?: EDITION,
13+
dev?: DEV,
14+
interim?: INTERIM,
15+
lts?: LTS,
16+
esm?: ESM
17+
}.freeze
18+
19+
Methods.each do |name, data|
20+
if data.instance_of?(Array)
21+
define_method(name) do |any = nil|
22+
str = any.to_s
23+
data.include?(str)
24+
end
25+
elsif data.instance_of?(Hash)
26+
define_method(name) do |any = nil|
27+
str = any.instance_of?(0.1.class) ? format("%.2f", any) : any.to_s
28+
data.each do |code, ver|
29+
return true if str == code.to_s
30+
return true if str.start_with?(ver)
31+
end
32+
false
33+
end
34+
end
35+
end
1036
end
1137
end
1238
end

lib/rootfs/distro/ubuntu/edition.rb

+19-16
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@ module RootFS
44
module Distro
55
module Ubuntu
66
# https://ubuntu.com/download
7-
87
# https://wiki.ubuntu.com/Releases
8+
99
# http://releases.ubuntu.com/
10+
# http://cdimage.ubuntu.com/
1011
# https://cloud-images.ubuntu.com/
1112

13+
EDITION = %w[
14+
desktop
15+
server
16+
base
17+
cloud
18+
minimal
19+
].freeze
20+
21+
DEV = {
22+
lunar: "23.04"
23+
}.freeze
24+
25+
INTERIM = {
26+
kinetic: "22.10"
27+
}.freeze
28+
1229
LTS = {
1330
jammy: "22.04",
1431
focal: "20.04",
@@ -20,21 +37,7 @@ module Ubuntu
2037
trusty: "14.04"
2138
}.freeze
2239

23-
DEV = {
24-
lunar: "23.04",
25-
kinetic: "22.10"
26-
}.freeze
27-
28-
CODENAME_VERSION = {}.merge(DEV, LTS, ESM).freeze
29-
30-
def lts?(any)
31-
str = any.to_s
32-
LTS.each do |code, ver|
33-
return true if str == code.to_s
34-
return true if str.start_with?(ver)
35-
end
36-
false
37-
end
40+
CODENAME_VERSION = {}.merge(DEV, INTERIM, LTS, ESM).freeze
3841
end
3942
end
4043
end

lib/rootfs/distro/ubuntu/url.rb

+22-17
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33
module RootFS
44
module Distro
55
module Ubuntu
6-
# https://ubuntu.com/download
7-
8-
# https://wiki.ubuntu.com/Releases
96
# http://releases.ubuntu.com/
7+
# http://cdimage.ubuntu.com/
108
# https://cloud-images.ubuntu.com/
119

12-
EDITION_RELEASE_URL = {
13-
Desktop: "http://cdimage.ubuntu.com/releases/",
14-
Server: "http://cdimage.ubuntu.com/releases/",
15-
Base: "http://cdimage.ubuntu.com/ubuntu-base/releases/",
16-
Cloud: "https://cloud-images.ubuntu.com/releases/",
17-
Minimal: "https://cloud-images.ubuntu.com/minimal/releases/"
18-
}.freeze
19-
20-
EDITION_DAILY_URL = {
21-
Desktop: "http://cdimage.ubuntu.com/",
22-
Server: "http://cdimage.ubuntu.com/ubuntu-server/",
23-
Base: "http://cdimage.ubuntu.com/ubuntu-base/",
24-
Cloud: "https://cloud-images.ubuntu.com/",
25-
Minimal: "https://cloud-images.ubuntu.com/minimal/daily/"
10+
EDITION_URL = {
11+
desktop: {
12+
release: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS",
13+
daily: "http://cdimage.ubuntu.com/{codename}/daily-preinstalled/current/SHA256SUMS"
14+
},
15+
server: {
16+
release: "http://cdimage.ubuntu.com/releases/{version}/release/SHA256SUMS",
17+
daily: "http://cdimage.ubuntu.com/ubuntu-server/{codename}/daily-preinstalled/current/SHA256SUMS"
18+
},
19+
base: {
20+
release: "http://cdimage.ubuntu.com/ubuntu-base/releases/{version}/release/SHA256SUMS",
21+
daily: "http://cdimage.ubuntu.com/ubuntu-base/{codename}/daily/current/SHA256SUMS"
22+
},
23+
cloud: {
24+
release: "https://cloud-images.ubuntu.com/releases/{version}/release/SHA256SUMS",
25+
daily: "https://cloud-images.ubuntu.com/{codename}/current/SHA256SUMS"
26+
},
27+
minimal: {
28+
release: "https://cloud-images.ubuntu.com/minimal/releases/{codename}/release/SHA256SUMS",
29+
daily: "https://cloud-images.ubuntu.com/minimal/daily/{codename}/current/SHA256SUMS"
30+
}
2631
}.freeze
2732
end
2833
end

lib/rootfs/distro/ubuntu_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ class MyClass
99

1010
u = MyClass.new
1111

12+
p u.arch?("armv8")
13+
p u.arch?("amd64")
14+
p u.edition?("cloud")
15+
p u.dev?(23.04)
16+
p u.dev?("lunar")
17+
p u.interim?(22.10)
18+
p u.interim?("22.10")
19+
p u.interim?("kinetic")
1220
p u.lts?("focal")
1321
p u.lts?("20.04.5")
1422
p u.lts?("20.04")
23+
p u.esm?(16.04)
1524
p u.lts?("20")
1625
p u.lts?("20.10")
1726
p MyClass::CODENAME_VERSION

0 commit comments

Comments
 (0)