summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorrorka900 <rorka900@gmail.com>2026-04-06 21:05:06 +0300
committerrorka900 <rorka900@gmail.com>2026-04-06 21:05:06 +0300
commit62d9463b3f24516158e9e73cd20ccebfc9eec329 (patch)
tree664ee2433618df788e9a3db3118a609329ca6e8d /src/config.rs
parent044d414f07b13bfdee5a04bc2484510ecfe0a0f8 (diff)
downloadror-62d9463b3f24516158e9e73cd20ccebfc9eec329.tar.gz
ror-62d9463b3f24516158e9e73cd20ccebfc9eec329.zip
feat: add sror package type, gpg repo verification, and group command
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 0c6fc1b..ff83f01 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -8,9 +8,17 @@ use colored::Colorize;
pub struct RepositoryConfig {
pub url: String,
#[serde(default)]
+ pub urlrepo: Option<String>,
+ #[serde(default)]
pub mirror: Option<String>,
+ #[serde(default = "default_gpg_support")]
+ pub gpg_support: bool,
+ #[serde(default)]
+ pub gpg_key: Option<String>,
}
+fn default_gpg_support() -> bool { true }
+
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct GlobalConfig {
#[serde(default = "default_ignore_speed")]
@@ -46,12 +54,79 @@ fn default_parallel_downloads() -> usize { 4 }
fn default_arch() -> String { std::env::consts::ARCH.to_string() }
fn default_libc() -> String { "glibc".to_string() }
+#[derive(Debug, Deserialize, Serialize, Clone, Default)]
+pub struct SystemProfile {
+ #[serde(rename = "init-system", default)]
+ pub init_system: Option<String>,
+ #[serde(default)]
+ pub libc: Option<String>,
+ #[serde(rename = "core-utils", default)]
+ pub core_utils: Option<String>,
+ #[serde(default)]
+ pub sh: Vec<String>,
+ #[serde(default)]
+ pub su: Vec<String>,
+ #[serde(default)]
+ pub udev: Option<String>,
+ #[serde(rename = "active-group", default)]
+ pub active_group: Option<String>,
+}
+
+impl SystemProfile {
+ pub fn group_name(&self) -> Option<String> {
+ if let Some(g) = &self.active_group {
+ return Some(g.clone());
+ }
+ let init = self.init_system.as_deref()?;
+ let libc = self.libc.as_deref()?;
+ let utils = self.core_utils.as_deref()?;
+ let sh = self.sh.first().map(|s| s.as_str())?;
+ let su = self.su.first().map(|s| s.as_str())?;
+ let udev = self.udev.as_deref()?;
+ Some(format!("{}-{}-{}-{}-{}-{}-min", init, libc, utils, sh, su, udev))
+ }
+
+ pub fn set_single_role(&mut self, role: &str, pkg: &str) {
+ match role {
+ "init-system" => self.init_system = Some(pkg.to_string()),
+ "libc" => self.libc = Some(pkg.to_string()),
+ "core-utils" => self.core_utils = Some(pkg.to_string()),
+ "udev" => self.udev = Some(pkg.to_string()),
+ _ => {}
+ }
+ }
+
+ pub fn replace_in_list_role(&mut self, role: &str, old_pkg: &str, new_pkg: &str) {
+ let list = match role {
+ "sh" => &mut self.sh,
+ "su" => &mut self.su,
+ _ => return,
+ };
+ if let Some(pos) = list.iter().position(|p| p == old_pkg) {
+ list[pos] = new_pkg.to_string();
+ } else {
+ list.push(new_pkg.to_string());
+ }
+ }
+ #[allow(dead_code)]
+ pub fn remove_from_list_role(&mut self, role: &str, pkg: &str) {
+ let list = match role {
+ "sh" => &mut self.sh,
+ "su" => &mut self.su,
+ _ => return,
+ };
+ list.retain(|p| p != pkg);
+ }
+}
+
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
pub struct Config {
#[serde(default)]
pub global: GlobalConfig,
#[serde(default)]
pub repositories: HashMap<String, RepositoryConfig>,
+ #[serde(default)]
+ pub profile: SystemProfile,
}
impl Config {
@@ -72,6 +147,15 @@ impl Config {
}
}
+ pub fn save(&self) -> std::io::Result<()> {
+ let path = Path::new("/etc/ror/ror.conf");
+ let ini = self.to_ini().map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ if let Some(parent) = path.parent() {
+ fs::create_dir_all(parent)?;
+ }
+ fs::write(path, ini)
+ }
+
pub fn to_ini(&self) -> Result<String, config::ConfigError> {
let mut lines = vec!["[global]".to_string()];
lines.push(format!("ignore_speed = {}", self.global.ignore_speed));
@@ -80,12 +164,37 @@ impl Config {
lines.push(format!("arch = {}", self.global.arch));
lines.push(format!("libc = {}", self.global.libc));
lines.push(String::new());
+
+ let p = &self.profile;
+ let has_profile = p.init_system.is_some() || p.libc.is_some()
+ || p.core_utils.is_some() || !p.sh.is_empty()
+ || !p.su.is_empty() || p.udev.is_some() || p.active_group.is_some();
+
+ if has_profile {
+ lines.push("[profile]".to_string());
+ if let Some(v) = &p.active_group { lines.push(format!("active-group = {}", v)); }
+ if let Some(v) = &p.init_system { lines.push(format!("init-system = {}", v)); }
+ if let Some(v) = &p.libc { lines.push(format!("libc = {}", v)); }
+ if let Some(v) = &p.core_utils { lines.push(format!("core-utils = {}", v)); }
+ if !p.sh.is_empty() { lines.push(format!("sh = {}", p.sh.join(","))); }
+ if !p.su.is_empty() { lines.push(format!("su = {}", p.su.join(","))); }
+ if let Some(v) = &p.udev { lines.push(format!("udev = {}", v)); }
+ lines.push(String::new());
+ }
+
for (name, repo) in &self.repositories {
lines.push(format!("[repositories.{}]", name));
lines.push(format!("url = \"{}\"", repo.url));
+ if let Some(v) = &repo.urlrepo {
+ lines.push(format!("urlrepo = \"{}\"", v));
+ }
if let Some(m) = &repo.mirror {
lines.push(format!("mirror = \"{}\"", m));
}
+ lines.push(format!("gpg_support = {}", repo.gpg_support));
+ if let Some(k) = &repo.gpg_key {
+ lines.push(format!("gpg_key = \"{}\"", k));
+ }
lines.push(String::new());
}
Ok(lines.join("\n"))
@@ -109,7 +218,10 @@ impl Config {
"\n",
"[repositories.rorkos]\n",
"url = \"https://github.com/RorkOS/RorkOS_package\"\n",
+ "urlrepo = \"https://github.com/RorkOS/RorkOS_packages_bin/releases/download/latest/\"\n",
"mirror = \"https://github.com/rork-os/RorkOS_package\"\n",
+ "gpg_support = true\n",
+ "gpg_key = \"rorka.pub\"\n",
);
fs::create_dir_all(path.parent().unwrap())?;
fs::write(path, ini)