Skip to content

Commit 22c51a5

Browse files
committed
feat: add Debian module to project
1 parent 0544035 commit 22c51a5

File tree

8 files changed

+406
-0
lines changed

8 files changed

+406
-0
lines changed

lib/rootfs/distro/debian.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../http"
4+
require_relative "../data"
5+
require_relative "debian/arch"
6+
require_relative "debian/file"
7+
require_relative "debian/url"
8+
require_relative "debian/version"
9+
10+
module RootFS
11+
module Distro
12+
module Debian
13+
end
14+
end
15+
end

lib/rootfs/distro/debian/arch.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Debian
8+
extend self
9+
10+
# https://www.debian.org/ports/
11+
# https://cdimage.debian.org/cdimage/release/current/
12+
# https://doi-janky.infosiftr.net/job/tianon/job/debuerreotype/
13+
ARCH = %w[
14+
amd64
15+
arm64
16+
armel
17+
armhf
18+
i386
19+
mips64el
20+
mipsel
21+
ppc64el
22+
riscv64
23+
s390x
24+
].freeze
25+
26+
def parse_arch(any)
27+
RootFS::Parse._str_in_arr(any, "Debian", "arch", ARCH)
28+
end
29+
end
30+
end
31+
end

lib/rootfs/distro/debian/file.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../debian"
4+
5+
module RootFS
6+
module Distro
7+
module Debian
8+
extend self
9+
10+
def files_of(edition = "netinst", release = "11.6.0", build: "release", arch: "amd64")
11+
url = RootFS::Distro::Debian.url_of(edition, release, build: build, arch: arch)
12+
return if url.nil?
13+
14+
if %w[docker slim].include?(edition)
15+
file = url.split("/").last.delete_suffix(".sha256")
16+
return { sha256sum: url, files: [file] }
17+
end
18+
19+
keywords = if edition == "desktop"
20+
[arch, ".iso"]
21+
elsif edition == "cloud"
22+
[arch, "generic-", ".tar.xz"]
23+
else
24+
[arch]
25+
end
26+
ignores = %w[edu mac]
27+
28+
resp = RootFS::HTTP.get(url)
29+
body = resp.body
30+
files = RootFS::Data.from_sha256sum(body, keywords, ignores)
31+
{ sha256sum: url, files: files }
32+
end
33+
end
34+
end
35+
end

lib/rootfs/distro/debian/file_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "file"
4+
5+
class MyClass
6+
extend RootFS::Distro::Debian
7+
include RootFS::Distro::Debian
8+
end
9+
10+
u = MyClass.new
11+
12+
p u.files_of
13+
p u.files_of("netinst", "11.6.0")
14+
p u.files_of("netinst", "11")
15+
p u.files_of("netinst", "11")
16+
p u.files_of("netinst", "daily")
17+
p u.files_of("netinst", "weekly")
18+
p u.files_of("desktop", "11.6.0")
19+
p u.files_of("desktop", "weekly")
20+
p u.files_of("cloud", "11.6.0")
21+
p u.files_of("cloud", "daily")
22+
p u.files_of("docker", "11.6.0", build: "daily")
23+
p u.files_of("slim", "11.6.0", build: "daily")
24+
p u.files_of("docker", :unstable, build: "daily")

