Обновление README.md, исходников, пакетки
This commit is contained in:
@ -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");
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user