use std::path::Path; use std::{env, path::PathBuf}; use tokio::fs; use crate::error::AppResult; use crate::tasks::all_tasks; const DEFAULT_CONFIG_DIR: &str = "/etc"; lazy_static::lazy_static! { pub static ref CFG_PATH: PathBuf = env::var("TRM_CFG_PATH").map(PathBuf::from).unwrap_or_else(|_| PathBuf::from(DEFAULT_CONFIG_DIR).join("tourmaline")); pub static ref SCRIPT_PATH: PathBuf = CFG_PATH.join("scripts"); } pub async fn generate_script_files>(output: P) -> AppResult<()> { let output = output.as_ref(); let tasks = all_tasks(); for (name, up_script, down_script) in tasks { let script_dir = output.join(&name); if !script_dir.exists() { fs::create_dir_all(&script_dir).await?; } fs::write( output.join(up_script), format!( r#" # Applies all system changes of `{name}` def main [cfg] {{ echo "Executing up task `{name}` with config" $cfg }} "# ) .trim(), ) .await?; fs::write( output.join(down_script), format!( r#" # Reverts all system changes of `{name}` def main [cfg] {{ echo "Executing up task `{name}` with config" $cfg }} "# ) .trim(), ) .await?; } Ok(()) }