lib/rootfs/distro/debian/url.rb

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../debian"
4+
5+
module RootFS
6+
module Distro
7+
module Debian
8+
extend self
9+
10+
# https://cdimage.debian.org/cdimage/
11+
# https://doi-janky.infosiftr.net/job/tianon/job/debuerreotype/
12+
13+
EDITION_URL = {
14+
netinst: {
15+
testing: {
16+
release: "https://cdimage.debian.org/cdimage/bookworm_di_alpha2/{arch}/iso-cd/SHA256SUMS",
17+
daily: "https://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/{arch}/iso-cd/SHA256SUMS",
18+
weekly: "https://cdimage.debian.org/cdimage/weekly-builds/{arch}/iso-cd/SHA256SUMS"
19+
},
20+
stable: {
21+
release: "https://cdimage.debian.org/cdimage/release/current/{arch}/iso-cd/SHA256SUMS"
22+
},
23+
archive: "https://cdimage.debian.org/cdimage/archive/{version}/{arch}/iso-cd/SHA256SUMS"
24+
},
25+
desktop: {
26+
testing: {
27+
weekly: "https://cdimage.debian.org/cdimage/weekly-live-builds/{arch}/iso-hybrid/SHA256SUMS"
28+
},
29+
stable: {
30+
release: "https://cdimage.debian.org/cdimage/release/current-live/{arch}/iso-hybrid/SHA256SUMS"
31+
},
32+
archive: "https://cdimage.debian.org/cdimage/archive/{version}-live/{arch}/iso-hybrid/SHA256SUMS"
33+
},
34+
cloud: {
35+
release: "https://cdimage.debian.org/cdimage/cloud/{codename}/latest/SHA512SUMS",
36+
daily: "https://cdimage.debian.org/cdimage/cloud/{codename}/daily/latest/SHA512SUMS"
37+
},
38+
docker: {
39+
daily: "https://doi-janky.infosiftr.net/job/tianon/job/debuerreotype/job/{arch}/lastSuccessfulBuild/artifact/{codename}/rootfs.tar.xz.sha256"
40+
},
41+
slim: {
42+
daily: "https://doi-janky.infosiftr.net/job/tianon/job/debuerreotype/job/{arch}/lastSuccessfulBuild/artifact/{codename}/slim/rootfs.tar.xz.sha256"
43+
}
44+
}.freeze
45+
46+
def url_of(edi, rel, build: "release", arch: "amd64")
47+
hash = RootFS::Distro::Debian.parse_edition(edi)
48+
return unless hash
49+
50+
edition = hash[:edition]
51+
52+
hash = RootFS::Distro::Debian.parse_release(rel, build: build)
53+
return unless hash
54+
55+
codename = hash[:codename]
56+
version = hash[:version]
57+
release = hash[:release]
58+
build = hash[:build]
59+
archive = hash[:archive]
60+
61+
hash = RootFS::Distro::Debian.parse_arch(arch)
62+
return unless hash
63+
64+
arch = hash[:arch]
65+
66+
url_tmpl = if %w[netinst desktop].include?(edition)
67+
if archive
68+
EDITION_URL[edition.to_sym][:archive]
69+
else
70+
EDITION_URL[edition.to_sym][release][build.to_sym]
71+
end
72+
else
73+
EDITION_URL[edition.to_sym][build.to_sym]
74+
end
75+
76+
return if url_tmpl.nil?
77+
78+
url_tmpl.gsub("{version}", version).gsub("{arch}", arch).gsub("{codename}", codename.to_s)
79+
end
80+
end
81+
end
82+
end

lib/rootfs/distro/debian/url_test.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "url"
4+
5+
class MyClass
6+
extend RootFS::Distro::Debian
7+
include RootFS::Distro::Debian
8+
end
9+
10+
u = MyClass.new
11+
12+
p u.url_of("netinst", "11.6.0")
13+
p u.url_of("netinst", "11")
14+
p u.url_of("netinst", "11")
15+
p u.url_of("netinst", "daily")
16+
p u.url_of("netinst", "weekly")
17+
p u.url_of("desktop", "11.6.0")
18+
p u.url_of("desktop", "weekly")
19+
p u.url_of("cloud", "11.6.0")
20+
p u.url_of("cloud", "daily")
21+
p u.url_of("docker", "11.6.0", build: "daily")
22+
p u.url_of("slim", "11.6.0", build: "daily")
23+
p u.url_of("docker", :unstable, build: "daily")

