update modules

This commit is contained in:
2025-09-02 20:01:30 +03:00
parent bcb6dcca1d
commit 968216f5f2
11 changed files with 91 additions and 28 deletions

View File

@ -1,9 +1,9 @@
Sexpkg's config file
Aeropkg config file
=
``` cfg *** Repository list and priority ***
gnu /pkg/gnu/sexpkg/var/gnu
musl /pkg/gnu/sexpkg/var/musl
gnu /pkg/gnu/aeropkg/var/gnu
musl /pkg/gnu/aeropkg/var/musl
```
``` cfg *** Clean exclude ***

View File

@ -2,7 +2,7 @@
if [ -z "$1" ]; then
echo "Ошибка: Укажите путь установки как аргумент."
echo "Пример использования: $0 /pkg/gnu/sexpkg/"
echo "Пример использования: $0 /pkg/gnu/aeropkg/"
exit 1
fi
@ -10,7 +10,7 @@ INSTALL_PATH="$1"
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
echo "Установка в '$INSTALL_PATH'..."
SEXPKG_HOME=$INSTALL_PATH cargo install --path . --root "$INSTALL_PATH"
AEROPKG_HOME=$INSTALL_PATH cargo install --path . --root "$INSTALL_PATH"
if [ $? -ne 0 ]; then
echo "Ошибка при установке."

View File

@ -1,11 +1,11 @@
use std::path::PathBuf;
use std::fs;
use super::pkglink::pkglink;
use super::link::link;
pub fn enable(repo: &String, pkgname: &String) -> Result<(), String> {
let source = PathBuf::from("/pkg").join(repo).join(pkgname);
let _ = fs::remove_file(&source.join("disabled"));
pkglink(&repo, &pkgname)?;
link(&repo, &pkgname)?;
Ok(())
}

View File

@ -2,19 +2,27 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process;
use std::os::unix::fs::MetadataExt;
use crate::utils::parser;
use crate::commands::pkglink::pkglink;
use crate::commands::link::link;
pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
let var_path = super::get_var_path();
let pkg_md_path = var_path.join(format!("{}/{}.md", repo, pkgname));
let pkg_md_path = var_path.join(format!("{}/{}.md", &repo, &pkgname));
let builded_pkg_md_path = PathBuf::from("/pkg").join(&repo).join(&pkgname).join("build-script.md");
if !pkg_md_path.exists() {
upload_from_repo(&repo, &pkgname, &pkg_md_path)?;
}
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(())
}
}
check_build_dependency(&repo, &pkg_md_path)?;
check_run_dependency(&pkg_md_path)?;
@ -23,7 +31,8 @@ pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
let src_dir = PathBuf::from("/pkg/src").join(&pkgname);
patch(&pkgname, &src_dir, &pkg_md_path)?;
build(&repo, &pkgname, &src_dir, &pkg_md_path)?;
pkglink(&repo, &pkgname).expect("Failed link package");
link(&repo, &pkgname).expect("Failed link package");
hook(&repo, &pkgname);
config(&src_dir, &pkg_md_path)?;
let src_remove_flag = match std::env::var("pkg_src_remove") {
@ -332,6 +341,19 @@ fn build(
}
};
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(())
} 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(&pkgname, &pkg_md_path)?;
patch(&pkgname, &src_dir, &pkg_md_path)?;
}
}
let output = Command::new("zsh")
.arg("-c")
.arg(&build_script)
@ -346,8 +368,8 @@ fn build(
let output = output.unwrap();
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprintln!("Script failed with error: {}", stderr);
return Err(false);
eprintln!("Script failed with error:\n{}", stderr);
std::process::exit(1);
}
let dest_dir = PathBuf::from("/pkg").join(repo).join(pkgname);
@ -357,11 +379,14 @@ fn build(
}
let dest_path = dest_dir.join("build-script.md");
if let Err(e) = fs::copy(pkg_md_path, &dest_path) {
fs::remove_file(&dest_path).expect("");
if let Err(e) = fs::hard_link(pkg_md_path, &dest_path) {
eprintln!("Failed to copy build script to destination: {}", e);
return Err(false);
}
fs::write(src_dir.join("aeropkg.build-script"), &build_script).unwrap();
Ok(())
}
@ -395,3 +420,14 @@ fn config(
Ok(())
}
fn hook(repo: &String, pkgname: &String) {
let pkg_dir = PathBuf::from("/pkg").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");
crate::utils::mv::mv(&lib64_dir, &lib_dir).unwrap();
crate::utils::mv::mv(&lib32_dir, &lib_dir).unwrap();
fs::remove_dir_all(&lib64_dir).unwrap();
fs::remove_dir_all(&lib32_dir).unwrap();
}

View File

@ -2,7 +2,7 @@ use std::path::PathBuf;
use crate::utils::hardcopy::hardcopy_handler;
use crate::utils::shell::*;
pub fn pkglink(repo: &String, pkgname: &String) -> Result<(), String> {
pub fn link(repo: &String, pkgname: &String) -> Result<(), String> {
let source = PathBuf::from("/pkg").join(repo).join(pkgname);
if source.join("disabled").exists() { return Ok(()) }

View File

@ -1,6 +1,6 @@
pub mod install;
pub mod delete;
pub mod pkglink;
pub mod link;
pub mod disable;
pub mod enable;
@ -8,5 +8,5 @@ use std::path::PathBuf;
pub fn get_var_path() -> PathBuf {
PathBuf::from(env!("SEXPKG_HOME")).join("var")
PathBuf::from(env!("AEROPKG_HOME")).join("var")
}

View File

@ -38,7 +38,7 @@ fn main() {
),
)
.subcommand(
clap::Command::new("pkglink")
clap::Command::new("link")
.about("Create package links and mount overlays")
.arg(
clap::Arg::new("repo")
@ -98,7 +98,7 @@ fn main() {
2 => {
let repo = args[0];
let pkgname = args[1];
commands::install::install(repo, pkgname).unwrap();
if let Err(_) = commands::install::install(repo, pkgname) { std::process::exit(1) }
}
_ => unreachable!(),
}
@ -112,13 +112,13 @@ fn main() {
} else {
commands::delete::delete(repo, pkgname);
}
} else if let Some(pkglink_matches) = matches.subcommand_matches("pkglink") {
let repo = pkglink_matches.get_one::<String>("repo").unwrap();
let pkgname = pkglink_matches.get_one::<String>("pkgname").unwrap();
} else if let Some(link_matches) = matches.subcommand_matches("link") {
let repo = link_matches.get_one::<String>("repo").unwrap();
let pkgname = link_matches.get_one::<String>("pkgname").unwrap();
match commands::pkglink::pkglink(&repo, &pkgname) {
Ok(_) => println!("pkglink completed successfully."),
Err(e) => eprintln!("Error during pkglink: {}", e),
match commands::link::link(&repo, &pkgname) {
Ok(_) => println!("link completed successfully."),
Err(e) => eprintln!("Error during link: {}", e),
}
} else if let Some(disable_matches) = matches.subcommand_matches("disable") {
let repo = disable_matches.get_one::<String>("repo").unwrap();

View File

@ -172,7 +172,7 @@ 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 index_conflict_path = Path::new("/pkg/gnu/sexpkg/etc/index-conflict.md");
let index_conflict_path = Path::new("/pkg/gnu/aeropkg/etc/index-conflict.md");
let content = fs::read_to_string(&index_conflict_path)?;
let start_marker = format!("``` cfg *** {} ***", base_system_folder);

