update hooks functions

This commit is contained in:
2026-09-10 23:05:56 +03:00
parent 055ebb7703
commit d2c2daf352
9 changed files with 86 additions and 17 deletions

View File

@ -6,6 +6,10 @@ use std::fs;
use std::io::{self, BufRead};
use std::path::Path;
pub fn get_general_hook() -> io::Result<String> {
let cfg_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
extract_block(cfg_path, &format!("``` sh *** hook ***"), "```")
}
pub fn get_stage_hook(stage: &str) -> io::Result<String> {
let cfg_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");

View File

@ -68,7 +68,7 @@ pub fn shell_update() {
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>) {
pub fn run_install_repo_stage_hook_script(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)
@ -89,6 +89,52 @@ pub fn run_install_script_hook(repo: &str, stage: &str, full_env: &HashMap<Strin
}
}
pub fn run_install_repo_hook_script(repo: &str, full_env: &HashMap<String, String>) {
run_install_stage_hook_script(repo, full_env);
}
pub fn run_install_stage_hook_script(stage: &str, full_env: &HashMap<String, String>) {
let hook_script = match parser::get_stage_hook(stage) {
Ok(script) => Ok(script),
Err(_) => parser::get_stage_hook(stage)
};
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
if let Ok(script) = hook_script {
let output = Command::new(&shell)
.arg("-c")
.arg(format!("set -e\n{}", script))
.envs(full_env)
.output();
if let Err(e) = output { panic!("Failed to execute hook script: {}", e) }
let output = output.unwrap();
if !output.status.success() { panic!("Hook script failed: {:?}", output) }
}
}
pub fn run_install_hook_script(full_env: &HashMap<String, String>) {
let hook_script = match parser::get_general_hook() {
Ok(script) => Ok(script),
Err(_) => parser::get_general_hook()
};
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
if let Ok(script) = hook_script {
let output = Command::new(&shell)
.arg("-c")
.arg(format!("set -e\n{}", script))
.envs(full_env)
.output();
if let Err(e) = output { panic!("Failed to execute hook script: {}", e) }
let output = output.unwrap();
if !output.status.success() { panic!("Hook script failed: {:?}", output) }
}
}
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());