lib/rootfs/distro/debian/version.rb

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Debian
8+
extend self
9+
10+
# https://www.debian.org/releases/
11+
# https://wiki.debian.org/DebianReleases
12+
# https://wiki.debian.org/LTS
13+
# https://www.debian.org/doc/manuals/debian-faq/ftparchives#sourceforcodenames
14+
15+
CODENAME_VERSION = {
16+
sid: "13",
17+
bookworm: "12",
18+
bullseye: "11",
19+
buster: "10",
20+
stretch: "9",
21+
jessie: "8"
22+
}.freeze
23+
24+
RELEASE_VERSION = {
25+
unstable: "13",
26+
testing: "12",
27+
stable: "11",
28+
oldstable: "10",
29+
oldoldstable: "9"
30+
}.freeze
31+
32+
CURRENT_VERSION = "11.6.0"
33+
34+
REGULAR_BUILD = %w[
35+
release
36+
daily
37+
weekly
38+
].freeze
39+
40+
EDITION = %w[
41+
netinst
42+
desktop
43+
cloud
44+
docker
45+
slim
46+
].freeze
47+
48+
# https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/
49+
DESKTOP = %w[
50+
cinnamon
51+
gnome
52+
kde
53+
lxde
54+
lxqt
55+
mate
56+
standard
57+
xfce
58+
].freeze
59+
60+
def archive?(semver)
61+
sem_arr = _semver_to_a(semver)
62+
curr_arr = _semver_to_a(CURRENT_VERSION)
63+
_less_than(sem_arr, curr_arr)
64+
end
65+
66+
def parse_edition(any)
67+
RootFS::Parse._str_in_arr(any, "Debian", "edition", EDITION)
68+
end
69+
70+
def parse_build(any)
71+
RootFS::Parse._str_in_arr(any, "Debian", "build", REGULAR_BUILD)
72+
end
73+
74+
def parse_desktop(any)
75+
RootFS::Parse._str_in_arr(any, "Debian", "desktop", DESKTOP)
76+
end
77+
78+
def parse_release(any, build: "release")
79+
hash = parse_build(build)
80+
return unless hash
81+
82+
build = hash[:build]
83+
str = any.to_s
84+
sym = str.to_sym
85+
86+
if REGULAR_BUILD.include?(str)
87+
testing_version = RELEASE_VERSION[:testing]
88+
testing_codename = CODENAME_VERSION.key(testing_version)
89+
{ codename: testing_codename, version: testing_version,
90+
release: :testing, build: any, archive: false }
91+
elsif CODENAME_VERSION.key?(sym)
92+
version = CODENAME_VERSION[sym]
93+
release = RELEASE_VERSION.key(version)
94+
archive = archive?(version)
95+
96+
{ codename: sym, version: version,
97+
release: release, build: build, archive: archive }
98+
elsif RELEASE_VERSION.key?(sym)
99+
version = RELEASE_VERSION[sym]
100+
codename = CODENAME_VERSION.key(version)
101+
archive = archive?(version)
102+
103+
{ codename: codename, version: version,
104+
release: sym, build: build, archive: archive }
105+
else
106+
codename = nil
107+
version = nil
108+
109+
version_valid = false
110+
CODENAME_VERSION.each do |code, ver|
111+
next unless str.start_with?(ver)
112+
113+
version_valid = true
114+
codename = code
115+
version = ver
116+
break
117+
end
118+
119+
if version_valid
120+
release = RELEASE_VERSION.key(version)
121+
archive = archive?(str)
122+
123+
{ codename: codename, version: str,
124+
release: release, build: build, archive: archive }
125+
else
126+
keys_values = CODENAME_VERSION.keys + CODENAME_VERSION.values + RELEASE_VERSION.keys
127+
puts "Valid Debian release: #{keys_values}"
128+
end
129+
end
130+
end
131+
132+
private
133+
134+
def _semver_to_a(str)
135+
str_arr = str.split(".")
136+
if str_arr.size < 3
137+
(3 - str_arr.size).times do
138+
str_arr.push(0)
139+
end
140+
end
141+
str_arr
142+
end
143+
144+
# https://tldp.org/LDP/abs/html/comparison-ops.html
145+
def _less_than(arr1, arr2)
146+
num1 = arr1.shift.to_i
147+
num2 = arr2.shift.to_i
148+
149+
if num1 < num2
150+
true
151+
elsif num1 > num2
152+
false
153+
elsif arr1.empty? && !arr2.empty?
154+
true
155+
elsif !arr1.empty? && arr2.empty?
156+
false
157+
elsif arr1.empty? && arr2.empty?
158+
false
159+
else
160+
_less_than(arr1, arr2)
161+
end
162+
end
163+
end
164+
end
165+
end

0 commit comments

Comments
 (0)