|
|
@ -7,10 +7,8 @@ use crate::{distro::OSConfig, error::ScriptError, utils::CFG_PATH};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ExecBuilder {
|
|
|
|
pub struct ExecBuilder {
|
|
|
|
script: PathBuf,
|
|
|
|
|
|
|
|
script_contents: String,
|
|
|
|
|
|
|
|
os_config: OSConfig,
|
|
|
|
|
|
|
|
task_config: embed_nu::Value,
|
|
|
|
task_config: embed_nu::Value,
|
|
|
|
|
|
|
|
ctx: Context,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ExecBuilder {
|
|
|
|
impl ExecBuilder {
|
|
|
@ -21,36 +19,38 @@ impl ExecBuilder {
|
|
|
|
) -> Result<Self, ScriptError> {
|
|
|
|
) -> Result<Self, ScriptError> {
|
|
|
|
let script_contents = Self::get_script_contents(&script)?;
|
|
|
|
let script_contents = Self::get_script_contents(&script)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
|
|
|
script,
|
|
|
|
|
|
|
|
script_contents,
|
|
|
|
|
|
|
|
os_config,
|
|
|
|
|
|
|
|
task_config,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
|
|
|
|
pub fn exec(self) -> Result<(), ScriptError> {
|
|
|
|
|
|
|
|
let mut ctx = Context::builder()
|
|
|
|
let mut ctx = Context::builder()
|
|
|
|
.with_command_groups(CommandGroupConfig::default().all_groups(true))?
|
|
|
|
.with_command_groups(CommandGroupConfig::default().all_groups(true))?
|
|
|
|
.add_parent_env_vars()
|
|
|
|
.add_parent_env_vars()
|
|
|
|
.add_var("TRM_CONFIG", self.os_config)?
|
|
|
|
.add_var("TRM_CONFIG", os_config)?
|
|
|
|
.add_script(self.script_contents)?
|
|
|
|
.add_script(script_contents)?
|
|
|
|
.build()?;
|
|
|
|
.build()?;
|
|
|
|
|
|
|
|
if !ctx.has_fn("main") {
|
|
|
|
if ctx.has_fn("main") {
|
|
|
|
Err(ScriptError::MissingMain(script))
|
|
|
|
let pipeline = ctx.call_fn(
|
|
|
|
|
|
|
|
"main",
|
|
|
|
|
|
|
|
vec![Argument::Positional(self.task_config.into_expression())],
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
ctx.print_pipeline_stderr(pipeline)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Err(ScriptError::MissingMain(self.script))
|
|
|
|
Ok(Self { ctx, task_config })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
|
|
|
|
pub fn exec(mut self) -> Result<(), ScriptError> {
|
|
|
|
|
|
|
|
let pipeline = self.ctx.call_fn(
|
|
|
|
|
|
|
|
"main",
|
|
|
|
|
|
|
|
vec![Argument::Positional(self.task_config.into_expression())],
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
self.ctx.print_pipeline_stderr(pipeline)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns if the script needs to be run inside the new root
|
|
|
|
|
|
|
|
pub fn requires_chroot(&self) -> bool {
|
|
|
|
|
|
|
|
self.ctx
|
|
|
|
|
|
|
|
.get_var("run_in_chroot")
|
|
|
|
|
|
|
|
.and_then(|v| v.as_bool().ok())
|
|
|
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
fn get_script_contents(path: &Path) -> Result<String, ScriptError> {
|
|
|
|
fn get_script_contents(path: &Path) -> Result<String, ScriptError> {
|
|
|
|
let path = CFG_PATH.join(path);
|
|
|
|
let path = CFG_PATH.join(path);
|
|
|
|