Обновление README.md, исходников, пакетки

This commit is contained in:
2026-03-27 13:13:52 +03:00
parent 30540602bd
commit 833f62c739
240 changed files with 2747 additions and 855 deletions

View File

@ -3,18 +3,18 @@ use crate::utils::parser;
pub fn delete(repo: &String, pkgname: &String) {
super::disable::disable(&repo, &pkgname).unwrap();
fs::remove_dir_all(super::get_aeropkg_base().join(&repo).join(&pkgname)).unwrap();
super::disable::disable(repo, pkgname);
fs::remove_dir_all(super::get_aeropkg_base().join(repo).join(pkgname)).unwrap()
}
pub fn delete_recursive(repo: &String, pkgname: &String) {
let pkg_dir = super::get_aeropkg_base().join(repo).join(pkgname);
let pkg_dir = &super::get_aeropkg_base().join(repo).join(pkgname);
if pkg_dir.exists() {
let var_path = super::get_var_path();
let pkg_md_path = var_path.join(format!("{}/{}.md", repo, pkgname));
let var_path = super::get_aeropkg_var();
let pkg_md_path = &var_path.join(format!("{}/{}.md", repo, pkgname));
match parser::get_build_deps(&pkg_md_path) {
match parser::get_build_deps(pkg_md_path) {
Ok(deps) => {
for dependency in deps.lines() {
let dependency = dependency.trim();
@ -33,9 +33,8 @@ pub fn delete_recursive(repo: &String, pkgname: &String) {
}
}
fs::remove_dir_all(&pkg_dir).unwrap();
fs::remove_dir_all(pkg_dir).unwrap()
} else {
eprintln!("{} not installed in {}", pkgname, repo)
println!("{} not installed in {}", pkgname, repo)
}
}

View File

@ -1,14 +1,13 @@
use std::fs;
use crate::utils::fs::deletecopy::deletecopy;
use crate::utils::fs::removelink::removelink;
use crate::utils::shell::*;
pub fn disable(repo: &String, pkgname: &String) -> Result<(), String> {
let source = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
if source.join("disabled").exists() { return Ok(()) };
pub fn disable(repo: &String, pkgname: &String) {
let source = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
if source.join("disabled").exists() { return };
let destination = source.parent()
.ok_or("Failed to get parent directory for path")?
let destination = &source.parent()
.ok_or("Failed to get parent directory for path").unwrap()
.to_path_buf();
let dirs_to_copy = vec![
@ -20,18 +19,14 @@ pub fn disable(repo: &String, pkgname: &String) -> Result<(), String> {
];
for base_system_folder_dir in dirs_to_copy {
let src = source.join(base_system_folder_dir);
let dest = destination.join(base_system_folder_dir);
let src = &source.join(base_system_folder_dir);
let dest = &destination.join(base_system_folder_dir);
if src.exists() {
deletecopy(&src, &dest)
.map_err(|e| format!("Failed to delete copy {} to {}: {}", src.display(), dest.display(), e))?;
}
if src.exists() { removelink(src, dest).map_err(|e| format!("Failed to remove link {} to {}: {}", src.display(), dest.display(), e)).unwrap() }
}
mount_overlay(&destination)?;
shell_update()?;
mount_overlay();
shell_update();
fs::File::create(&source.join("disabled")).ok();
Ok(())
fs::File::create(source.join("disabled")).ok();
}

View File

@ -1,10 +1,9 @@
use std::fs;
use super::link::link;
pub fn enable(repo: &String, pkgname: &String) -> Result<(), String> {
let source = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
let _ = fs::remove_file(&source.join("disabled"));
pub fn enable(repo: &String, pkgname: &String) {
let source = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
let _ = fs::remove_file(source.join("disabled"));
link(&repo, &pkgname)?;
Ok(())
link(repo, pkgname)
}

View File

@ -1,5 +1,6 @@
use std::path::Path;
use std::process;
use std::fs;
use std::os::unix::fs::MetadataExt;
use crate::utils::parser::{self, pkginfo};
use super::run::download::download;
@ -8,63 +9,56 @@ use super::run::build::build;
use super::run::config::config;
pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
let pkg_md_path = crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
pub fn install(repo: &String, pkgname: &String) {
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
let builded_pkg_md_path = crate::commands::get_aeropkg_base().join(repo).join(pkgname).join("build-script.md");
if builded_pkg_md_path.exists() {
if fs::metadata(builded_pkg_md_path).unwrap().ino() == fs::metadata(pkg_md_path).unwrap().ino() { return }
}
check_build_dependency(&repo, &pkg_md_path)?;
check_run_dependency(&pkg_md_path)?;
download(&repo, &pkgname)?;
patch(&repo, &pkgname)?;
build(&repo, &pkgname)?;
config(&repo, &pkgname)?;
println!("Package {} installed successfully from repo {}", pkgname, repo);
Ok(())
check_build_dependency(repo, pkg_md_path);
check_run_dependency(pkg_md_path);
download(repo, pkgname);
patch(repo, pkgname);
build(repo, pkgname);
config(repo, pkgname);
}
fn check_build_dependency(repo: &String, pkg_md_path: &Path) -> Result<(), bool> {
let deps = match parser::get_build_deps(&pkg_md_path) {
fn check_build_dependency(repo: &String, pkg_md_path: &Path) {
let deps = match parser::get_build_deps(pkg_md_path) {
Ok(deps) => deps,
Err(_) => { return Ok(()) }
Err(_) => { return }
};
for dependency in deps.lines() {
if !dependency.trim().is_empty() {
if !super::get_aeropkg_base().join(repo).join(dependency).exists() {
match install(repo, &dependency.to_string()) {
Ok(()) => {}
Err(_) => {process::exit(1) }
}
install(repo, &dependency.to_string())
}
}
}
Ok(())
}
fn check_run_dependency(pkg_md_path: &Path) -> Result<(), bool> {
fn check_run_dependency(pkg_md_path: &Path) {
let deps = match parser::get_run_deps(pkg_md_path) {
Ok(deps) => deps,
Err(_) => { return Ok(()) }
Err(_) => { return }
};
let repo_list = parser::repoinfo::get_repo_list();
let repo_list = &parser::repoinfo::get_repo_list();
for pkgname in deps.split_whitespace() {
let mut found = false;
for repo_name in &repo_list {
for repo_name in repo_list {
let path = super::get_aeropkg_base().join(repo_name).join(pkgname);
if path.exists() {
found = true;
break;
found = true; break
}
}
if !found {
install(&pkginfo::get_priority_repo(pkgname.to_string()), &pkgname.to_string());
install(&pkginfo::get_priority_repo(&pkgname.to_string()), &pkgname.to_string())
}
}
Ok(())
}

View File

@ -1,12 +1,12 @@
use crate::utils::fs::hardcopy::hardcopy_handler;
use crate::utils::shell::*;
pub fn link(repo: &String, pkgname: &String) -> Result<(), String> {
pub fn link(repo: &String, pkgname: &String) {
let source = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
if source.join("disabled").exists() { println!("Can't link disabled package: {}", &pkgname); return Ok(()) }
if source.join("disabled").exists() { println!("Disabled package, no linking: {}\nUse `pkg enable {}` to link", pkgname, pkgname); return }
let destination = source.parent()
.ok_or("Failed to get parent directory for path")?
.ok_or("Failed to get parent directory for path").unwrap()
.to_path_buf();
let dirs_to_copy = vec![
@ -24,12 +24,10 @@ pub fn link(repo: &String, pkgname: &String) -> Result<(), String> {
if src.exists() {
hardcopy_handler(&src, &dest)
.map_err(|e| format!("Failed to copy {} to {}: {}", src.display(), dest.display(), e))?;
.map_err(|e| format!("Failed to copy {} to {}: {}", src.display(), dest.display(), e)).unwrap()
}
}
mount_overlay(&destination)?;
shell_update()?;
Ok(())
mount_overlay();
shell_update()
}

View File

@ -9,18 +9,18 @@ pub mod run;
use std::path::PathBuf;
pub fn get_var_path() -> PathBuf {
PathBuf::from(env!("AEROPKG_HOME")).join("var")
pub fn get_aeropkg_var() -> PathBuf {
PathBuf::from(env!("aeropkg_home")).join("var")
}
pub fn get_etc_path() -> PathBuf {
PathBuf::from(env!("AEROPKG_HOME")).join("etc")
pub fn get_aeropkg_etc() -> PathBuf {
PathBuf::from(env!("aeropkg_home")).join("etc")
}
pub fn get_aeropkg_home() -> PathBuf {
PathBuf::from(env!("AEROPKG_HOME"))
PathBuf::from(env!("aeropkg_home"))
}
pub fn get_aeropkg_base() -> PathBuf {
PathBuf::from(env!("AEROPKG_BASE"))
PathBuf::from(env!("aeropkg_base"))
}

View File

@ -1,5 +1,4 @@
use std::fs;
use std::os::unix::fs::MetadataExt;
use crate::utils::parser::{self, env::get_install_env};
use crate::utils::shell::{run_install_script,run_install_script_hook};
@ -8,81 +7,67 @@ use super::download::download;
use super::patch::patch;
pub fn build(
repo: &String,
pkgname: &String,
) -> Result<(), bool> {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(&pkgname);
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
let builded_pkg_md_path = crate::commands::get_aeropkg_base().join(&repo).join(&pkgname).join("build-script.md");
if builded_pkg_md_path.exists() {
if fs::metadata(&builded_pkg_md_path).unwrap().ino() == fs::metadata(&pkg_md_path).unwrap().ino() {
println!("package {} already installed in {} repo", &pkgname, &repo);
return Ok(())
}
}
pub fn build(repo: &String, pkgname: &String) {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(pkgname);
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
let builded_pkg_md_path = &crate::commands::get_aeropkg_base().join(repo).join(pkgname).join("build-script.md");
let build_script = match parser::get_build_script(pkg_md_path) {
Ok(script) => script,
Err(error) => {
eprintln!("Failed to parse build script: {}", error);
return Err(false);
panic!("Failed to parse build script: {}", error);
}
};
if builded_pkg_md_path.exists() {
let builded_script = match parser::get_build_script(builded_pkg_md_path) {
Ok(script) => script,
Err(error) => {
panic!("Failed to parse build block from {}: {}", builded_pkg_md_path.to_string_lossy(), error);
}
};
if build_script == builded_script { return }
}
if src_dir.join("aeropkg.applied-build").exists() {
let src_build = fs::read_to_string(src_dir.join("aeropkg.applied-build")).unwrap_or("".to_string());
if build_script == src_build {
return Ok(())
return
} else {
println!("build:\n{}\nend build", build_script);
println!("src build:\n{}\nend src build", src_build);
fs::remove_dir_all(src_dir).unwrap();
download(&repo, &pkgname)?;
patch(&repo, &pkgname)?;
download(repo, pkgname);
patch(repo, pkgname)
}
}
let full_env = get_install_env(repo, pkgname, pkg_md_path, "build");
run_install_script(&build_script, src_dir, &full_env)?;
run_install_script_hook(repo, "build", &full_env)?;
run_install_script(&build_script, src_dir, &full_env);
run_install_script_hook(repo, "build", &full_env);
let dest_dir = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
if let Err(e) = fs::create_dir_all(&dest_dir) {
eprintln!("Failed to create destination directory: {}", e);
return Err(false);
}
let dest_path = dest_dir.join("build-script.md");
fs::remove_file(&dest_path).ok();
if let Err(e) = fs::hard_link(pkg_md_path, &dest_path) {
eprintln!("Failed to copy build script to destination: {}", e);
return Err(false);
}
if let Err(e) = fs::create_dir_all(&dest_dir) { panic!("Failed to create destination directory: {}", e) }
let dest_path = &dest_dir.join("build-script.md");
fs::remove_file(dest_path).ok();
if let Err(e) = fs::hard_link(pkg_md_path, dest_path) { panic!("Failed to copy build script to destination: {}", e) }
fs::write(src_dir.join("aeropkg.build-script"), &build_script).unwrap();
let save_source_flag = full_env.get("save_source").map_or(false, |v| v == "true");
if !save_source_flag {
if let Err(e) = fs::remove_dir_all(&src_dir) { panic!("Failed to remove source directory: {}", e) }
}
hook(repo, pkgname);
let link_flag = full_env.get("disable").map_or(true, |v| v != "true");
if !link_flag {
let _ = fs::File::create(crate::commands::get_aeropkg_base().join(repo).join(pkgname).join("disabled"));
}
link(&repo, &pkgname).expect("Failed link package");
let save_source_flag = full_env.get("save_source").map_or(false, |v| v == "true");
if !save_source_flag {
if let Err(e) = fs::remove_dir_all(&src_dir) {
eprintln!("Failed to remove source directory: {}", e);
return Err(false);
}
}
hook(&repo, &pkgname);
Ok(())
link(repo, pkgname)
}
fn hook(repo: &String, pkgname: &String) {
let pkg_dir = crate::commands::get_aeropkg_base().join(&repo).join(&pkgname);
let pkg_dir = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
let lib_dir = &pkg_dir.join("lib");
let lib64_dir = &pkg_dir.join("lib64");
let lib32_dir = &pkg_dir.join("lib32");

View File

@ -3,23 +3,18 @@ use crate::utils::parser::{self, env::get_install_env};
use crate::utils::shell::{run_install_script,run_install_script_hook};
pub fn config(
repo: &String,
pkgname: &String
) -> Result<(), bool> {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(&pkgname);
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
pub fn config(repo: &String, pkgname: &String) {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(pkgname);
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
let config_script = match parser::get_config_script(pkg_md_path) {
Ok(script) => script,
Err(_) => { return Ok(()) }
Err(_) => { return }
};
let full_env = get_install_env(repo, pkgname, pkg_md_path, "config");
run_install_script(&config_script, src_dir, &full_env)?;
run_install_script_hook(repo, "config", &full_env)?;
run_install_script(&config_script, src_dir, &full_env);
run_install_script_hook(repo, "config", &full_env);
link(&repo, &pkgname).expect("Failed link package");
Ok(())
link(repo, pkgname)
}

View File

@ -2,14 +2,11 @@ use crate::utils::parser::{self, env::get_custom_env};
use crate::utils::shell::run_install_script;
pub fn custom(scriptname: &String, repo: &String, pkgname: &String) -> Result<(), bool> {
pub fn custom(scriptname: &String, repo: &String, pkgname: &String) {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(&pkgname);
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
let config_script = parser::get_custom_script(pkg_md_path, scriptname);
let env = get_custom_env(repo, pkgname, pkg_md_path);
run_install_script(&config_script, src_dir, &env)?;
Ok(())
let config_script = &parser::get_custom_script(pkg_md_path, scriptname);
let env = &get_custom_env(repo, pkgname, pkg_md_path);
run_install_script(config_script, src_dir, env)
}

View File

@ -5,35 +5,81 @@ use std::process::{Command, Stdio};
use crate::utils::parser::{self, env::get_install_env};
use crate::utils::shell::run_install_script_hook;
pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
if !pkg_md_path.exists() { upload_from_repo(&repo, &pkgname, &pkg_md_path)? }
pub fn download(repo: &String, pkgname: &String) {
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
if !pkg_md_path.exists() { upload_from_repo(repo, pkgname, pkg_md_path) }
let full_env = get_install_env(repo, pkgname, pkg_md_path, "download");
let url = match parser::pkginfo::get_url(pkg_md_path) {
Ok(url) => url,
Err(e) => {
eprintln!("Failed to parse URL: {}", e);
return Err(false);
panic!("Failed to parse URL: {}", e)
}
};
let src = crate::commands::get_aeropkg_base().join("src").join(pkgname);
if src.exists() {
let src_url = fs::read_to_string(src.join("aeropkg.download-url")).unwrap_or("".to_string());
if url == src_url {
return Ok(())
} else {
fs::remove_dir_all(&src).unwrap();
if url == src_url { return }
else {
fs::remove_dir_all(&src).unwrap()
}
}
if url.ends_with(".git") || url.starts_with("git://") {
let git_status = Command::new("git")
.arg("clone")
.arg(&url)
.arg(&src)
.status();
if !url.ends_with(".git") {
if git_status.is_err() || !git_status.unwrap().success() {
panic!("Failed to clone git repository from URL: {}", url)
}
}
else if url.is_empty() { return }
else if url.ends_with(".zip") {
if let Err(e) = fs::create_dir_all(&src) {
eprintln!("Failed to create directory {}: {}", &src.display(), e);
return Err(false);
panic!("Failed to create directory {}: {}", &src.display(), e)
}
let zip_path = src.join("archive.zip");
let wget_status = Command::new("wget")
.arg("-O")
.arg(&zip_path)
.arg("-q")
.arg("--show-progress")
.arg(&url)
.envs(&full_env)
.status();
if wget_status.is_err() || !wget_status.unwrap().success() {
panic!("Failed to download zip archive from URL: {}", url)
}
let output_flag = format!("-o{}", src.display());
let sevenz_status = Command::new("7z")
.arg("x")
.arg(&zip_path)
.arg(output_flag)
.arg("-y")
.arg("-bd")
.arg("-bso0")
.arg("-bse0")
.arg("-bsp0")
.envs(&full_env)
.status();
if sevenz_status.is_err() || !sevenz_status.unwrap().success() {
panic!("Failed to extract zip archive from URL: {}", url)
}
fs::remove_file(&zip_path).ok();
}
else {
if let Err(e) = fs::create_dir_all(&src) {
panic!("Failed to create directory {}: {}", &src.display(), e)
}
let compress_flag = if url.ends_with(".bz2") {
"--bzip2"
@ -50,8 +96,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
} else if url.ends_with(".gz") {
"--gzip"
} else {
eprintln!("Unsupported compression format for URL: {}", url);
return Err(false);
panic!("Unsupported compression format for URL: {}", url)
};
let wget_output = Command::new("wget")
@ -65,10 +110,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
let tar_input = match wget_output {
Ok(child) => child.stdout.unwrap(),
Err(e) => {
eprintln!("Failed to execute wget: {}", e);
return Err(false);
}
Err(e) => { panic!("Failed to execute wget: {}", e) }
};
let tar_status = Command::new("tar")
@ -81,8 +123,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
.status();
if tar_status.is_err() || !tar_status.unwrap().success() {
eprintln!("Failed to extract archive from URL: {}", url);
return Err(false);
panic!("Failed to extract archive from URL: {}", url)
}
let entries = fs::read_dir(&src).unwrap();
@ -100,29 +141,16 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
fs::rename(entry.path(), dest).unwrap();
}
fs::remove_dir(single_dir).unwrap();
}
} else {
let git_status = Command::new("git")
.arg("clone")
.arg(&url)
.arg(&src)
.status();
if git_status.is_err() || !git_status.unwrap().success() {
eprintln!("Failed to clone git repository from URL: {}", url);
return Err(false);
fs::remove_dir(single_dir).unwrap()
}
}
fs::write(src.join("aeropkg.download-url"), &url).unwrap();
run_install_script_hook(repo, "download", &full_env)?;
Ok(())
run_install_script_hook(repo, "download", &full_env)
}
fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Result<(), bool> {
fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) {
let repo_addr = parser::repoinfo::get_repo_addr(repo);
let rsync_command = format!(
"rsync --include='{}.md' --exclude='*' {} {}",
@ -137,13 +165,9 @@ fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Resu
.expect("Failed to execute rsync");
if !rsync_output.status.success() {
eprintln!("broken repo: {}", repo);
return Err(false);
panic!("broken repo: {}", repo)
}
if !pkg_md_path.exists() {
eprintln!("not found {} in {} repo", pkgname, repo);
return Err(true);
panic!("not found {} in {} repo", pkgname, repo)
}
Ok(())
}

View File

@ -4,29 +4,22 @@ use crate::utils::parser::{self, env::get_install_env};
use crate::utils::shell::{run_install_script,run_install_script_hook};
use super::download::download;
pub fn patch(
repo: &String,
pkgname: &String,
) -> Result<(), bool> {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(&pkgname);
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
pub fn patch(repo: &String, pkgname: &String) {
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(pkgname);
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
let patch_script = &parser::get_patch_script(pkg_md_path).unwrap_or("".to_string());
if src_dir.join("aeropkg.applied-patch").exists() {
let src_patch = &fs::read_to_string(src_dir.join("aeropkg.applied-patch")).unwrap_or("".to_string());
if patch_script == src_patch {
return Ok(())
} else {
if patch_script == src_patch { return }
else if src_patch != "" {
fs::remove_dir_all(src_dir).unwrap();
download(&repo, &pkgname)?;
download(repo, pkgname)
}
}
if patch_script == "" { return Ok(()) }
let full_env = get_install_env(repo, pkgname, pkg_md_path, "patch");
run_install_script(patch_script, src_dir, &full_env)?;
run_install_script_hook(repo, "patch", &full_env)?;
fs::write(src_dir.join("aeropkg.applied-patch"), &patch_script).unwrap();
Ok(())
run_install_script(patch_script, src_dir, &full_env);
run_install_script_hook(repo, "patch", &full_env);
fs::write(src_dir.join("aeropkg.applied-patch"), &patch_script).unwrap()
}

View File

@ -2,13 +2,13 @@ use super::download::download;
use super::patch::patch;
use super::build::build;
use super::config::config;
use super::custom::custom;
pub fn run(script: &String, repo: &String, pkgname: &String) -> Result<(), bool> {
if script == "download" { download(&repo, &pkgname)?; return Ok(()) }
if script == "patch" { patch(&repo, &pkgname)?; return Ok(()) }
if script == "build" { build(&repo, &pkgname)?; return Ok(()) }
if script == "config" { config(&repo, &pkgname)?; return Ok(()) }
Ok(())
pub fn run(script: &String, repo: &String, pkgname: &String) {
if script == "download" { download(repo, pkgname) }
else if script == "patch" { patch(repo, pkgname) }
else if script == "build" { build(repo, pkgname) }
else if script == "config" { config(repo, pkgname) }
else { custom(script, repo, pkgname) }
}

View File

@ -4,23 +4,30 @@ use std::os::unix::fs::MetadataExt;
use glob::Pattern;
pub fn trim_handler(repo: &String, trim_date: i64) {
let etc_path = super::get_aeropkg_etc();
let cfg_path = etc_path.join("aeropkg.md");
let rules = &crate::utils::parser::get_trim_rules(&cfg_path).unwrap();
let pkg_dir = &super::get_aeropkg_base().join(repo);
fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) -> Result<(), std::io::Error> {
let metadata = fs::symlink_metadata(path)?;
trim(repo, pkg_dir, trim_date, rules)
}
fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) {
let metadata = fs::symlink_metadata(path).unwrap();
if metadata.is_dir() {
if rules_check(repo, path, rules) {
for entry in fs::read_dir(path)? {
let entry = entry?;
let entry_path = entry.path();
trim(repo, &entry_path, trim_date, rules)?;
for entry in fs::read_dir(path).unwrap() {
let entry_path = &entry.unwrap().path();
trim(repo, entry_path, trim_date, rules)
}
}
} else if metadata.is_file() {
if rules_check(repo, path, rules) {
let atime = metadata.atime();
if atime < trim_date {
fs::remove_file(path)?;
if let Err(e) = fs::remove_file(path) { panic!("Failed to remove file: {}", e) }
}
}
} else if metadata.file_type().is_symlink() {
@ -28,26 +35,12 @@ fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) -> Result<(
let symlink_path = if symlink_value.is_relative() { path.parent().unwrap().join(&symlink_value) } else { symlink_value };
if !symlink_path.exists() {
println!("remove symlink: {} {}", path.display(), symlink_path.display());
fs::remove_file(path)?;
fs::remove_file(path).unwrap();
}
}
}
Ok(())
}
pub fn trim_handler(repo: &String, trim_date: i64) {
let etc_path = super::get_etc_path();
let cfg_path = etc_path.join("aeropkg.md");
let rules = crate::utils::parser::get_trim_rules(&cfg_path).unwrap();
let pkg_dir = super::get_aeropkg_base().join(repo);
trim(repo, &pkg_dir, trim_date, &rules).unwrap();
}
fn rules_check(repo: &String, path: &Path, rules: &String) -> bool {
let mut confirm = true;
@ -60,16 +53,16 @@ fn rules_check(repo: &String, path: &Path, rules: &String) -> bool {
}
let wildcard_string = if rule.starts_with('/') {
rule.to_string()
&rule.to_string()
} else {
super::get_aeropkg_base().join(repo).join(rule).to_string_lossy().into_owned()
&super::get_aeropkg_base().join(repo).join(rule).to_string_lossy().into_owned()
};
let path_str = path.to_str().unwrap_or("");
if let Ok(pattern) = Pattern::new(&wildcard_string) {
if let Ok(pattern) = Pattern::new(wildcard_string) {
if pattern.matches(path_str) {
confirm = !invert;
confirm = !invert
}
}
}

View File

@ -4,6 +4,14 @@ mod commands;
mod utils;
fn main() {
#[cfg(not(debug_assertions))]
{
std::panic::set_hook(Box::new(|info| {
eprintln!("{}", info);
std::process::exit(1);
}));
}
for (key, value) in utils::parser::env::get_global_env() {
unsafe { std::env::set_var(key, value) }
}

View File

@ -1,36 +1,57 @@
use crate::commands;
use crate::utils::parser::pkginfo;
pub fn delete(matches: &clap::ArgMatches) {
let repo = matches.get_one::<String>("repo").unwrap();
let pkgname = matches.get_one::<String>("pkgname").unwrap();
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
let recursive = matches.get_flag("recursive");
if recursive {
commands::delete::delete_recursive(repo, pkgname);
} else {
commands::delete::delete(repo, pkgname);
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo_installed(&pkgname.to_string())
};
if recursive {
commands::delete::delete_recursive(resolved_repo, &pkgname.to_string())
} else {
commands::delete::delete(resolved_repo, &pkgname.to_string())
}
}
}
pub fn command() -> clap::Command {
clap::Command::new("delete")
.about("Delete a package from a repository")
.about("Delete package")
.arg(
clap::Arg::new("repo")
.help("Repository name")
.required(true),
.long("repo")
.short('r')
.help("Specify the repository to delete the package(s) from (applies to all packages)")
.value_name("REPO")
.num_args(1)
)
.arg(
clap::Arg::new("pkgname")
.help("Package name")
.required(true),
.help("Name(s) of the package(s) to delete")
.required(true)
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
.arg(
clap::Arg::new("recursive")
.short('R')
.long("recursive")
.help("Recursively delete the package")
.action(clap::ArgAction::SetTrue),
.action(clap::ArgAction::SetTrue)
)
}

View File

@ -1,29 +1,45 @@
use crate::commands;
use crate::utils::parser::pkginfo;
pub fn disable(matches: &clap::ArgMatches) {
let repo = matches.get_one::<String>("repo").unwrap();
let pkgname = matches.get_one::<String>("pkgname").unwrap();
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
match commands::disable::disable(&repo, &pkgname) {
Ok(_) => println!("disable completed successfully."),
Err(e) => eprintln!("Error during disable: {}", e),
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo(&pkgname.to_string())
};
commands::disable::disable(resolved_repo, &pkgname.to_string());
}
}
pub fn command() -> clap::Command {
clap::Command::new("disable")
.about("Disable package")
.arg(
clap::Arg::new("repo")
.help("Repository name")
.required(true)
.index(1),
.long("repo")
.short('r')
.help("Specify the repository to install the package(s) from (applies to all packages)")
.value_name("REPO")
.num_args(1)
)
.arg(
clap::Arg::new("pkgname")
.help("Package name")
.help("Name(s) of the package(s) to install")
.required(true)
.index(2),
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
}

View File

@ -1,29 +1,43 @@
use crate::commands;
use crate::utils::parser::pkginfo;
pub fn enable(matches: &clap::ArgMatches) {
let repo = matches.get_one::<String>("repo").unwrap();
let pkgname = matches.get_one::<String>("pkgname").unwrap();
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
match commands::enable::enable(&repo, &pkgname) {
Ok(_) => println!("enable completed successfully."),
Err(e) => eprintln!("Error during enable: {}", e),
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo(&pkgname.to_string())
};
commands::enable::enable(resolved_repo, &pkgname.to_string());
}
}
pub fn command() -> clap::Command {
clap::Command::new("enable")
.about("Enable package")
.arg(
clap::Arg::new("repo")
.help("Repository name")
.required(true)
.index(1),
.long("repo")
.short('r')
.help("Specify the repository to install the package(s) from (applies to all packages)")
.value_name("REPO")
.num_args(1)
)
.arg(
clap::Arg::new("pkgname")
.help("Package name")
.help("Name(s) of the package(s) to install")
.required(true)
.index(2),
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
}

View File

@ -1,33 +1,42 @@
use crate::commands;
use crate::utils::parser::pkginfo;
pub fn install(matches: &clap::ArgMatches) {
let args: Vec<&String> = matches.get_many::<String>("args").unwrap().collect();
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
match args.len() {
1 => {
let pkgname = args[0];
commands::install::install(&pkginfo::get_priority_repo(pkgname.to_string()), &pkgname.to_string());
}
2 => {
let repo = args[0];
let pkgname = args[1];
if let Err(_) = commands::install::install(repo, pkgname) { std::process::exit(1) }
}
_ => unreachable!(),
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo(&pkgname.to_string())
};
commands::install::install(resolved_repo, &pkgname.to_string());
}
}
pub fn command() -> clap::Command {
clap::Command::new("install")
.about("Install a package")
.about("Install one or more packages")
.arg(
clap::Arg::new("args")
.help("Repository and package name (optional repo)")
clap::Arg::new("repo")
.long("repo")
.short('r')
.help("Specify the repository to install the package(s) from (applies to all packages)")
.value_name("REPO")
.num_args(1)
)
.arg(
clap::Arg::new("pkgname")
.help("Name(s) of the package(s) to install")
.required(true)
.num_args(1..=2)
.value_names(["repo", "pkgname"]),
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
}

View File

@ -1,29 +1,43 @@
use crate::commands;
use crate::utils::parser::pkginfo;
pub fn link(matches: &clap::ArgMatches) {
let repo = matches.get_one::<String>("repo").unwrap();
let pkgname = matches.get_one::<String>("pkgname").unwrap();
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
match commands::link::link(&repo, &pkgname) {
Ok(_) => println!("link completed successfully."),
Err(e) => eprintln!("Error during link: {}", e),
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo_installed(&pkgname.to_string())
};
commands::link::link(resolved_repo, &pkgname.to_string());
}
}
pub fn command() -> clap::Command {
clap::Command::new("link")
.about("Create package links and mount overlays")
.arg(
clap::Arg::new("repo")
.help("Repository name")
.required(true)
.index(1),
)
.arg(
clap::Arg::new("pkgname")
.help("Package name")
.required(true)
.index(2),
)
.about("Create package links and mount overlays")
.arg(
clap::Arg::new("repo")
.long("repo")
.short('r')
.help("Specify the repository to install the package(s) from (applies to all packages)")
.value_name("REPO")
.num_args(1)
)
.arg(
clap::Arg::new("pkgname")
.help("Name(s) of the package(s) to install")
.required(true)
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
}

View File

@ -1,43 +1,53 @@
use crate::commands;
use crate::utils::parser::pkginfo;
// pkg run <script> [repo] <pkgname>
// pkg run kernel_change gnu linux-6.17
// pkg run kernel_change linux-6.17
//
// pkg md_path должен брать из уже установленного ?
// Или пусть проверяет
pub fn run(matches: &clap::ArgMatches) {
let args: Vec<&String> = matches.get_many::<String>("args").unwrap().collect();
let scriptname = &matches
.get_one::<String>("scriptname")
.expect("scriptname is required")
.to_string();
match args.len() {
2 => {
let pkgname = args[1];
let scriptname = args[0];
commands::run::custom::custom(scriptname , &pkginfo::get_priority_repo(pkgname.to_string()), &pkgname.to_string());
}
3 => {
let scriptname = args[0];
let repo = args[0];
let pkgname = args[1];
commands::run::custom::custom(scriptname , &repo, &pkgname.to_string());
if let Err(_) = commands::install::install(repo, pkgname) { std::process::exit(1) }
}
_ => unreachable!(),
let pkg_names: Vec<&str> = matches
.get_many::<String>("pkgname")
.expect("At least one package name is required")
.map(|s| s.as_str())
.collect();
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
for pkgname in pkg_names {
let resolved_repo = if let Some(explicit_repo) = repo {
&explicit_repo.to_string()
} else {
&pkginfo::get_priority_repo(&pkgname.to_string())
};
commands::run::run::run(scriptname, resolved_repo, &pkgname.to_string());
}
}
pub fn command() -> clap::Command {
clap::Command::new("run")
.about("Install a package")
.about("Run a script on one or more packages")
.arg(
clap::Arg::new("args")
.help("Repository and package name (optional repo)")
clap::Arg::new("scriptname")
.help("Name of the script to run")
.required(true)
.num_args(1..=2)
.value_names(["repo", "pkgname"]),
.value_name("SCRIPTNAME")
)
.arg(
clap::Arg::new("pkgname")
.help("Name(s) of the package(s) to run the script on")
.required(true)
.value_name("PKGNAME")
.action(clap::ArgAction::Append)
)
.arg(
clap::Arg::new("repo")
.long("repo")
.short('r')
.help("Specify the repository to use for all packages")
.value_name("REPO")
.num_args(1)
)
}

View File

@ -6,14 +6,14 @@ pub fn trim(matches: &clap::ArgMatches) {
let date = matches.get_one::<String>("date").unwrap();
let time = matches.get_one::<String>("time").map(|s| s.as_str()).unwrap_or("00:00:00");
let datetime_str = format!("{} {}", date, time);
let datetime_str = &format!("{} {}", date, time);
let datetime = NaiveDateTime::parse_from_str(&datetime_str, "%d.%m.%Y %H:%M:%S")
let datetime = NaiveDateTime::parse_from_str(datetime_str, "%d.%m.%Y %H:%M:%S")
.expect("Invalid date or time format. Expected format: DD.MM.YYYY HH:mm:ss");
let trim_date = datetime.and_utc().timestamp();
commands::trim::trim_handler(&repo, trim_date);
commands::trim::trim_handler(repo, trim_date)
}
pub fn command() -> clap::Command {

View File

@ -11,7 +11,7 @@ use std::thread;
fn hardcopy(
source: &Path,
destination: &Path,
conflict_sender: Option<mpsc::Sender<(Vec<PathBuf>, mpsc::Sender<PathBuf>)>>,
conflict_sender: Option<mpsc::Sender<(Vec<PathBuf>, mpsc::Sender<PathBuf>)>>
) -> io::Result<()> {
let metadata = fs::symlink_metadata(source)?;
@ -22,7 +22,7 @@ fn hardcopy(
Err(_) => {
if let Ok(dest_metadata) = fs::metadata(destination) {
if dest_metadata.ino() == metadata.ino() {
return Ok(());
return Ok(())
}
}
@ -30,9 +30,9 @@ fn hardcopy(
Ok(index_source) => {
if index_source == source {
fs::remove_file(destination)?;
fs::hard_link(source, destination)?;
fs::hard_link(source, destination)?
} else {
return Ok(());
return Ok(())
}
}
Err(_) => {
@ -41,20 +41,19 @@ fn hardcopy(
let count = conflict_list.len();
if count == 1 {
fs::remove_file(destination)?;
fs::hard_link(source, destination)?;
fs::hard_link(source, destination)?
} else if count >= 1 {
let (response_tx, response_rx) = mpsc::channel();
if let Some(sender) = &conflict_sender {
sender.send((conflict_list.clone(), response_tx)).unwrap(); }
if let Some(sender) = &conflict_sender { sender.send((conflict_list.clone(), response_tx)).unwrap() }
let selected_source = response_rx.recv().unwrap();
append_index_block(&selected_source, &destination)?;
append_index_conflict(&selected_source, &destination)?;
if selected_source == source {
fs::remove_file(destination)?;
fs::hard_link(source, destination)?;
fs::hard_link(source, destination)?
} else {
return Ok(());
return Ok(())
}
}
}
@ -73,20 +72,17 @@ fn hardcopy(
} else {
Ok(())
}
})?;
})?
} else if metadata.file_type().is_symlink() {
let symlink_value = fs::read_link(source)?;
if destination.exists() { fs::remove_file(destination)? }
unix::fs::symlink(symlink_value, destination)?;
unix::fs::symlink(symlink_value, destination)?
}
Ok(())
}
pub fn hardcopy_handler(
source: &Path,
destination: &Path,
) -> io::Result<()> {
pub fn hardcopy_handler(source: &Path, destination: &Path) -> io::Result<()> {
let (tx, rx): (
mpsc::Sender<(Vec<PathBuf>, mpsc::Sender<PathBuf>)>,
mpsc::Receiver<(Vec<PathBuf>, mpsc::Sender<PathBuf>)>,
@ -95,8 +91,7 @@ pub fn hardcopy_handler(
thread::spawn(move || {
for (conflict_list, response_tx) in rx {
let selected_source = choise_index_conflict(conflict_list);
response_tx.send(selected_source).unwrap();
response_tx.send(selected_source).unwrap()
}
});
@ -109,14 +104,8 @@ fn find_files_with_location(destination: &Path) -> Vec<PathBuf> {
let mut components = destination.components();
let prefix = match (components.next(), components.next(), components.next()) {
(Some(first), Some(second), Some(third)) => {
PathBuf::from(first.as_os_str())
.join(second.as_os_str())
.join(third.as_os_str())
}
_ => {
return Vec::new();
}
(Some(first), Some(second), Some(third)) => { PathBuf::from(first.as_os_str()).join(second.as_os_str()).join(third.as_os_str()) }
_ => { return Vec::new() }
};
let file_location: PathBuf = components.as_path().to_path_buf();
@ -129,7 +118,7 @@ fn find_files_with_location(destination: &Path) -> Vec<PathBuf> {
let target_path = path.join(&file_location);
if target_path.exists() {
if !path.join(PathBuf::from("disabled")).exists() {
found_files.push(target_path);
found_files.push(target_path)
}
}
}
@ -139,10 +128,9 @@ fn find_files_with_location(destination: &Path) -> Vec<PathBuf> {
found_files
}
fn choise_index_conflict(conflict_list: Vec<PathBuf>) -> PathBuf {
for (index, path) in conflict_list.iter().enumerate() {
println!("{}: {}", index + 1, path.display());
println!("{}: {}", index + 1, path.display())
}
let count = conflict_list.len();
@ -157,60 +145,26 @@ fn choise_index_conflict(conflict_list: Vec<PathBuf>) -> PathBuf {
.expect("Failed to read input");
match input.trim().parse::<usize>() {
Ok(selected) if selected >= 1 && selected <= count => {
return conflict_list[selected - 1].clone();
}
_ => {
println!("Invalid input. Please enter a number between 1 and {}.", count);
}
Ok(selected) if selected >= 1 && selected <= count => { return conflict_list[selected - 1].clone() }
_ => { println!("Invalid input. Please enter a number between 1 and {}.", count) }
}
}
}
fn append_index_conflict(source: &Path, destination: &Path) -> io::Result<()> {
let source_str = source.to_str().ok_or_else(|| { io::Error::new(io::ErrorKind::InvalidInput, "source path is not valid UTF-8") })?;
let dest_str = destination.to_str().ok_or_else(|| { io::Error::new(io::ErrorKind::InvalidInput, "destination path is not valid UTF-8") })?;
fn append_index_block(source: &Path, destination: &Path) -> io::Result<()> {
let source_components: Vec<_> = source.iter().collect();
let base_system_folder = source_components[4].to_str().unwrap();
let new_line = format!("{} {}\n", dest_str, source_str);
let index_conflict_path = crate::commands::get_etc_path().join("index-conflict.md");
let content = fs::read_to_string(&index_conflict_path)?;
let index_conflict_path = crate::commands::get_aeropkg_etc().join("index-conflict.md");
let start_marker = format!("``` cfg *** {} ***", base_system_folder);
let lines: Vec<&str> = content.lines().collect();
let mut start_block_index = None;
let mut end_block_index = None;
let mut file = fs::OpenOptions::new()
.create(true)
.append(true)
.open(&index_conflict_path)?;
for (i, line) in lines.iter().enumerate() {
if line.contains(&start_marker) {
start_block_index = Some(i);
} else if start_block_index.is_some() && line.trim() == "```" {
end_block_index = Some(i);
break;
}
}
let end_block_index = end_block_index.ok_or_else(|| {
io::Error::new(io::ErrorKind::InvalidData, "End block not found")
})?;
let new_line = format!(
"{} {}",
destination.to_str().unwrap(),
source.to_str().unwrap()
);
let mut new_content = String::new();
for (i, line) in lines.iter().enumerate() {
if i == end_block_index {
new_content.push_str(&new_line);
new_content.push('\n');
}
new_content.push_str(line);
new_content.push('\n');
}
let mut file = fs::File::create(&index_conflict_path)?;
file.write_all(new_content.as_bytes())?;
file.write_all(new_line.as_bytes())?;
Ok(())
}

View File

@ -1,3 +1,3 @@
pub mod hardcopy;
pub mod deletecopy;
pub mod removelink;
pub mod mv;

View File

@ -18,7 +18,7 @@ pub fn mv(source: &Path, destination: &Path) -> io::Result<()> {
} else {
Ok(())
}
})?;
})?
} else if metadata.file_type().is_symlink() {
fs::rename(source, destination).ok();
}

View File

@ -5,14 +5,14 @@ use std::path::Path;
use std::os::unix::fs::MetadataExt;
pub fn deletecopy(source: &Path, destination: &Path) -> io::Result<()> {
pub fn removelink(source: &Path, destination: &Path) -> io::Result<()> {
let metadata = fs::symlink_metadata(source)?;
if metadata.file_type().is_file() {
if let Ok(dest_metadata) = fs::metadata(destination) {
if dest_metadata.ino() == metadata.ino() {
fs::remove_file(destination).ok();
return Ok(());
return Ok(())
}
}
} else if metadata.file_type().is_dir() {
@ -20,11 +20,11 @@ pub fn deletecopy(source: &Path, destination: &Path) -> io::Result<()> {
entries.par_iter().try_for_each(|entry| {
let path_source = entry.path();
if let Some(file_name) = path_source.file_name() {
deletecopy(&path_source, &destination.join(file_name))
removelink(&path_source, &destination.join(file_name))
} else {
Ok(())
}
})?;
})?
} else if metadata.file_type().is_symlink() {
fs::remove_file(destination).ok();
}

View File

@ -32,14 +32,16 @@ pub fn get_custom_env(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Ha
pub fn get_global_env() -> HashMap<String, String> {
let mut full_env = HashMap::new();
full_env.insert("repo".to_string(), repo.clone());
full_env.insert("pkgname".to_string(), pkgname.clone());
full_env.insert("aeropkg_home".to_string(), crate::commands::get_aeropkg_home().to_string_lossy().into_owned().clone());
full_env.insert("aeropkg_base".to_string(), crate::commands::get_aeropkg_base().to_string_lossy().into_owned().clone());
full_env.insert("aeropkg_etc".to_string(), crate::commands::get_aeropkg_etc().to_string_lossy().into_owned().clone());
full_env.insert("aeropkg_var".to_string(), crate::commands::get_aeropkg_var().to_string_lossy().into_owned().clone());
if let Some(global_env) = get_global_env_string().ok() { full_env.extend(global_env) }
return full_env
}
fn get_global_env_string() -> io::Result<HashMap<String, String>> {
let cfg_path = crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = crate::commands::get_aeropkg_etc().join("aeropkg.md");
let content = extract_block(&cfg_path, &format!("``` env *** env ***"), "```")?;
Ok(parse_env_vars(&content))
}
@ -49,13 +51,9 @@ fn parse_env_vars(content: &str) -> HashMap<String, String> {
.lines()
.filter_map(|line| {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
return None;
}
if line.is_empty() || line.starts_with('#') { return None }
let parts: Vec<&str> = line.splitn(2, '=').collect();
if parts.len() != 2 {
return None;
}
if parts.len() != 2 { return None }
Some((parts[0].to_string(), parts[1].to_string()))
})
.collect()
@ -68,19 +66,19 @@ pub fn get_pkg_env(file_path: &Path) -> io::Result<HashMap<String, String>> {
pub fn get_repo_env(repo: &str) -> io::Result<HashMap<String, String>> {
let cfg_path = crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = crate::commands::get_aeropkg_etc().join("aeropkg.md");
let content = extract_block(&cfg_path, &format!("``` env *** env {} ***", repo), "```")?;
Ok(parse_env_vars(&content))
}
pub fn get_stage_env(stage: &str) -> io::Result<HashMap<String, String>> {
let cfg_path = crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = crate::commands::get_aeropkg_etc().join("aeropkg.md");
let content = extract_block(&cfg_path, &format!("``` env *** env {} ***", stage), "```")?;
Ok(parse_env_vars(&content))
}
pub fn get_repo_and_stage_env(repo: &str, stage: &str) -> io::Result<HashMap<String, String>> {
let cfg_path = crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = crate::commands::get_aeropkg_etc().join("aeropkg.md");
let content = extract_block(&cfg_path, &format!("``` env *** env {} {} ***", repo, stage), "```")?;
Ok(parse_env_vars(&content))
}

View File

@ -8,12 +8,12 @@ use std::path::Path;
pub fn get_stage_hook(stage: &str) -> io::Result<String> {
let cfg_path = &crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
extract_block(cfg_path, &format!("``` sh *** hook {} ***", &stage), "```")
}
pub fn get_repo_and_stage_hook(repo: &str, stage: &str) -> io::Result<String> {
let cfg_path = &crate::commands::get_etc_path().join("aeropkg.md");
let cfg_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
extract_block(cfg_path, &format!("``` sh *** hook {} {} ***", &repo, &stage), "```")
}
@ -23,29 +23,19 @@ pub fn get_build_deps(file_path: &Path) -> io::Result<String> { extract_block(fi
pub fn get_run_deps(file_path: &Path) -> io::Result<String> { extract_block(file_path, "``` cfg *** run deps ***", "```") }
pub fn get_build_script(file_path: &Path) -> io::Result<String> { extract_block(file_path, "``` sh *** build ***", "```") }
pub fn get_config_script(file_path: &Path) -> io::Result<String> { extract_block(file_path, "``` sh *** config ***", "```") }
pub fn get_patch_script(file_path: &Path) -> io::Result<String> { extract_block(file_path, "``` sh *** config ***", "```") }
pub fn get_patch_script(file_path: &Path) -> io::Result<String> { extract_block(file_path, "``` sh *** patch ***", "```") }
pub fn get_custom_script(file_path: &Path, scriptname: &String) -> String { extract_block(file_path, &format!("``` sh *** {} ***", scriptname), "```").expect(&format!("Can't get custom script: {}", &scriptname)) }
fn extract_block(
file_path: &Path,
start_marker: &str,
end_marker: &str,
) -> io::Result<String> {
fn extract_block(file_path: &Path, start_marker: &str, end_marker: &str) -> io::Result<String> {
let lines = read_lines(file_path)?;
let mut block_started = false;
let mut result = Vec::new();
for line in lines {
if line.trim() == start_marker {
block_started = true;
continue;
}
if line.trim() == start_marker { block_started = true; continue }
if block_started {
if line.trim() == end_marker {
break;
}
result.push(line.trim().to_string());
if line.trim() == end_marker { break }
result.push(line.trim().to_string())
}
}

View File

@ -1,9 +1,10 @@
use std::fs;
use std::io;
use std::fs::{self, File};
use std::io::{self, BufRead, BufReader};
use std::path::{Path,PathBuf};
use super::*;
pub fn get_name<P: AsRef<Path>>(pkg_file_path: P) -> io::Result<String> {
let first_line = read_first_line(pkg_file_path)?;
Ok(first_line.split_whitespace().next().unwrap_or("").to_string())
@ -39,9 +40,7 @@ pub fn get_use_status(repo: &str, pkgname: &str) -> bool {
let base_path = crate::commands::get_aeropkg_base().join(repo);
let path = Path::new(&base_path);
if !path.exists() || !path.is_dir() {
return false;
}
if !path.exists() || !path.is_dir() { return false }
let mut match_count = 0;
@ -54,10 +53,7 @@ pub fn get_use_status(repo: &str, pkgname: &str) -> bool {
for line in lines.iter() {
if line.trim() == format!("={}", pkgname) {
match_count += 1;
if match_count > 1 {
return true
}
break;
if match_count > 1 { return true }; break
}
}
}
@ -68,57 +64,61 @@ pub fn get_use_status(repo: &str, pkgname: &str) -> bool {
return false
}
pub fn get_priority_repo(pkgname: String) -> String {
pub fn get_priority_repo(pkgname: &String) -> String {
let repo_list = repoinfo::get_repo_list();
let var_path = crate::commands::get_var_path();
let var_path = crate::commands::get_aeropkg_var();
for repo in repo_list {
let pkg_path = var_path.join(&repo).join(format!("{}.md", &pkgname));
let pkg_path = var_path.join(&repo).join(format!("{}.md", pkgname));
if pkg_path.exists() {
return repo;
}
}
panic!("Package {} not found in any available repository", pkgname);
panic!("Package {} not found in any available repository", pkgname)
}
pub fn get_priority_repo_installed(pkgname: &String) -> String {
let repo_list = repoinfo::get_repo_list();
let aeropkg_base = crate::commands::get_aeropkg_base();
for repo in repo_list {
let pkg_path = aeropkg_base.join(&repo).join(pkgname);
if pkg_path.exists() {
return repo;
}
}
panic!("Package {} not found in any available repository", pkgname)
}
pub fn get_index_conflict<P: AsRef<Path>>(pkg_file_path: P) -> io::Result<PathBuf> {
let pkg_file_path_path = pkg_file_path.as_ref();
let parts: Vec<&str> = pkg_file_path_path
.iter()
.map(|component| component.to_str().unwrap_or(""))
.collect();
if parts.len() < 4 {
return Err(io::Error::new(
let pkg_file_path = pkg_file_path.as_ref();
let pkg_file_path_str = pkg_file_path.to_str().ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidInput,
"Invalid pkg_file_path path format",
));
}
let system_struct_folder = parts[3]; // bin, sbin, include, lib, share
let etc = crate::commands::get_etc_path();
let cfg_path = etc.join("index-conflict.md");
let start_marker = format!("``` cfg *** {} ***", system_struct_folder);
let end_marker = "```";
let block_content = extract_block(&cfg_path, &start_marker, end_marker)?;
let pkg_file_path_str = pkg_file_path_path.to_str().ok_or_else(|| {
io::Error::new(io::ErrorKind::InvalidInput, "Failed to convert pkg_file_path path to string")
"pkg_file_path is not valid UTF-8",
)
})?;
for line in block_content.lines() {
let trimmed_line = line.trim();
if trimmed_line.starts_with(pkg_file_path_str) {
let mut words = trimmed_line.split_whitespace();
if let Some(_) = words.next() {
if let Some(path_source) = words.next() {
return Ok(PathBuf::from(path_source));
}
let etc = crate::commands::get_aeropkg_etc();
let cfg_path = etc.join("index-conflict.md");
let file = File::open(&cfg_path)?;
let reader = BufReader::new(file);
for line in reader.lines() {
let line = line?;
let trimmed = line.trim();
if trimmed.is_empty() || trimmed.starts_with('#') {
continue;
}
let mut parts = trimmed.split_whitespace();
if let (Some(dst), Some(src)) = (parts.next(), parts.next()) {
if dst == pkg_file_path_str {
return Ok(PathBuf::from(src))
}
}
}
@ -126,8 +126,8 @@ pub fn get_index_conflict<P: AsRef<Path>>(pkg_file_path: P) -> io::Result<PathBu
Err(io::Error::new(
io::ErrorKind::NotFound,
format!(
"No matching line found for pkg_file_path: {}",
pkg_file_path_path.display()
"No conflict mapping found for path: {}",
pkg_file_path.display()
),
))
}

View File

@ -1,7 +1,7 @@
use super::*;
pub fn get_repo_addr(repo: &str) -> String {
let file_path = &crate::commands::get_etc_path().join("aeropkg.md");
let file_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** Repository list and priority ***", "```").expect("Can't parse repo list block");
@ -15,11 +15,11 @@ pub fn get_repo_addr(repo: &str) -> String {
}
}
panic!("Repository '{}' not found in the repository list", repo);
panic!("Repository '{}' not found in the repository list", repo)
}
pub fn get_repo_list() -> Vec<String> {
let file_path = &crate::commands::get_etc_path().join("aeropkg.md");
let file_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** Repository list and priority ***", "```").expect("Can't parse repo list block");
@ -29,7 +29,7 @@ pub fn get_repo_list() -> Vec<String> {
if !trimmed_line.is_empty() {
let parts: Vec<&str> = trimmed_line.split_whitespace().collect();
if let Some(repo) = parts.first() {
repo_list.push(repo.to_string());
repo_list.push(repo.to_string())
}
}
}

View File

@ -5,80 +5,73 @@ use std::collections::HashMap;
use crate::utils::parser;
pub fn mount_overlay(path_repo: &Path) -> Result<(), String> {
let lowerdirs = vec![
path_repo.join("bin"),
path_repo.join("sbin"),
];
let lowerdir_str = lowerdirs.iter()
pub fn mount_overlay() {
let repo_list = parser::repoinfo::get_repo_list();
let aeropkg_base = crate::commands::get_aeropkg_base();
let mut lowerdirs = Vec::new();
for repo in &repo_list {
let repo_path = Path::new(&aeropkg_base).join(repo);
if repo_path.join("bin").exists() { lowerdirs.push(repo_path.join("bin")) }
if repo_path.join("sbin").exists() { lowerdirs.push(repo_path.join("sbin")) }
}
let lowerdir_str: String = lowerdirs
.iter()
.map(|p| p.to_string_lossy())
.collect::<Vec<_>>()
.join(":");
let mounts = vec![
("/usr/bin", &lowerdir_str),
("/usr/sbin", &lowerdir_str),
("/bin", &lowerdir_str),
("/sbin", &lowerdir_str),
let mounts = [
("/usr/bin"),
("/usr/sbin"),
("/bin"),
("/sbin"),
];
for (target, lowerdir) in mounts {
for &mount_point in &mounts {
let output = Command::new("mount")
.arg("-t").arg("overlay")
.arg("overlay")
.arg("-o").arg(format!("lowerdir={}", lowerdir))
.arg(target)
.arg("-o").arg(format!("lowerdir={}", lowerdir_str))
.arg(mount_point)
.output()
.map_err(|e| format!("Failed to execute mount command: {}", e))?;
.expect(&format!("Failed to execute mount command for {}", mount_point));
if !output.status.success() {
return Err(format!(
"Mount failed for target {}: {}",
target,
panic!(
"Mount failed for {}: {}",
mount_point,
String::from_utf8_lossy(&output.stderr)
));
);
}
}
Ok(())
}
pub fn shell_update() -> Result<(), String> {
pub fn shell_update() {
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
let output_hash = Command::new(&shell)
.arg("-c")
.arg("hash -r")
.output()
.map_err(|e| format!("Failed to execute hash -r with shell {}: {}", shell, e))?;
.map_err(|e| format!("Failed to execute hash -r with shell {}: {}", shell, e)).unwrap();
if !output_hash.status.success() {
return Err(format!(
"hash -r failed: {}",
String::from_utf8_lossy(&output_hash.stderr)
));
}
if !output_hash.status.success() { panic!("hash -r failed: {}", String::from_utf8_lossy(&output_hash.stderr)) }
let output_ldconfig = Command::new("ldconfig")
.output()
.map_err(|e| format!("Failed to execute ldconfig: {}", e))?;
.map_err(|e| format!("Failed to execute ldconfig: {}", e)).unwrap();
if !output_ldconfig.status.success() {
return Err(format!(
"ldconfig failed: {}",
String::from_utf8_lossy(&output_ldconfig.stderr)
));
}
Ok(())
if !output_ldconfig.status.success() { panic!("ldconfig failed: {}", String::from_utf8_lossy(&output_ldconfig.stderr)) }
}
pub fn run_install_script_hook(repo: &str, stage: &str, full_env: &HashMap<String, String>) -> Result<(), bool> {
pub fn run_install_script_hook(repo: &str, stage: &str, full_env: &HashMap<String, String>) {
let hook_script = match parser::get_repo_and_stage_hook(repo, stage) {
Ok(script) => Ok(script),
Err(_) => parser::get_stage_hook(stage),
Err(_) => parser::get_stage_hook(stage)
};
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
@ -86,46 +79,31 @@ pub fn run_install_script_hook(repo: &str, stage: &str, full_env: &HashMap<Strin
if let Ok(script) = hook_script {
let output = Command::new(&shell)
.arg("-c")
.arg(&script)
.arg(format!("set -e\n{}", script))
.envs(full_env)
.output();
if let Err(e) = output {
eprintln!("Failed to execute hook script: {}", e);
return Err(false);
}
if let Err(e) = output { panic!("Failed to execute hook script: {}", e) }
let output = output.unwrap();
if !output.status.success() {
eprintln!("Hook script failed: {:?}", output);
return Err(false);
}
if !output.status.success() { panic!("Hook script failed: {:?}", output) }
}
Ok(())
}
pub fn run_install_script(script: &str, work_dir: &Path, full_env: &HashMap<String, String>) -> Result<(), bool> {
pub fn run_install_script(script: &str, work_dir: &Path, full_env: &HashMap<String, String>) {
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
let output = Command::new(&shell)
.arg("-c")
.arg(&script)
.arg(format!("set -e\n{}", script))
.current_dir(work_dir)
.envs(full_env)
.output();
if let Err(e) = output {
eprintln!("Failed to execute shell script: {}", e);
return Err(false);
}
if let Err(e) = output { panic!("Failed to execute shell script: {}", e) }
let output = output.unwrap();
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprintln!("Failed to execute script:\n``` sh\n{}\n```\nError: {}", script, stderr);
return Err(false);
panic!("Failed to execute script:\n``` sh\n{}\n```\nError: {}", script, stderr)
}
Ok(())
}