View File

@ -2,3 +2,4 @@ pub mod hardcopy;
pub mod parser;
pub mod deletecopy;
pub mod shell;
pub mod mv;

26
src/utils/mv.rs Normal file
View File

@ -0,0 +1,26 @@
use rayon::prelude::*;
use std::fs;
use std::io;
use std::path::Path;
pub fn mv(source: &Path, destination: &Path) -> io::Result<()> {
let metadata = fs::symlink_metadata(source)?;
if metadata.file_type().is_file() {
fs::rename(source, destination).ok();
} else if metadata.file_type().is_dir() {
fs::create_dir_all(destination)?;
let entries: Vec<_> = fs::read_dir(source)?.collect::<io::Result<Vec<_>>>()?;
entries.par_iter().try_for_each(|entry| {
let path = entry.path();
if let Some(file_name) = path.file_name() {
let dest_path = destination.join(file_name);
mv(&path, &dest_path)
} else {
Ok(())
}
})?;
} else if metadata.file_type().is_symlink() {
fs::rename(source, destination).ok();
}
Ok(())
}

View File

@ -62,7 +62,7 @@ pub fn get_patch_script<P: AsRef<Path>>(file_path: P) -> io::Result<String> {
pub fn get_repo_list() -> io::Result<Vec<String>> {
let file_path = crate::commands::get_var_path().join("sexpkg.md");
let file_path = crate::commands::get_var_path().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** Repository list and priority ***", "```")?;
@ -86,7 +86,7 @@ pub fn get_repo_addr(repo: &str) -> io::Result<String> {
let file_path = exe_path
.parent()
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to get executable directory"))?
.join("../etc/sexpkg.md");
.join("../etc/aeropkg.md");
let block = extract_block(file_path, "``` sh *** Repository list and priority ***", "```")?;
@ -157,7 +157,7 @@ pub fn get_index_conflict<P: AsRef<Path>>(destination: P) -> io::Result<PathBuf>
let system_struct_folder = parts[3]; // bin, sbin, include, lib, share
let etc = Path::new("/pkg/gnu/sexpkg/etc");
let etc = Path::new("/pkg/gnu/aeropkg/etc");
let cfg_path = etc.join("index-conflict.md");
let start_marker = format!("``` cfg *** {} ***", system_struct_folder);