Skip to content

Commit 67888cc

Browse files
committed
feat: add Gentoo module to project
1 parent 0b2de04 commit 67888cc

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

lib/rootfs/distro/gentoo.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 "gentoo/arch"
6+
require_relative "gentoo/stage3"
7+
require_relative "gentoo/file"
8+
require_relative "gentoo/url"
9+
10+
module RootFS
11+
module Distro
12+
module Gentoo
13+
end
14+
end
15+
end

lib/rootfs/distro/gentoo/arch.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Gentoo
8+
extend self
9+
10+
# https://www.gentoo.org/downloads/
11+
ARCH = %w[
12+
amd64
13+
alpha
14+
arm
15+
arm64
16+
hppa
17+
ia64
18+
loong
19+
mips
20+
m68k
21+
ppc
22+
riscv
23+
s390
24+
sparc
25+
x86
26+
].freeze
27+
28+
def parse_arch(any)
29+
RootFS::Parse._str_in_arr(any, "Gentoo", "arch", ARCH)
30+
end
31+
end
32+
end
33+
end

lib/rootfs/distro/gentoo/file.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../gentoo"
4+
5+
module RootFS
6+
module Distro
7+
module Gentoo
8+
extend self
9+
10+
def files_of(*argv, **opts)
11+
arch = argv[0] || opts[:arch] || "amd64"
12+
feature = argv[1] || opts[:feature] || ["openrc"]
13+
14+
url = RootFS::Distro::Gentoo.url_of(arch)
15+
return if url.nil?
16+
17+
hash = Gentoo.parse_feature(feature)
18+
return unless hash
19+
20+
feature = hash[:feature]
21+
22+
resp = RootFS::HTTP.get(url)
23+
body = resp.body
24+
files = RootFS::Data.from_gentoo_txt(body, feature)
25+
{ latest: url, files: files }
26+
end
27+
end
28+
end
29+
end

lib/rootfs/distro/gentoo/file_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "file"
4+
5+
class MyClass
6+
extend RootFS::Distro::Gentoo
7+
include RootFS::Distro::Gentoo
8+
end
9+
10+
u = MyClass.new
11+
12+
pp u.files_of
13+
pp u.files_of("arm64", "desktop")
14+
feat = %w[armv7a hardfp systemd]
15+
pp u.files_of("arm", feat)

lib/rootfs/distro/gentoo/stage3.rb

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../parse"
4+
5+
module RootFS
6+
module Distro
7+
module Gentoo
8+
extend self
9+
10+
# https://www.gentoo.org/downloads/
11+
# https://distfiles.gentoo.org/
12+
FEATURE = %w[
13+
openrc
14+
systemd
15+
desktop
16+
mergedusr
17+
hardened
18+
nomultilib
19+
selinux
20+
llvm
21+
musl
22+
x32
23+
armv4tl
24+
armv5tel
25+
armv6j
26+
hardfp
27+
armv7a
28+
hppa1.1
29+
hppa2.0
30+
mips2
31+
mips3
32+
n32
33+
n64
34+
mipsel2
35+
mipsel3
36+
power9le
37+
ppc64le
38+
ppc64
39+
ppc
40+
lp64
41+
lp64d
42+
multilib
43+
i486
44+
i686
45+
].freeze
46+
47+
def parse_feature(any = "openrc")
48+
RootFS::Parse._arr_in_arr(any, "Gentoo", "feature", FEATURE)
49+
end
50+
end
51+
end
52+
end
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "stage3"
4+
5+
class MyClass
6+
extend RootFS::Distro::Gentoo
7+
include RootFS::Distro::Gentoo
8+
end
9+
10+
g = MyClass.new
11+
12+
p g.parse_feature
13+
p g.parse_feature(%w[desktop systemd])
14+
feat = %w[armv7a hardfp systemd]
15+
p g.parse_feature(feat)
16+
p g.parse_feature(%w[llvm ulibc])

lib/rootfs/distro/gentoo/url.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../gentoo"
4+
5+
module RootFS
6+
module Distro
7+
module Gentoo
8+
extend self
9+
10+
# https://www.gentoo.org/downloads/
11+
# https://distfiles.gentoo.org/
12+
13+
URL_TMPL = "https://bouncer.gentoo.org/fetch/root/all/releases/{arch}/autobuilds/latest-stage3.txt"
14+
15+
def url_of(arch = "amd64")
16+
hash = Gentoo.parse_arch(arch)
17+
return unless hash
18+
19+
arch = hash[:arch]
20+
URL_TMPL.gsub("{arch}", arch)
21+
end
22+
end
23+
end
24+
end

lib/rootfs/distro/gentoo/url_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "url"
4+
require_relative "arch"
5+
6+
class MyClass
7+
extend RootFS::Distro::Gentoo
8+
include RootFS::Distro::Gentoo
9+
end
10+
11+
u = MyClass.new
12+
13+
MyClass::ARCH.each do |arch|
14+
p u.url_of(arch)
15+
end
16+
17+
p u.url_of("riscv64")

0 commit comments

Comments
 (0)