summaryrefslogtreecommitdiff
path: root/src/main.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/main.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/main.rs')
-rw-r--r--src/main.rs267
1 files changed, 159 insertions, 108 deletions
diff --git a/src/main.rs b/src/main.rs
index fc1df89..5b93b66 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,8 +52,11 @@ struct Args {
#[arg(long = "dry-run")]
dry_run: bool,
- #[arg(short = 'u', long = "upgrade", value_name = "RECIPE")]
- upgrade: Option<std::path::PathBuf>,
+ #[arg(short = 'u', long = "upgrade")]
+ upgrade: bool,
+
+ #[arg(long = "up", value_name = "GROUP")]
+ upgrade_to: Option<String>,
#[arg(long = "repo-add", value_names = ["NAME", "URL"])]
repo_add: Option<Vec<String>>,
@@ -78,128 +81,138 @@ struct Args {
#[arg(long = "di", value_names = ["DELETE", "INSTALL"], num_args = 2)]
delete_install: Option<Vec<String>>,
-
+
#[arg(long = "lg", alias = "listgroups")]
listgroups: bool,
}
-fn main() {
- let args = Args::parse();
+fn run_di(del_pkg: String, inst_pkg: String, cfg: Arc<config::Config>) {
+ let db = install::InstalledDB::load();
- if args.version {
- println!("ror {}", env!("CARGO_PKG_VERSION"));
+ if !db.is_installed(&del_pkg) {
+ eprintln!("{} Package '{}' is not installed.", "[ror]".red().bold(), del_pkg);
return;
}
- if args.gen_config {
- let config_path = Path::new("/etc/ror/ror.conf");
- match config::Config::create_default_config(config_path) {
- Ok(()) => println!(
- "{} Default config created at {:?}",
- "[ror]".blue().bold(),
- config_path
- ),
- Err(e) => eprintln!(
- "{} Failed to create config: {}",
- "[ror]".red().bold(),
- e
- ),
+ let del_role = delete::critical_role_of(&del_pkg);
+ let inst_role = delete::critical_role_of_from_recipe(&inst_pkg);
+
+ if let Some(dr) = del_role {
+ match inst_role {
+ None => {
+ eprintln!(
+ "{} '{}' provides critical role '{}' but '{}' does not. Replacement rejected.",
+ "[ror]".red().bold(), del_pkg, dr, inst_pkg
+ );
+ return;
+ }
+ Some(ir) if ir != dr => {
+ eprintln!(
+ "{} Role mismatch: '{}' is '{}' but '{}' is '{}'. Roles must match.",
+ "[ror]".red().bold(), del_pkg, dr, inst_pkg, ir
+ );
+ return;
+ }
+ _ => {}
}
- return;
}
- let cfg = Arc::new(config::Config::load());
-
- if let Some(di_args) = args.delete_install {
- let del_pkg = di_args[0].clone();
- let inst_pkg = di_args[1].clone();
-
- let db = install::InstalledDB::load();
-
- if !db.is_installed(&del_pkg) {
- eprintln!("{} Package '{}' is not installed.", "[ror]".red().bold(), del_pkg);
- return;
- }
+ if let Err(e) = delete::check_critical_removal_with_replacement(&del_pkg, &inst_pkg, &db) {
+ eprintln!("{}", e);
+ return;
+ }
- if let Err(e) = delete::check_critical_removal_with_replacement(&del_pkg, &inst_pkg, &db) {
+ if let Err(e) = delete::check_critical_install(&inst_pkg, &db) {
+ if !db.packages.contains_key(&inst_pkg) && !e.contains(&del_pkg) {
eprintln!("{}", e);
return;
}
+ }
- if let Err(e) = delete::check_critical_install(&inst_pkg, &db) {
- let already_installed_by_same = db.packages.get(&inst_pkg).is_some();
- if !already_installed_by_same {
- let conflict_is_the_deleted = e.contains(&del_pkg);
- if !conflict_is_the_deleted {
- eprintln!("{}", e);
- return;
- }
- }
- }
+ let record_files = db.packages.get(&del_pkg).map(|r| r.files.clone()).unwrap_or_default();
- let record_files = db.packages
- .get(&del_pkg)
- .map(|r| r.files.clone())
- .unwrap_or_default();
-
- println!(
- "{} Replacing '{}' with '{}'...",
- "[ror]".blue().bold(),
- del_pkg,
- inst_pkg
- );
-
- let del_pkg_for_thread = del_pkg.clone();
- let inst_pkg_for_thread = inst_pkg.clone();
- let cfg_for_thread = Arc::clone(&cfg);
-
- let del_handle = thread::spawn(move || {
- println!("{} [remove] Starting removal of '{}'", ">>>".yellow(), del_pkg_for_thread);
- let ok = delete::remove_package_files_only(&del_pkg_for_thread, &record_files);
- if ok {
- println!("{} [remove] Files removed for '{}'", ">>>".green(), del_pkg_for_thread);
- } else {
- eprintln!("{} [remove] Errors during removal of '{}'", "[ror]".red().bold(), del_pkg_for_thread);
- }
- ok
- });
+ let full_rebuild = del_role.map(|r| matches!(r, "libc" | "core-utils" | "udev")).unwrap_or(false);
- let inst_handle = thread::spawn(move || {
- println!("{} [install] Starting install of '{}'", ">>>".cyan(), inst_pkg_for_thread);
- install::install_package_with_result(&inst_pkg_for_thread, &cfg_for_thread)
- });
+ println!("{} Replacing '{}' with '{}'...", "[ror]".blue().bold(), del_pkg, inst_pkg);
- let del_ok = del_handle.join().unwrap_or(false);
- let inst_result = inst_handle.join().unwrap_or_else(|_| Err("install thread panicked".to_string()));
+ if full_rebuild {
+ println!("{} Critical role '{}' — running parallel replace + full system rebuild", ">>>".yellow(), del_role.unwrap());
+ }
- let mut db = install::InstalledDB::load();
+ let del_pkg_c = del_pkg.clone();
+ let inst_pkg_c = inst_pkg.clone();
+ let cfg_c = Arc::clone(&cfg);
- if del_ok {
- db.packages.remove(&del_pkg);
- println!("{} '{}' removed from database", "[ror]".green(), del_pkg);
- }
+ let del_handle = thread::spawn(move || {
+ delete::remove_package_files_only(&del_pkg_c, &record_files)
+ });
+
+ let inst_handle = thread::spawn(move || {
+ install::install_package_with_result(&inst_pkg_c, &cfg_c)
+ });
+
+ let del_ok = del_handle.join().unwrap_or(false);
+ let inst_result = inst_handle.join().unwrap_or_else(|_| Err("panicked".to_string()));
+
+ let mut db = install::InstalledDB::load();
+ if del_ok { db.packages.remove(&del_pkg); }
+ match inst_result {
+ Ok(p) => { db.add_package(p); }
+ Err(e) => { eprintln!("{} Failed to install '{}': {}", "[ror]".red().bold(), inst_pkg, e); }
+ }
+ if let Err(e) = db.save() {
+ eprintln!("{} Failed to save DB: {}", "[ror]".red().bold(), e);
+ return;
+ }
- match inst_result {
- Ok(installed_pkg) => {
- db.add_package(installed_pkg);
- println!("{} '{}' added to database", "[ror]".green(), inst_pkg);
+ if del_ok {
+ if let Some(role) = del_role {
+ let mut sys_cfg = config::Config::load();
+ if delete::is_strict_role(role) {
+ sys_cfg.profile.set_single_role(role, &inst_pkg);
+ } else {
+ sys_cfg.profile.replace_in_list_role(role, &del_pkg, &inst_pkg);
}
- Err(e) => {
- eprintln!("{} Failed to install '{}': {}", "[ror]".red().bold(), inst_pkg, e);
+ if let Err(e) = sys_cfg.save() {
+ eprintln!("{} Failed to update profile: {}", "[ror]".yellow().bold(), e);
+ } else {
+ println!("{} Profile updated: {} = {}", "[ror]".cyan().bold(), role, inst_pkg);
+ if let Some(name) = sys_cfg.profile.group_name() {
+ println!("{} Active group: {}", "[ror]".cyan(), name.cyan());
+ if full_rebuild {
+ println!("{} Running full system rebuild...", ">>>".yellow());
+ let recipe = PathBuf::from(format!("/var/ror/packages/groups/{}.yaml", name));
+ update::rebuild_from_recipe(&recipe, &sys_cfg);
+ }
+ }
}
}
+ }
- if let Err(e) = db.save() {
- eprintln!("{} Failed to save installed DB: {}", "[ror]".red().bold(), e);
- } else {
- println!(
- "{} Replace operation finished: '{}' -> '{}'",
- "[ror]".green().bold(),
- del_pkg,
- inst_pkg
- );
+ println!("{} Replace finished: '{}' -> '{}'", "[ror]".green().bold(), del_pkg, inst_pkg);
+}
+
+fn main() {
+ let args = Args::parse();
+
+ if args.version {
+ println!("ror {}", env!("CARGO_PKG_VERSION"));
+ return;
+ }
+
+ if args.gen_config {
+ let config_path = Path::new("/etc/ror/ror.conf");
+ match config::Config::create_default_config(config_path) {
+ Ok(()) => println!("{} Default config created at {:?}", "[ror]".blue().bold(), config_path),
+ Err(e) => eprintln!("{} Failed to create config: {}", "[ror]".red().bold(), e),
}
+ return;
+ }
+
+ let cfg = Arc::new(config::Config::load());
+ if let Some(di_args) = args.delete_install {
+ run_di(di_args[0].clone(), di_args[1].clone(), cfg);
return;
}
@@ -219,11 +232,7 @@ fn main() {
}
if args.build_rootfs {
- let arch = if args.rootfs_arch == "native" {
- "native"
- } else {
- &args.rootfs_arch
- };
+ let arch = if args.rootfs_arch == "native" { "native" } else { &args.rootfs_arch };
if let (Some(group), Some(target)) = (args.rootfs_group, args.rootfs_target) {
if let Err(e) = rootfs::build_rootfs(&group, &target, &cfg, arch, true) {
eprintln!("{} {}", "[ror]".red().bold(), e);
@@ -247,9 +256,10 @@ fn main() {
if !args.install.is_empty() {
let db = install::InstalledDB::load();
for pkg_name in &args.install {
- if pkg_name.starts_with('@') {
- continue;
- }
+ if pkg_name.starts_with('@') { continue; }
+ let is_local = pkg_name.starts_with('/') || pkg_name.starts_with("./")
+ || pkg_name.ends_with(".ror") || pkg_name.ends_with(".sror");
+ if is_local { continue; }
if let Err(e) = delete::check_critical_install(pkg_name, &db) {
eprintln!("{}", e);
return;
@@ -267,15 +277,56 @@ fn main() {
Err(e) => eprintln!("{} {}", "[ror]".red().bold(), e),
}
} else {
- if let Err(e) = parallel::install_packages_parallel(&args.install, Arc::clone(&cfg)) {
- eprintln!("{} {}", "[ror]".red().bold(), e);
+ let (local_pkgs, remote_pkgs): (Vec<String>, Vec<String>) = args.install.iter()
+ .cloned()
+ .partition(|p| {
+ p.starts_with('/') || p.starts_with("./")
+ || p.ends_with(".ror") || p.ends_with(".sror")
+ });
+ for path_str in &local_pkgs {
+ install::install_local_package(std::path::Path::new(path_str), &cfg);
+ }
+ if !remote_pkgs.is_empty() {
+ if let Err(e) = parallel::install_packages_parallel(&remote_pkgs, Arc::clone(&cfg)) {
+ eprintln!("{} {}", "[ror]".red().bold(), e);
+ }
}
}
return;
}
- if let Some(recipe_path) = args.upgrade {
- update::rebuild_from_recipe(&recipe_path, &cfg);
+ if args.upgrade {
+ match cfg.profile.group_name() {
+ Some(name) => {
+ let recipe = PathBuf::from(format!("/var/ror/packages/groups/{}.yaml", name));
+ println!("{} Upgrading via profile group: {}", "[ror]".blue().bold(), name.cyan());
+ update::rebuild_from_recipe(&recipe, &cfg);
+ }
+ None => {
+ eprintln!(
+ "{} No system profile in ror.conf. Use --up <group> to set a profile first.",
+ "[ror]".red().bold()
+ );
+ }
+ }
+ return;
+ }
+
+ if let Some(group_name) = args.upgrade_to {
+ let recipe = PathBuf::from(format!("/var/ror/packages/groups/{}.yaml", group_name));
+ if !recipe.exists() {
+ eprintln!("{} Group '{}' not found at {}", "[ror]".red().bold(), group_name, recipe.display());
+ return;
+ }
+ let mut sys_cfg = config::Config::load();
+ sys_cfg.profile.active_group = Some(group_name.clone());
+ if let Err(e) = sys_cfg.save() {
+ eprintln!("{} Failed to save profile: {}", "[ror]".red().bold(), e);
+ return;
+ }
+ println!("{} Profile set to group: {}", "[ror]".cyan().bold(), group_name.cyan());
+ println!("{} Upgrading system...", ">>>".yellow());
+ update::rebuild_from_recipe(&recipe, &sys_cfg);
return;
}