Skip to content

Commit

Permalink
feat: Add Gentoo
Browse files Browse the repository at this point in the history
  • Loading branch information
lj3954 authored and flexiondotorg committed Aug 27, 2024
1 parent 5d010a4 commit 8b525f4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mod ubuntu;
pub(crate) use arch::{manjaro::BigLinux, ArchLinux, Archcraft, ArcoLinux, ArtixLinux, AthenaOS, BlendOS, CachyOS, EndeavourOS, Garuda};
pub(crate) use debian::{Antix, BunsenLabs, CrunchbangPlusPlus, Debian, Devuan, EasyOS, EndlessOS};
pub(crate) use fedora_redhat::{Alma, Bazzite, CentOSStream, Fedora};
pub(crate) use independent::{Alpine, Batocera, ChimeraLinux, NixOS};
pub(crate) use independent::{Alpine, Batocera, ChimeraLinux, Gentoo, NixOS};
pub(crate) use ubuntu::{Bodhi, Edubuntu, Elementary, Kubuntu, Lubuntu, Ubuntu, UbuntuBudgie, UbuntuCinnamon, UbuntuKylin, UbuntuMATE, UbuntuServer, UbuntuStudio, UbuntuUnity, Xubuntu};
59 changes: 59 additions & 0 deletions src/linux/independent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,62 @@ impl Distro for ChimeraLinux {
.into()
}
}

const GENTOO_MIRROR: &str = "https://distfiles.gentoo.org/releases/";

pub struct Gentoo;
impl Distro for Gentoo {
const NAME: &'static str = "gentoo";
const PRETTY_NAME: &'static str = "Gentoo";
const HOMEPAGE: Option<&'static str> = Some("https://www.gentoo.org/");
const DESCRIPTION: Option<&'static str> = Some("Highly flexible, source-based Linux distribution.");
async fn generate_configs() -> Option<Vec<Config>> {
let iso_regex = Arc::new(Regex::new(r#"\d{8}T\d{6}Z\/(admincd|install|livegui).*?.iso"#).unwrap());
let futures = [(Arch::x86_64, "amd64"), (Arch::aarch64, "arm64")]
.into_iter()
.map(|(arch, arch_str)| {
let iso_regex = iso_regex.clone();
let mirror = format!("{GENTOO_MIRROR}{arch_str}/autobuilds/");
async move {
let image_data = capture_page(&(mirror.clone() + "latest-iso.txt")).await?;

let futures = iso_regex
.captures_iter(&image_data)
.map(|c| c.extract())
.map(|(iso, [mut edition])| {
if edition == "install" {
edition = "minimal";
}
let url = format!("{mirror}{iso}");
let checksum_url = url.clone() + ".sha256";
let arch = arch.clone();
async move {
let checksum = capture_page(&checksum_url).await.and_then(|cs| {
cs.lines()
.skip_while(|l| !l.contains("iso"))
.next()
.and_then(|l| l.split_whitespace().next().map(ToString::to_string))
});

Config {
release: Some("latest".to_string()),
edition: Some(edition.to_string()),
iso: Some(vec![Source::Web(WebSource::new(url, checksum, None, None))]),
arch,
..Default::default()
}
}
});

Some(futures::future::join_all(futures).await)
}
});
futures::future::join_all(futures)
.await
.into_iter()
.flatten()
.flatten()
.collect::<Vec<Config>>()
.into()
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async fn main() {
linux::Fedora,
other::FreeDOS,
linux::Garuda,
linux::Garuda,
linux::Gentoo,
);

let distros = futures::future::join_all(futures)
Expand Down

0 comments on commit 8b525f4

Please sign in to comment.