1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
use serde::Deserialize;
use std::fs;
use std::path::Path;
use colored::Colorize;
use crate::config;
use crate::install;
#[derive(Debug, Deserialize)]
pub struct Group {
#[allow(dead_code)]
pub name: String,
pub description: Option<String>,
pub libc: Option<String>,
pub version: Option<String>,
pub packages: Vec<String>,
}
#[allow(dead_code)]
pub fn install_group(group_name: &str, cfg: &config::Config) {
let group_file = format!("/var/ror/packages/groups/{}.yaml", group_name);
if !Path::new(&group_file).exists() {
eprintln!("{} Group '{}' not found!", "[ror]".red().bold(), group_name);
return;
}
let content = match fs::read_to_string(&group_file) {
Ok(c) => c,
Err(e) => {
eprintln!("{} Failed to read group file: {}", "[ror]".red().bold(), e);
return;
}
};
let group: Group = match serde_yaml::from_str(&content) {
Ok(g) => g,
Err(e) => {
eprintln!("{} Group YAML error: {}", "[ror]".red().bold(), e);
return;
}
};
println!(
"{} {} Installing group '{}' ({} packages)",
"[ror]".blue().bold(),
">>>".green(),
group.name,
group.packages.len()
);
if let Some(desc) = &group.description {
println!("{} {}", "Description:".yellow(), desc);
}
for pkg in &group.packages {
println!("{} Installing package: {}", ">>>".cyan(), pkg);
install::install_package(pkg, cfg);
}
println!("{} Group '{}' installation completed.", "[ror]".blue().bold(), group.name);
}
pub fn load_group(group_name: &str) -> Result<Group, String> {
let group_file = format!("/var/ror/packages/groups/{}.yaml", group_name);
let content = fs::read_to_string(&group_file)
.map_err(|e| format!("Failed to read group file: {}", e))?;
let group: Group = serde_yaml::from_str(&content)
.map_err(|e| format!("Group YAML error: {}", e))?;
Ok(group)
}
pub fn list_groups() {
let groups_dir = "/var/ror/packages/groups";
if !Path::new(groups_dir).exists() {
println!("{} Groups directory not found.", "[ror]".yellow());
return;
}
println!("{} Available package groups:", "[ror]".blue().bold());
if let Ok(entries) = std::fs::read_dir(groups_dir) {
let mut groups: Vec<String> = entries.flatten()
.filter_map(|e| e.file_name().to_str().map(|s| s.to_string()))
.filter(|n| n.ends_with(".yaml"))
.map(|n| n.trim_end_matches(".yaml").to_string())
.collect();
groups.sort();
for (i, group_name) in groups.iter().enumerate() {
println!(
" {} {}",
format!("[{}]", i + 1).cyan().bold(),
group_name.green()
);
}
}
}
|