summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorIvan Vasilchenko <qvkapp@gmail.com>2026-11-19 22:14:55 +0300
committerIvan Vasilchenko <qvkapp@gmail.com>2026-11-19 22:14:55 +0300
commit283afa1922f87e5e97c4bec2c019b3add71e375a (patch)
treed6d8a9defcf3450f0200ff13f83ad99aea246287 /src/config.rs
parent78828df65dfc90d30e82490b290db04ebf2c6f30 (diff)
downloadror-main.tar.gz
ror-main.zip
refactor: update license to mpl-2.0, improve config, progress bar and rootfsHEAD1.0.4main
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs69
1 files changed, 37 insertions, 32 deletions
diff --git a/src/config.rs b/src/config.rs
index e4ffdaf..e9d1c95 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -54,8 +54,26 @@ impl Default for GlobalConfig {
fn default_ignore_speed() -> bool { false }
fn default_strict_gpg() -> bool { false }
fn default_parallel_downloads() -> usize { 4 }
-fn default_arch() -> String { std::env::consts::ARCH.to_string() }
-fn default_libc() -> String { "glibc".to_string() }
+
+pub fn detect_arch() -> String {
+ std::env::consts::ARCH.to_string()
+}
+
+pub fn detect_libc() -> String {
+ if cfg!(target_env = "musl") {
+ "musl".to_string()
+ } else {
+ "glibc".to_string()
+ }
+}
+
+fn default_arch() -> String {
+ detect_arch()
+}
+
+fn default_libc() -> String {
+ detect_libc()
+}
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct SystemProfile {
@@ -167,29 +185,17 @@ impl Config {
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));
- lines.push(format!("strict_gpg = {}", self.global.strict_gpg));
lines.push(format!("parallel_downloads = {}", self.global.parallel_downloads));
- 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());
+ if self.global.strict_gpg {
+ lines.push(format!("strict_gpg = {}", self.global.strict_gpg));
+ }
+ if self.global.allow_external_binaries {
+ lines.push(format!("allow_external_binaries = {}", self.global.allow_external_binaries));
}
+ if self.global.ignore_speed {
+ lines.push(format!("ignore_speed = {}", self.global.ignore_speed));
+ }
+ lines.push(String::new());
for (name, repo) in &self.repositories {
lines.push(format!("[repositories.{}]", name));
@@ -200,7 +206,9 @@ impl Config {
if let Some(m) = &repo.mirror {
lines.push(format!("mirror = \"{}\"", m));
}
- lines.push(format!("gpg_support = {}", repo.gpg_support));
+ if repo.gpg_support {
+ lines.push(format!("gpg_support = {}", repo.gpg_support));
+ }
if let Some(k) = &repo.gpg_key {
lines.push(format!("gpg_key = \"{}\"", k));
}
@@ -219,20 +227,17 @@ impl Config {
pub fn create_default_config(path: &Path) -> std::io::Result<()> {
let ini = concat!(
"[global]\n",
- "ignore_speed = true\n",
- "strict_gpg = false\n",
- "allow_external_binaries = true\n",
"parallel_downloads = 4\n",
- "arch = x86_64\n",
- "libc = glibc\n\n",
+ "strict_gpg = false\n\n",
"[repositories.rorkos]\n",
- "url = \"https://rorkos.duckdns.org/pkg/\"\n",
+ "url = \"https://codeberg.org/RorkOS/packages.git\"\n",
"urlrepo = \"https://rorkos.duckdns.org/pkg/\"\n",
- "mirror = \"https://rorkos.duckdns.org/pkg/\"\n",
"gpg_support = false\n",
);
- fs::create_dir_all(path.parent().unwrap())?;
+ if let Some(parent) = path.parent() {
+ fs::create_dir_all(parent)?;
+ }
let mut tmp = NamedTempFile::new_in(path.parent().unwrap_or(Path::new(".")))?;
tmp.write_all(ini.as_bytes())?;
fs::set_permissions(tmp.path(), std::fs::Permissions::from_mode(0o644))?;