Skip to content

Commit b127676

Browse files
committed
feat: add Fedora module to project
1 parent de53e69 commit b127676

File tree

8 files changed

+277
-0
lines changed

8 files changed

+277
-0
lines changed

lib/rootfs/distro/fedora.rb

Lines changed: 15 additions & 0 deletions
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 "fedora/arch"
6+
require_relative "fedora/file"
7+
require_relative "fedora/tier"
8+
require_relative "fedora/url"
9+
10+
module RootFS
11+
module Distro
12+
module Fedora
13+
end
14+
end
15+
end

lib/rootfs/distro/fedora/arch.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Fedora
8+
extend self
9+
10+
# https://dl.fedoraproject.org/pub/alt/rawhide-kernel-nodebug/
11+
# https://arm.fedoraproject.org/
12+
ARCH = %w[
13+
x86_64
14+
aarch64
15+
armhfp
16+
ppc64
17+
ppc64le
18+
s390x
19+
].freeze
20+
21+
def parse_arch(any)
22+
RootFS::Parse._str_in_arr(any, "Fedora", "arch", ARCH)
23+
end
24+
end
25+
end
26+
end

lib/rootfs/distro/fedora/file.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../fedora"
4+
5+
module RootFS
6+
module Distro
7+
module Fedora
8+
extend self
9+
10+
def files_of(*argv, **opts)
11+
tier = argv[0] || opts[:tier] || "fedora"
12+
version = argv[1] || opts[:version] || "rawhide"
13+
arch = argv[2] || opts[:arch] || "x86_64"
14+
edition = argv[3] || opts[:edition] || "Container"
15+
desktop = argv[4] || opts[:desktop]
16+
17+
url = RootFS::Distro::Fedora.url_of(tier)
18+
return if url.nil?
19+
20+
hash = Fedora.parse_version(version)
21+
return unless hash
22+
23+
version = hash[:version]
24+
25+
hash = Fedora.parse_arch(arch)
26+
return unless hash
27+
28+
arch = hash[:arch]
29+
30+
if edition
31+
hash = Fedora.parse_edition(edition)
32+
return unless hash
33+
34+
edition = hash[:edition]
35+
end
36+
37+
if desktop
38+
hash = Fedora.parse_desktop(desktop)
39+
return unless hash
40+
41+
desktop = hash[:desktop]
42+
end
43+
44+
keywords = []
45+
[version, edition, arch, desktop].each do |any|
46+
keywords.push(any) if any
47+
end
48+
49+
resp = RootFS::HTTP.get(url)
50+
body = resp.body
51+
files = RootFS::Data.from_fedora_txt(body, keywords)
52+
{ imagelist: url, files: files }
53+
end
54+
end
55+
end
56+
end

lib/rootfs/distro/fedora/file_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "file"
4+
5+
class MyClass
6+
extend RootFS::Distro::Fedora
7+
include RootFS::Distro::Fedora
8+
end
9+
10+
u = MyClass.new
11+
12+
pp u.files_of
13+
pp u.files_of("1st", 37, "aarch64")
14+
pp u.files_of("1st", 36, "armhfp")

lib/rootfs/distro/fedora/tier.rb

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Fedora
8+
extend self
9+
10+
# https://dl.fedoraproject.org/pub/
11+
TIER = %w[
12+
fedora
13+
fedora-secondary
14+
alt
15+
].freeze
16+
17+
# https://dl.fedoraproject.org/pub/fedora/linux/releases/
18+
VERSION = %(
19+
rawhide
20+
test
21+
7
22+
8
23+
9
24+
10
25+
11
26+
12
27+
13
28+
14
29+
15
30+
16
31+
17
32+
18
33+
19
34+
20
35+
21
36+
22
37+
23
38+
24
39+
25
40+
26
41+
27
42+
28
43+
29
44+
30
45+
31
46+
32
47+
33
48+
34
49+
35
50+
36
51+
37
52+
)
53+
54+
# https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/
55+
EDITION = %w[
56+
AtomicHost
57+
AtomicWorkstation
58+
Cloud
59+
Container
60+
Everything
61+
Kinoite
62+
Modular
63+
Server
64+
Silverblue
65+
Spins
66+
Workstation
67+
].freeze
68+
69+
# https://dl.fedoraproject.org/pub/fedora/imagelist-fedora
70+
DESKTOP = %w[
71+
MATE_Compiz
72+
Cinnamon
73+
KDE
74+
LXDE
75+
LXQt
76+
SoaS
77+
Xfce
78+
i3
79+
].freeze
80+
81+
def parse_tier(any = "fedora")
82+
any = "fedora" if any == "1st"
83+
any = "fedora-secondary" if any == "2nd"
84+
any = "alt" if any == "3rd"
85+
RootFS::Parse._str_in_arr(any, "Fedora", "tier", TIER)
86+
end
87+
88+
def parse_version(any = "rawhide")
89+
any = any.to_s if any.instance_of?(0.class)
90+
RootFS::Parse._str_in_arr(any, "Fedora", "version", VERSION)
91+
end
92+
93+
def parse_edition(any = "Container")
94+
RootFS::Parse._str_in_arr(any, "Fedora", "edition", EDITION)
95+
end
96+
97+
def parse_desktop(any)
98+
RootFS::Parse._str_in_arr(any, "Fedora", "desktop", DESKTOP)
99+
end
100+
end
101+
end
102+
end

lib/rootfs/distro/fedora/tier_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "tier"
4+
5+
class MyClass
6+
extend RootFS::Distro::Fedora
7+
include RootFS::Distro::Fedora
8+
end
9+
10+
f = MyClass.new
11+
12+
p f.parse_tier
13+
p f.parse_tier("alt")
14+
p f.parse_tier("2nd")
15+
p f.parse_tier("3rd")
16+
17+
p f.parse_version
18+
p f.parse_version(37)
19+
20+
p f.parse_edition
21+
p f.parse_edition("Spins")
22+
23+
p f.parse_desktop("KDE")
24+
p f.parse_desktop("MATE")

lib/rootfs/distro/fedora/url.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../fedora"
4+
5+
module RootFS
6+
module Distro
7+
module Fedora
8+
extend self
9+
10+
# https://dl.fedoraproject.org/pub/fedora/imagelist-fedora
11+
# https://dl.fedoraproject.org/pub/fedora-secondary/imagelist-fedora-secondary
12+
# https://dl.fedoraproject.org/pub/alt/imagelist-alt
13+
14+
URL_TMPL = "https://dl.fedoraproject.org/pub/{tier}/imagelist-{tier}"
15+
16+
def url_of(tier = "fedora")
17+
hash = Fedora.parse_tier(tier)
18+
return unless tier
19+
20+
tier = hash[:tier]
21+
URL_TMPL.gsub("{tier}", tier)
22+
end
23+
end
24+
end
25+
end

lib/rootfs/distro/fedora/url_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "url"
4+
5+
class MyClass
6+
extend RootFS::Distro::Fedora
7+
include RootFS::Distro::Fedora
8+
end
9+
10+
f = MyClass.new
11+
12+
p f.url_of
13+
p f.url_of("alt")
14+
p f.url_of("2nd")
15+
p f.url_of("3rd")

0 commit comments

Comments
 (0)