Compare commits
3
Commits
7339809963
...
f35967c6e3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f35967c6e3 | ||
|
|
0d11ad4903 | ||
|
|
3fcfba2588 |
Generated
+186
@@ -2,6 +2,192 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d91e0c145792ef73a6ad36d27c75ac09f1832222a3c209689d90f534685ee5b7"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.6.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.107"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.47"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ruport"
|
name = "ruport"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "3.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.61.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|||||||
+36
@@ -3,4 +3,40 @@ name = "ruport"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
drop-in = []
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "portage"
|
||||||
|
path = "libportage/lib.rs"
|
||||||
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "ebuild"
|
||||||
|
path = "src/ebuild.rs"
|
||||||
|
required-features = ["drop-in"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "emerge"
|
||||||
|
path = "src/emerge.rs"
|
||||||
|
required-features = ["drop-in"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "emaint"
|
||||||
|
path = "src/emaint.rs"
|
||||||
|
required-features = ["drop-in"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "ruport"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = {version="4.6", features=["derive"]}
|
||||||
|
log = "0.4.33"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 'z'
|
||||||
|
lto = true
|
||||||
|
strip = true
|
||||||
|
panic = "abort"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
use std::io::Result;
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
|
use portage::util::logger::logger_init;
|
||||||
|
use portage::config::PortageConfig;
|
||||||
|
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
match logger_init(log::LevelFilter::Debug) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{e}");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let cfg = PortageConfig::new()?;
|
||||||
|
cfg.display_config();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
use std::io::Result;
|
||||||
|
|
||||||
|
use portage::repository::RepoConfig;
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
// the repo configuration
|
||||||
|
let mut repos = RepoConfig::new()?;
|
||||||
|
|
||||||
|
// read the config
|
||||||
|
repos.read_config()?;
|
||||||
|
|
||||||
|
// print repo config
|
||||||
|
repos.print_repos()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
use std::{fmt, path::{Path, PathBuf}};
|
||||||
|
|
||||||
|
mod ruport;
|
||||||
|
mod portage;
|
||||||
|
|
||||||
|
use ruport::RuportConfigProvider;
|
||||||
|
use portage::PortageConfigProvider;
|
||||||
|
|
||||||
|
use crate::features::Features;
|
||||||
|
|
||||||
|
trait ConfigProvider {
|
||||||
|
fn new() -> Result<Self, ConfigError> where Self: Sized;
|
||||||
|
fn parse_global(&mut self) -> Result<(), std::io::Error>;
|
||||||
|
|
||||||
|
// getter
|
||||||
|
fn get_elog(&self) -> ELog;
|
||||||
|
fn get_features(&self) -> Vec<Features>;
|
||||||
|
|
||||||
|
// display functions
|
||||||
|
fn display_cflags(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum ConfigError {
|
||||||
|
PortageConfigNotFound,
|
||||||
|
RuportConfigNotFound,
|
||||||
|
}
|
||||||
|
impl fmt::Display for ConfigError {
|
||||||
|
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// portage paths
|
||||||
|
pub(crate) struct PortagePaths {
|
||||||
|
distdir: PathBuf,
|
||||||
|
pkgdir: PathBuf,
|
||||||
|
rpmdir: PathBuf,
|
||||||
|
tmpdir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
// elog classes
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
enum ELogClasses {
|
||||||
|
Log,
|
||||||
|
Warn,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
impl ELogClasses {
|
||||||
|
pub fn from(line: String) -> Vec<Self> {
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
|
let line = line.trim_matches('"')
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for v in line {
|
||||||
|
match v {
|
||||||
|
"log" => ret.push(ELogClasses::Log),
|
||||||
|
"warn" => ret.push(ELogClasses::Warn),
|
||||||
|
"error" => ret.push(ELogClasses::Error),
|
||||||
|
|
||||||
|
_ => eprintln!("unknown ELog Class: {v}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
pub(crate) struct ELog {
|
||||||
|
classes: Vec<ELogClasses>,
|
||||||
|
system: String,
|
||||||
|
mail_uri: String,
|
||||||
|
mail_subject: String,
|
||||||
|
mail_from: String,
|
||||||
|
}
|
||||||
|
impl ELog {
|
||||||
|
pub fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
classes: vec![ELogClasses::Log, ELogClasses::Warn, ELogClasses::Error],
|
||||||
|
system: "save_summary:log,warn,error,qa echo".to_string(),
|
||||||
|
|
||||||
|
mail_uri: "root".to_string(),
|
||||||
|
mail_subject: "[portage] ebuild log for {pkg} on {host}".to_string(),
|
||||||
|
mail_from: "portage@localhost".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This struct holds the current configuration.
|
||||||
|
pub struct PortageConfig {
|
||||||
|
provider: Box<dyn ConfigProvider>,
|
||||||
|
|
||||||
|
elog: ELog,
|
||||||
|
features: Vec<Features>,
|
||||||
|
}
|
||||||
|
impl PortageConfig {
|
||||||
|
pub fn new() -> Result<Self, std::io::Error> {
|
||||||
|
let mut p: Box<dyn ConfigProvider> = match PortageConfigProvider::new() {
|
||||||
|
Ok(prov) => Box::new(prov),
|
||||||
|
Err(_) => {
|
||||||
|
match RuportConfigProvider::new() {
|
||||||
|
Ok(prov) => Box::new(prov),
|
||||||
|
Err(_) => Box::new(RuportConfigProvider::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match p.parse_global() {
|
||||||
|
Ok(r) => {},
|
||||||
|
Err(e) => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
let elog = p.get_elog();
|
||||||
|
let features = p.get_features();
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
provider: p,
|
||||||
|
elog: elog,
|
||||||
|
features: features,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn display_config(&self) {
|
||||||
|
self.provider.display_cflags();
|
||||||
|
|
||||||
|
// display active features
|
||||||
|
println!("Active Features: {:?}", self.features);
|
||||||
|
|
||||||
|
// print elog information
|
||||||
|
println!("ELOG: ");
|
||||||
|
println!("\tClasses: {:?}", self.elog.classes);
|
||||||
|
println!("\tSystem: {}", self.elog.system);
|
||||||
|
println!("\tMail Subject: {}", self.elog.mail_subject);
|
||||||
|
println!("\tMail From: ({}) {}", self.elog.mail_uri, self.elog.mail_from);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
|
||||||
|
use std::{collections::HashMap, fs::File, io::{BufRead, BufReader, Error, ErrorKind}, path::{Path, PathBuf}};
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
|
use crate::features::Features;
|
||||||
|
|
||||||
|
use super::ConfigProvider;
|
||||||
|
use super::ConfigError;
|
||||||
|
use super::PortagePaths;
|
||||||
|
use super::{ELog,ELogClasses};
|
||||||
|
|
||||||
|
/// The Portage config provider.
|
||||||
|
///
|
||||||
|
/// It is the default configuration in "normal" gentoo system. Per default,
|
||||||
|
/// Ruport try to read this configuration first.
|
||||||
|
pub(crate) struct PortageConfigProvider{
|
||||||
|
global_path: PathBuf,
|
||||||
|
compile_flags: HashMap<String, String>,
|
||||||
|
features: Vec<Features>,
|
||||||
|
mirrors: Vec<String>,
|
||||||
|
paths: PortagePaths,
|
||||||
|
elog: ELog,
|
||||||
|
}
|
||||||
|
impl PortageConfigProvider {
|
||||||
|
fn validate_data(&mut self, data: Vec<(String,String)>) -> std::io::Result<()> {
|
||||||
|
for (key,value) in data {
|
||||||
|
match key.as_str() {
|
||||||
|
"CFLAGS" => self.compile_flags.insert("CFLAGS".to_string(), value),
|
||||||
|
"CXXFLAGS" => self.compile_flags.insert("CXXFLAGS".to_string(), value),
|
||||||
|
"FFLAGS" => self.compile_flags.insert("FFLAGS".to_string(), value),
|
||||||
|
"FCFLAGS" => self.compile_flags.insert("FCFLAGS".to_string(), value),
|
||||||
|
"LDFLAGS" => self.compile_flags.insert("LDFLAGS".to_string(), value),
|
||||||
|
|
||||||
|
"GENTOO_MIRRORS" => {
|
||||||
|
let mirrors: Vec<&str> = value.split_whitespace().collect();
|
||||||
|
for mirror in mirrors {
|
||||||
|
self.mirrors.push(mirror.to_string());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"FEATURES" => {
|
||||||
|
let features: Vec<&str> = value.split_whitespace().collect();
|
||||||
|
for feature in features {
|
||||||
|
let f = Features::from(feature);
|
||||||
|
if f.is_some(){
|
||||||
|
self.features.push(f.unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"DISTDIR" => {
|
||||||
|
let dir = value.trim_matches('"');
|
||||||
|
self.paths.distdir = PathBuf::from(dir);
|
||||||
|
},
|
||||||
|
"PKGDIR" => {
|
||||||
|
let dir = value.trim_matches('"');
|
||||||
|
self.paths.pkgdir = PathBuf::from(dir);
|
||||||
|
},
|
||||||
|
"RPMDIR" => {
|
||||||
|
let dir = value.trim_matches('"');
|
||||||
|
self.paths.rpmdir = PathBuf::from(dir);
|
||||||
|
},
|
||||||
|
"PORTAGE_TMPDIR" => {
|
||||||
|
let dir = value.trim_matches('"');
|
||||||
|
self.paths.tmpdir = PathBuf::from(dir);
|
||||||
|
},
|
||||||
|
|
||||||
|
// ELog configuration
|
||||||
|
"PORTAGE_ELOG_CLASSES" => {
|
||||||
|
let classes = value.trim_matches('"')
|
||||||
|
.split_whitespace()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
for class in classes {
|
||||||
|
let c = match class {
|
||||||
|
"log" => ELogClasses::Log,
|
||||||
|
"warn" => ELogClasses::Warn,
|
||||||
|
"error" => ELogClasses::Error,
|
||||||
|
};
|
||||||
|
self.elog.classes.push(c);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"PORTAGE_ELOG_SYSTEM" => self.elog.system = value,
|
||||||
|
"PORTAGE_ELOG_MAILURI" => self.elog.mail_uri = value,
|
||||||
|
"PORTAGE_ELOG_MAILSUBJECT" => {
|
||||||
|
let subject = value
|
||||||
|
.replace("\\${PACKAGE", "{pkg}")
|
||||||
|
.replace("\\${HOST}", "{host}");
|
||||||
|
self.elog.mail_subject = subject;
|
||||||
|
},
|
||||||
|
"PORTAGE_ELOG_MAILFROM" => self.elog.mail_from = value,
|
||||||
|
|
||||||
|
&_ => todo!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConfigProvider for PortageConfigProvider {
|
||||||
|
fn new() -> Result<Self, ConfigError> {
|
||||||
|
let global_path = Path::new("/usr/share/portage/config/make.globals");
|
||||||
|
|
||||||
|
if !global_path.exists() {
|
||||||
|
return Err(ConfigError::PortageConfigNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
log::debug!("using portage config");
|
||||||
|
|
||||||
|
Ok(Self{
|
||||||
|
global_path: global_path.to_path_buf(),
|
||||||
|
compile_flags: HashMap::new(),
|
||||||
|
features: Vec::new(),
|
||||||
|
mirrors: Vec::new(),
|
||||||
|
paths: PortagePaths {
|
||||||
|
distdir: PathBuf::new(),
|
||||||
|
pkgdir: PathBuf::new(),
|
||||||
|
rpmdir: PathBuf::new(),
|
||||||
|
tmpdir: PathBuf::new(),
|
||||||
|
},
|
||||||
|
elog: ELog::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_global(&mut self) -> Result<(), std::io::Error> {
|
||||||
|
let file = File::open(self.global_path.clone())?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let mut data: Vec<(String, String)> = Vec::new();
|
||||||
|
|
||||||
|
let mut current_key: Option<String> = None;
|
||||||
|
let mut current_value = String::new();
|
||||||
|
|
||||||
|
for line in reader.lines() {
|
||||||
|
let line = line?;
|
||||||
|
let line = line.trim();
|
||||||
|
|
||||||
|
// ignore empty line or comments
|
||||||
|
if line.is_empty() || line.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// multiple line
|
||||||
|
if current_key.is_some() {
|
||||||
|
current_value.push(' ');
|
||||||
|
current_value.push_str(&line.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(index) = line.find('=') {
|
||||||
|
let key = line[..index].trim().to_string();
|
||||||
|
let value = line[index+1..].trim();
|
||||||
|
|
||||||
|
if value.starts_with('"') && !value.ends_with('"') {
|
||||||
|
current_key = Some(key);
|
||||||
|
current_value = value.to_string();
|
||||||
|
} else {
|
||||||
|
data.push((key, current_value.to_string()));
|
||||||
|
current_value.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.validate_data(data)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn eparse_global(&mut self) -> std::io::Result<()> {
|
||||||
|
// let file = File::open(self.global_path.clone())?;
|
||||||
|
// let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
// let mut data: HashMap<String, String> = HashMap::new();
|
||||||
|
|
||||||
|
// let mut current_key: Option<String> = None;
|
||||||
|
// let mut current_value = String::new();
|
||||||
|
|
||||||
|
// for line in reader.lines() {
|
||||||
|
// let line = line.unwrap();
|
||||||
|
// let line = line.trim();
|
||||||
|
|
||||||
|
// // ignore empty line or comments
|
||||||
|
// if line.is_empty() || line.starts_with('#') {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // multiline option
|
||||||
|
// if current_key.is_some() {
|
||||||
|
// current_value.push(' ');
|
||||||
|
// current_value.push_str(line);
|
||||||
|
|
||||||
|
// if line.ends_with('"') {
|
||||||
|
// data.insert(
|
||||||
|
// current_key.take().unwrap(),
|
||||||
|
// current_value.clone(),
|
||||||
|
// );
|
||||||
|
// current_value.clear();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if let Some(index) = line.find('=') {
|
||||||
|
// let key = line[..index].trim().to_string();
|
||||||
|
// let value = line[index+1..].trim();
|
||||||
|
|
||||||
|
// if value.starts_with('"') && ! value.ends_with('"') {
|
||||||
|
// current_key = Some(key);
|
||||||
|
// current_value = value.to_string();
|
||||||
|
// } else {
|
||||||
|
// if current_value.contains("${*}") {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// data.insert(key, value.to_string());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // data.insert(
|
||||||
|
// // key.to_string(),
|
||||||
|
// // value.to_string()
|
||||||
|
// // );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // now get the values from the buffer
|
||||||
|
// let cflags = data.get("CFLAGS");
|
||||||
|
// if cflags.is_some() {
|
||||||
|
// self.compile_flags.insert("CFLAGS".to_string(), cflags.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// let cxxflags = data.get("CXXFLAGS");
|
||||||
|
// if cxxflags.is_some() {
|
||||||
|
// self.compile_flags.insert("CXXFLAGS".to_string(), cxxflags.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// let ldflags = data.get("LDFLAGS");
|
||||||
|
// if ldflags.is_some() {
|
||||||
|
// self.compile_flags.insert("LDFLAGS".to_string(), ldflags.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// let fflags = data.get("FFLAGS");
|
||||||
|
// if fflags.is_some() {
|
||||||
|
// self.compile_flags.insert("FFLAGS".to_string(), fflags.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// let fcflags = data.get("FCFLAGS");
|
||||||
|
// if fcflags.is_some() {
|
||||||
|
// self.compile_flags.insert("FCFLAGS".to_string(), fcflags.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// let mirrors = data.get("GENTOO_MIRRORS");
|
||||||
|
// let mirrors: Vec<&str> = mirrors.unwrap().split_whitespace().collect();
|
||||||
|
// for mirror in mirrors {
|
||||||
|
// self.mirrors.push(mirror.to_string());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let features = data.get("FEATURES");
|
||||||
|
// if features.is_some() {
|
||||||
|
// self.features = Features::from_line(features.unwrap().to_string())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let distdir = data.get("DISTDIR");
|
||||||
|
// let pkgdir = data.get("PKGDIR");
|
||||||
|
// let rpmdir = data.get("RPMDIR");
|
||||||
|
// let tmpdir = data.get("PORTAGE_TMPDIR");
|
||||||
|
// if distdir.is_some() {
|
||||||
|
// self.paths.distdir = PathBuf::from(distdir.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// if pkgdir.is_some() {
|
||||||
|
// self.paths.pkgdir = PathBuf::from(pkgdir.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// if rpmdir.is_some() {
|
||||||
|
// self.paths.rpmdir = PathBuf::from(rpmdir.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// if tmpdir.is_some() {
|
||||||
|
// self.paths.tmpdir = PathBuf::from(tmpdir.unwrap().to_string())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // elog settings
|
||||||
|
// let elog_classes = data.get("PORTAGE_ELOG_CLASSES");
|
||||||
|
// let elog_system = data.get("PORTAGE_ELOG_SYSTEM");
|
||||||
|
// let elog_mailuri = data.get("PORTAGE_ELOG_MAILURI");
|
||||||
|
// let elog_mailsubject = data.get("PORTAGE_ELOG_MAILSUBJECT");
|
||||||
|
// let elog_mailfrom = data.get("PORTAGE_ELOG_MAILFROM");
|
||||||
|
// if elog_classes.is_some() {
|
||||||
|
// self.elog.classes = ELogClasses::from(elog_classes.unwrap().to_string());
|
||||||
|
// }
|
||||||
|
// if elog_system.is_some() {
|
||||||
|
// self.elog.system = elog_system.unwrap().to_string();
|
||||||
|
// }
|
||||||
|
// if elog_mailuri.is_some() {
|
||||||
|
// self.elog.mail_uri = elog_mailuri.unwrap().to_string();
|
||||||
|
// }
|
||||||
|
// if elog_mailsubject.is_some() {
|
||||||
|
// let subject = elog_mailsubject.unwrap().to_string();
|
||||||
|
// let _ = subject.replace("\\${PACKAGE}", "{pkg}")
|
||||||
|
// .replace("\\${HOST}", "{host}");
|
||||||
|
// self.elog.mail_subject = subject;
|
||||||
|
// }
|
||||||
|
// if elog_mailfrom.is_some() {
|
||||||
|
// self.elog.mail_from = elog_mailfrom.unwrap().to_string();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn get_elog(&self) -> ELog {
|
||||||
|
self.elog.clone()
|
||||||
|
}
|
||||||
|
fn get_features(&self) -> Vec<Features> {
|
||||||
|
self.features.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_cflags(&self) {
|
||||||
|
println!("Compiler Flags:");
|
||||||
|
for (k,v) in self.compile_flags.clone() {
|
||||||
|
let v = v.trim_matches('"');
|
||||||
|
println!("\t{k} = {v}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::features::Features;
|
||||||
|
|
||||||
|
use super::ConfigProvider;
|
||||||
|
use super::ConfigError;
|
||||||
|
use super::{ELog,ELogClasses};
|
||||||
|
|
||||||
|
/// The Ruport config provider.
|
||||||
|
///
|
||||||
|
/// It is used, then there is no current portage configuration available.
|
||||||
|
/// It is also capable of, creating default configs, useful for embedded
|
||||||
|
/// systems.
|
||||||
|
pub(crate) struct RuportConfigProvider{
|
||||||
|
global_path: PathBuf,
|
||||||
|
elog: ELog,
|
||||||
|
features: Vec<Features>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RuportConfigProvider {
|
||||||
|
pub fn default() -> Self {
|
||||||
|
let elog = ELog::default();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
global_path: PathBuf::from("/usr/share/ruport/config.ini"),
|
||||||
|
elog,
|
||||||
|
features: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ConfigProvider for RuportConfigProvider {
|
||||||
|
fn new() -> Result<Self, ConfigError> {
|
||||||
|
let global_path = Path::new("/usr/share/ruport/config.ini");
|
||||||
|
if !global_path.exists() {
|
||||||
|
return Err(ConfigError::RuportConfigNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
log::debug!("using ruport config.");
|
||||||
|
Ok(Self{
|
||||||
|
global_path: global_path.to_path_buf(),
|
||||||
|
elog: ELog::default(),
|
||||||
|
features: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn parse_global(&mut self) -> std::io::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_elog(&self) -> ELog {
|
||||||
|
self.elog.clone()
|
||||||
|
}
|
||||||
|
fn get_features(&self) -> Vec<crate::features::Features> {
|
||||||
|
self.features.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_cflags(&self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
|
||||||
|
#[derive(Debug,Clone,Copy)]
|
||||||
|
pub enum Features {
|
||||||
|
AssumeDigests,
|
||||||
|
BinPkgDoCompress,
|
||||||
|
BinPkgDoStrip,
|
||||||
|
BinPkgIgnoreSignature,
|
||||||
|
BinPkgLogs,
|
||||||
|
BinPkgMultiInstance,
|
||||||
|
BinPkgRequestSignature,
|
||||||
|
BinPkgSigning,
|
||||||
|
BuildPkg,
|
||||||
|
BuildPkgLive,
|
||||||
|
BuildPkgProactive,
|
||||||
|
BuildSysPkg,
|
||||||
|
Candy,
|
||||||
|
CaseInsensistiveFs,
|
||||||
|
Ccache,
|
||||||
|
Chflags,
|
||||||
|
CleanLogs,
|
||||||
|
CollisionProtect,
|
||||||
|
CompressBuildLogs,
|
||||||
|
CompressDebug,
|
||||||
|
CompressIndex,
|
||||||
|
ConfigProtectIfModified,
|
||||||
|
DeDupDebug,
|
||||||
|
Digest,
|
||||||
|
DistCC,
|
||||||
|
DistLocks,
|
||||||
|
DowngradeBackup,
|
||||||
|
EbuildLocks,
|
||||||
|
FailClean,
|
||||||
|
FakeRoot,
|
||||||
|
FixLaFiles,
|
||||||
|
ForceMirror,
|
||||||
|
GetBinPkg,
|
||||||
|
GpgKeepAlive,
|
||||||
|
HomeDirTemplateCopy,
|
||||||
|
IceCream,
|
||||||
|
InstallSources,
|
||||||
|
IpcSandbox,
|
||||||
|
JobServerToken,
|
||||||
|
KeepTemp,
|
||||||
|
KeepWork,
|
||||||
|
LMirror,
|
||||||
|
MergeSync,
|
||||||
|
MergeWait,
|
||||||
|
MetadataTransfer,
|
||||||
|
Mirror,
|
||||||
|
MountSandbox,
|
||||||
|
MultilibStrict,
|
||||||
|
NetworkSandbox,
|
||||||
|
NetworkSandboxProxy,
|
||||||
|
News,
|
||||||
|
NoAuto,
|
||||||
|
NoClean,
|
||||||
|
NoDoc,
|
||||||
|
NoInfo,
|
||||||
|
NoMan,
|
||||||
|
NoStrip,
|
||||||
|
NoTitles,
|
||||||
|
PackDebug,
|
||||||
|
ParallelFetch,
|
||||||
|
ParallelInstall,
|
||||||
|
PidSandbox,
|
||||||
|
PkgdirIndexTrusted,
|
||||||
|
PrelinkChecksums,
|
||||||
|
PreserveLibs,
|
||||||
|
ProtectOwned,
|
||||||
|
PythonTrace,
|
||||||
|
QAUnresolvedSonameDeps,
|
||||||
|
Sandbox,
|
||||||
|
SeLinux,
|
||||||
|
SeSandbox,
|
||||||
|
SFPerms,
|
||||||
|
Sign,
|
||||||
|
SkipRoCheck,
|
||||||
|
SplitDebug,
|
||||||
|
SplitElog,
|
||||||
|
SplitLog,
|
||||||
|
Strict,
|
||||||
|
StrictKeepDir,
|
||||||
|
Stricter,
|
||||||
|
Suidctl,
|
||||||
|
Test,
|
||||||
|
TestFailContinue,
|
||||||
|
UnknownFeaturesFilter,
|
||||||
|
UnknownFeaturesWarn,
|
||||||
|
UnmergeBackup,
|
||||||
|
UnmergeLogs,
|
||||||
|
UnmergeOrphans,
|
||||||
|
Unprivileged,
|
||||||
|
UserFetch,
|
||||||
|
UserPriv,
|
||||||
|
UserSandbox,
|
||||||
|
UserSync,
|
||||||
|
WarnOnLargeEnv,
|
||||||
|
WebRsyncGpg,
|
||||||
|
XATTR,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Features {
|
||||||
|
pub fn from(val: &str) -> Option<Self> {
|
||||||
|
log::debug!("features val line: {val}");
|
||||||
|
|
||||||
|
match val {
|
||||||
|
"assume-digests" => Some(Self::AssumeDigests),
|
||||||
|
|
||||||
|
"binpkg-docompress" => Some(Self::BinPkgDoCompress),
|
||||||
|
"binpkg-dostrip" => Some(Self::BinPkgDoStrip),
|
||||||
|
"binpkg-ignore-signature" => Some(Self::BinPkgIgnoreSignature),
|
||||||
|
"binpkg-logs" => Some(Self::BinPkgLogs),
|
||||||
|
"binpkg-multi-instance" => Some(Self::BinPkgMultiInstance),
|
||||||
|
"binpkg-request-signature" => Some(Self::BinPkgRequestSignature),
|
||||||
|
"binpkg-signing" => Some(Self::BinPkgSigning),
|
||||||
|
|
||||||
|
"buildpkg" => Some(Self::BuildPkg),
|
||||||
|
"buildpkg-live" => Some(Self::BuildPkgLive),
|
||||||
|
"buildpkg-proactive" => Some(Self::BuildPkgProactive),
|
||||||
|
"buildsyspkg" => Some(Self::BuildSysPkg),
|
||||||
|
|
||||||
|
"candy" => Some(Self::Candy),
|
||||||
|
"case-insensistive-fs" => Some(Self::CaseInsensistiveFs),
|
||||||
|
"ccache" => Some(Self::Ccache),
|
||||||
|
"chflags" => Some(Self::Chflags),
|
||||||
|
"clean-logs" => Some(Self::CleanLogs),
|
||||||
|
"collision-protect" => Some(Self::CollisionProtect),
|
||||||
|
"compress-build-logs" => Some(Self::CompressBuildLogs),
|
||||||
|
"compressdebug" => Some(Self::CompressDebug),
|
||||||
|
"compress-index" => Some(Self::CompressIndex),
|
||||||
|
"config-protect-if-modified" => Some(Self::ConfigProtectIfModified),
|
||||||
|
"dedupdebug" => Some(Self::DeDupDebug),
|
||||||
|
"digest" => Some(Self::Digest),
|
||||||
|
"distcc" => Some(Self::DistCC),
|
||||||
|
"distlocks" => Some(Self::DistLocks),
|
||||||
|
"downgrade-backup" => Some(Self::DowngradeBackup),
|
||||||
|
"ebuild-locks" => Some(Self::EbuildLocks),
|
||||||
|
"fail-clean" => Some(Self::FailClean),
|
||||||
|
"fakeroot" => Some(Self::FakeRoot),
|
||||||
|
"fixlafiles" => Some(Self::FixLaFiles),
|
||||||
|
"force-mirror" => Some(Self::ForceMirror),
|
||||||
|
"getbinpkg" => Some(Self::GetBinPkg),
|
||||||
|
"gpg-keepalive" => Some(Self::GpgKeepAlive),
|
||||||
|
"home-dir-template-copy" => Some(Self::HomeDirTemplateCopy),
|
||||||
|
"icecream" => Some(Self::IceCream),
|
||||||
|
"installsources" => Some(Self::InstallSources),
|
||||||
|
"ipc-sandbox" => Some(Self::IpcSandbox),
|
||||||
|
"jobserver-token" => Some(Self::JobServerToken),
|
||||||
|
"keeptemp" => Some(Self::KeepTemp),
|
||||||
|
"keepwork" => Some(Self::KeepWork),
|
||||||
|
"lmirror" => Some(Self::LMirror),
|
||||||
|
"merge-sync" => Some(Self::MergeSync),
|
||||||
|
"merge-wait" => Some(Self::MergeWait),
|
||||||
|
"metadata-transfer" => Some(Self::MetadataTransfer),
|
||||||
|
"mirror" => Some(Self::Mirror),
|
||||||
|
"mount-sandbox" => Some(Self::MountSandbox),
|
||||||
|
"multilib-strict" => Some(Self::MultilibStrict),
|
||||||
|
"network-sandbox" => Some(Self::NetworkSandbox),
|
||||||
|
"network-sandbox-proxy" => Some(Self::NetworkSandboxProxy),
|
||||||
|
"news" => Some(Self::News),
|
||||||
|
|
||||||
|
"noauto" => Some(Self::NoAuto),
|
||||||
|
"noclean" => Some(Self::NoClean),
|
||||||
|
"nodoc" => Some(Self::NoDoc),
|
||||||
|
"noinfo" => Some(Self::NoInfo),
|
||||||
|
"noman" => Some(Self::NoMan),
|
||||||
|
"nostrip" => Some(Self::NoStrip),
|
||||||
|
"notitles" => Some(Self::NoTitles),
|
||||||
|
|
||||||
|
"packdebug" => Some(Self::PackDebug),
|
||||||
|
"parallel-fetch" => Some(Self::ParallelFetch),
|
||||||
|
"parallel-install" => Some(Self::ParallelInstall),
|
||||||
|
"pid-sandbox" => Some(Self::PidSandbox),
|
||||||
|
"pkgdir-index-trusted" => Some(Self::PkgdirIndexTrusted),
|
||||||
|
"prelink-checksums" => Some(Self::PrelinkChecksums),
|
||||||
|
"preserve-libs" => Some(Self::PreserveLibs),
|
||||||
|
"protect-owned" => Some(Self::ProtectOwned),
|
||||||
|
"python-trace" => Some(Self::PythonTrace),
|
||||||
|
"qa-unresolved-soname-deps" => Some(Self::QAUnresolvedSonameDeps),
|
||||||
|
"sandbox" => Some(Self::Sandbox),
|
||||||
|
"selinux" => Some(Self::SeLinux),
|
||||||
|
"sesandbox" => Some(Self::SeSandbox),
|
||||||
|
"sfperms" => Some(Self::SFPerms),
|
||||||
|
"sign" => Some(Self::Sign),
|
||||||
|
"skiprocheck" => Some(Self::SkipRoCheck),
|
||||||
|
"splitdebug" => Some(Self::SplitDebug),
|
||||||
|
"split-elog" => Some(Self::SplitElog),
|
||||||
|
"split-log" => Some(Self::SplitLog),
|
||||||
|
|
||||||
|
"strict" => Some(Self::Strict),
|
||||||
|
"strict-keepdir" => Some(Self::StrictKeepDir),
|
||||||
|
"stricter" => Some(Self::Stricter),
|
||||||
|
"suidctl" => Some(Self::Suidctl),
|
||||||
|
|
||||||
|
"test" => Some(Self::Test),
|
||||||
|
"test-fail-continue" => Some(Self::TestFailContinue),
|
||||||
|
|
||||||
|
"unknown-features-filter" => Some(Self::UnknownFeaturesFilter),
|
||||||
|
"unknown-features-warn" => Some(Self::UnknownFeaturesWarn),
|
||||||
|
|
||||||
|
"unmerge-backup" => Some(Self::UnmergeBackup),
|
||||||
|
"unmerge-logs" => Some(Self::UnmergeLogs),
|
||||||
|
"unmerge-orphans" => Some(Self::UnmergeOrphans),
|
||||||
|
|
||||||
|
"unprivileged" => Some(Self::Unprivileged),
|
||||||
|
|
||||||
|
"userfetch" => Some(Self::UserFetch),
|
||||||
|
"userpriv" => Some(Self::UserPriv),
|
||||||
|
"usersandbox" => Some(Self::UserSandbox),
|
||||||
|
"usersync" => Some(Self::UserSync),
|
||||||
|
|
||||||
|
"warn-on-large-env" => Some(Self::WarnOnLargeEnv),
|
||||||
|
"webrsync-gpg" => Some(Self::WebRsyncGpg),
|
||||||
|
"xattr" => Some(Self::XATTR),
|
||||||
|
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn from_line(line: String) -> Vec<Self> {
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
for v in line.split_whitespace() {
|
||||||
|
let f = Self::from(v);
|
||||||
|
if f.is_some() {
|
||||||
|
ret.push(f.unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use std::io::Result;
|
||||||
|
use clap::ValueEnum;
|
||||||
|
|
||||||
|
use crate::repository::RepoConfig;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod util;
|
||||||
|
pub mod repository;
|
||||||
|
pub(crate) mod features;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,ValueEnum)]
|
||||||
|
pub enum Action {
|
||||||
|
Search,
|
||||||
|
Update,
|
||||||
|
Remove,
|
||||||
|
Sync,
|
||||||
|
Depclean,
|
||||||
|
Install,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PortageContext
|
||||||
|
///
|
||||||
|
/// holds the system and repository configuration.
|
||||||
|
/// It is the first thing, you need to create, to have full access to this library.
|
||||||
|
pub struct PortageContext {
|
||||||
|
repo_config: RepoConfig,
|
||||||
|
}
|
||||||
|
impl PortageContext {
|
||||||
|
pub fn new() -> Result<Self> {
|
||||||
|
let mut repo_config = RepoConfig::new()?;
|
||||||
|
repo_config.read_config()?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
repo_config
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
use std::env::current_exe;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::fs::self;
|
||||||
|
use std::io::{BufRead, BufReader, Result};
|
||||||
|
use std::{fs::File, path::{Path,PathBuf}};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
enum SyncType {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Rsync(String),
|
||||||
|
Git(String),
|
||||||
|
}
|
||||||
|
impl SyncType {
|
||||||
|
pub fn get_uri(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Git(uri) => uri.to_string(),
|
||||||
|
Self::Rsync(uri) => uri.to_string(),
|
||||||
|
Self::None => String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Display for SyncType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let (typ, uri) = match self {
|
||||||
|
Self::Git(uri) => ("git", uri.as_str()),
|
||||||
|
Self::Rsync(uri) => ("rsync", uri.as_str()),
|
||||||
|
Self::None => ("none",""),
|
||||||
|
};
|
||||||
|
write!(f, "{typ} uri: {uri}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
struct RepositoryConfig {
|
||||||
|
pub name: String,
|
||||||
|
pub location: PathBuf,
|
||||||
|
sync_type: SyncType,
|
||||||
|
auto_sync: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RepoConfig {
|
||||||
|
main_repo: String,
|
||||||
|
repos: Vec<RepositoryConfig>,
|
||||||
|
initialized: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepoConfig {
|
||||||
|
pub fn new() -> Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
main_repo: String::new(),
|
||||||
|
repos: Vec::new(),
|
||||||
|
initialized: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_config(&mut self) -> Result<()> {
|
||||||
|
// test portage internal config
|
||||||
|
if PathBuf::from("/usr/share/portage/config/repos.conf").exists() {
|
||||||
|
let configs = self.read_file(PathBuf::from("/usr/share/portage/config/repos.conf"))?;
|
||||||
|
self.main_repo = String::from(configs[0].name.clone());
|
||||||
|
self.repos.push(configs[0].clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// test the portage config directory: /etc/portage/repos.conf
|
||||||
|
let dir = Path::new("/etc/portage/repos.conf");
|
||||||
|
// check if directory exists...
|
||||||
|
if dir.is_dir() {
|
||||||
|
let entries = fs::read_dir(dir)?
|
||||||
|
.map(|res| res.map(|e| e.path()))
|
||||||
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
|
for entry in entries {
|
||||||
|
let configs = self.read_file(entry)?;
|
||||||
|
for config in configs {
|
||||||
|
self.repos.push(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.initialized = true;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_file(&mut self, path: PathBuf) -> Result<Vec<RepositoryConfig>> {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let mut reader = BufReader::new(file);
|
||||||
|
|
||||||
|
let mut repos = Vec::new();
|
||||||
|
let mut data = HashMap::<String,HashMap<String,String>>::new();
|
||||||
|
|
||||||
|
let mut current_repo = String::new();
|
||||||
|
for line in reader.lines() {
|
||||||
|
let line = line.unwrap();
|
||||||
|
let line = line.trim();
|
||||||
|
|
||||||
|
// ignore empty lines
|
||||||
|
if line.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore comments
|
||||||
|
if line.starts_with(';') || line.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if line.starts_with('[') && line.ends_with(']') {
|
||||||
|
current_repo = line[1..line.len() -1].to_string();
|
||||||
|
} else if let Some(index) = line.find('=') {
|
||||||
|
let key = line[..index].trim().to_string();
|
||||||
|
let value = line[index +1 ..].trim().to_string();
|
||||||
|
|
||||||
|
if !current_repo.is_empty() {
|
||||||
|
let repo = data.entry(current_repo.clone()).or_insert(HashMap::new());
|
||||||
|
repo.insert(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse hashmap
|
||||||
|
println!("data: {:#?}", data);
|
||||||
|
for d in data {
|
||||||
|
if d.0 == "DEFAULT" {
|
||||||
|
let main_repo = d.1.get("main_repo");
|
||||||
|
if main_repo.is_some() {
|
||||||
|
self.main_repo = main_repo.unwrap().clone();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut repo = RepositoryConfig::default();
|
||||||
|
// get repo name
|
||||||
|
repo.name = d.0;
|
||||||
|
|
||||||
|
// get repo sync type & uri
|
||||||
|
let sync_type = d.1.get("sync-type");
|
||||||
|
let sync_uri = d.1.get("sync-uri");
|
||||||
|
if sync_type.is_some() && sync_uri.is_some() {
|
||||||
|
let sync_type = sync_type.unwrap();
|
||||||
|
let sync_uri = sync_uri.unwrap();
|
||||||
|
let sync = match sync_type.to_ascii_lowercase().as_str() {
|
||||||
|
"rsync" => SyncType::Rsync(sync_uri.to_string()),
|
||||||
|
"git" => SyncType::Git(sync_uri.to_string()),
|
||||||
|
_ => SyncType::None,
|
||||||
|
};
|
||||||
|
repo.sync_type = sync;
|
||||||
|
}
|
||||||
|
// get auto-sync option
|
||||||
|
let auto_sync = d.1.get("auto-sync");
|
||||||
|
if auto_sync.is_some() {
|
||||||
|
match auto_sync.unwrap().to_ascii_lowercase().as_str() {
|
||||||
|
"true" => repo.auto_sync = true,
|
||||||
|
_ => repo.auto_sync = false,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
repo.auto_sync = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get repository location
|
||||||
|
let location = d.1.get("location");
|
||||||
|
if location.is_some() {
|
||||||
|
let location = location.unwrap();
|
||||||
|
let path = PathBuf::from(location.clone());
|
||||||
|
repo.location = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parsed all relevant data, so push the repo config
|
||||||
|
repos.push(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(repos)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_repos(&self) -> Result<()> {
|
||||||
|
println!("Main Repository: {}", self.main_repo);
|
||||||
|
println!();
|
||||||
|
|
||||||
|
for repo in self.repos.clone().into_iter() {
|
||||||
|
println!("Repository: {}", repo.name);
|
||||||
|
println!("\tlocation: {}", repo.location.display());
|
||||||
|
println!("\tsync-type: {}", repo.sync_type);
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
use log::{Record, Level, Metadata, SetLoggerError, LevelFilter};
|
||||||
|
|
||||||
|
struct SimpleLogger;
|
||||||
|
|
||||||
|
impl log::Log for SimpleLogger {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
|
metadata.level() <= Level::Debug
|
||||||
|
}
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
|
metadata.level() <= Level::Info
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log(&self, record: &Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
println!("{} - {}" , record.level(), record.args());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
static LOGGER: SimpleLogger = SimpleLogger;
|
||||||
|
|
||||||
|
pub fn logger_init(level: LevelFilter) -> Result<(), SetLoggerError> {
|
||||||
|
log::set_logger(&LOGGER)
|
||||||
|
.map(|()| log::set_max_level(level))
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
pub mod logger;
|
||||||
+108
@@ -0,0 +1,108 @@
|
|||||||
|
use clap::{CommandFactory, Parser};
|
||||||
|
|
||||||
|
use signal_hook::{consts::SIGINT, iterator::Signals};
|
||||||
|
use std::{collections::HashMap, error::Error, path::PathBuf, thread};
|
||||||
|
|
||||||
|
use portage::Action;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(
|
||||||
|
name = "emerge",
|
||||||
|
about = "command-line interface to the Portage system"
|
||||||
|
)]
|
||||||
|
struct Cli {
|
||||||
|
/// Pretend mode
|
||||||
|
#[arg(short = 'p', long)]
|
||||||
|
pub pretend: bool,
|
||||||
|
|
||||||
|
/// Ask before executing
|
||||||
|
#[arg(short = 'a', long)]
|
||||||
|
pub ask: bool,
|
||||||
|
|
||||||
|
/// Update package
|
||||||
|
#[arg(short = 'u',long,action)]
|
||||||
|
pub update: bool,
|
||||||
|
|
||||||
|
/// Clean unused packages
|
||||||
|
#[arg(short='c',long,action)]
|
||||||
|
pub depclean: bool,
|
||||||
|
|
||||||
|
/// Synchronize repositories
|
||||||
|
#[arg(long,action)]
|
||||||
|
pub sync: bool,
|
||||||
|
|
||||||
|
/// search for matches of the supplied string in the ebuild repository.
|
||||||
|
#[arg(short = 's',long,action)]
|
||||||
|
pub search: bool,
|
||||||
|
|
||||||
|
/// Number of jobs
|
||||||
|
#[arg(short = 'j', long)]
|
||||||
|
pub jobs: Option<u32>,
|
||||||
|
|
||||||
|
/// Set the PORTAGE_CONFIGROOT environment variable
|
||||||
|
#[arg(long,default_value="/")]
|
||||||
|
pub config_root: PathBuf,
|
||||||
|
|
||||||
|
/// Set the ROOT environment variable
|
||||||
|
#[arg(long)]
|
||||||
|
pub root: PathBuf,
|
||||||
|
|
||||||
|
/// Set the SYSROOT environment variable
|
||||||
|
#[arg(long)]
|
||||||
|
pub sysroot: PathBuf,
|
||||||
|
|
||||||
|
/// Set the EPREFIX environment variable
|
||||||
|
#[arg(long)]
|
||||||
|
pub prefix: PathBuf,
|
||||||
|
|
||||||
|
/// Package or sets
|
||||||
|
#[arg()]
|
||||||
|
pub targets: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cli {
|
||||||
|
pub fn get_action(&self) -> Action {
|
||||||
|
if self.sync {
|
||||||
|
Action::Sync
|
||||||
|
} else if self.depclean {
|
||||||
|
Action::Depclean
|
||||||
|
} else if self.update {
|
||||||
|
Action::Update
|
||||||
|
} else if self.search {
|
||||||
|
Action::Search(self.targets.clone())
|
||||||
|
} else {
|
||||||
|
Action::Install(self.targets.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_paths(&self) -> HashMap<&str, PathBuf> {
|
||||||
|
let mut paths = HashMap::new();
|
||||||
|
|
||||||
|
paths.insert("PORTAGE_CONFIGROOT", self.config_root.clone());
|
||||||
|
paths.insert("SYSROOT", self.sysroot.clone());
|
||||||
|
paths.insert("ROOT", self.root.clone());
|
||||||
|
paths.insert("EPREFIX", self.prefix.clone());
|
||||||
|
|
||||||
|
paths
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
if std::env::args_os().len() == 1 {
|
||||||
|
Cli::command().print_help()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let cli = Cli::parse();
|
||||||
|
let mut signals = Signals::new([SIGINT])?;
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
for sig in signals.forever() {
|
||||||
|
println!("Received signal {:?}", sig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
portage::perform_action(cli.get_action(), cli.get_paths())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
+45
-2
@@ -1,3 +1,46 @@
|
|||||||
fn main() {
|
use std::io::Result;
|
||||||
println!("Hello, world!");
|
use clap::{Args, CommandFactory, Parser};
|
||||||
|
use portage::{Action, PortageContext};
|
||||||
|
use portage::util::logger::logger_init;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Cli {
|
||||||
|
/// ask before doing anything
|
||||||
|
#[arg(short='a', long)]
|
||||||
|
pub ask: bool,
|
||||||
|
/// be verbose on the output
|
||||||
|
#[arg(short='v', long)]
|
||||||
|
pub verbose: bool,
|
||||||
|
/// show debug messages
|
||||||
|
#[arg(short='d', long, default_value="false")]
|
||||||
|
pub debug: bool,
|
||||||
|
|
||||||
|
/// action to perform
|
||||||
|
#[arg(value_enum)]
|
||||||
|
pub action: Action,
|
||||||
|
/// package atoms/names to perform actions against
|
||||||
|
#[arg()]
|
||||||
|
pub targets: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()>{
|
||||||
|
if std::env::args_os().len() == 1 {
|
||||||
|
Cli::command().print_help().unwrap();
|
||||||
|
println!();
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let _cli = Cli::parse();
|
||||||
|
|
||||||
|
if _cli.debug {
|
||||||
|
logger_init(log::LevelFilter::Debug)
|
||||||
|
.expect("unable to setup logger");
|
||||||
|
} else {
|
||||||
|
logger_init(log::LevelFilter::Info)
|
||||||
|
.expect("unable to setup logger");
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ctx = PortageContext::new()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user