|
|
@ -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,34 +19,36 @@ 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") {
|
|
|
|
|
|
|
|
Err(ScriptError::MissingMain(script))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Ok(Self { ctx, task_config })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.has_fn("main") {
|
|
|
|
#[tracing::instrument(level = "trace", skip_all)]
|
|
|
|
let pipeline = ctx.call_fn(
|
|
|
|
pub fn exec(mut self) -> Result<(), ScriptError> {
|
|
|
|
|
|
|
|
let pipeline = self.ctx.call_fn(
|
|
|
|
"main",
|
|
|
|
"main",
|
|
|
|
vec![Argument::Positional(self.task_config.into_expression())],
|
|
|
|
vec![Argument::Positional(self.task_config.into_expression())],
|
|
|
|
)?;
|
|
|
|
)?;
|
|
|
|
ctx.print_pipeline_stderr(pipeline)?;
|
|
|
|
self.ctx.print_pipeline_stderr(pipeline)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(ScriptError::MissingMain(self.script))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 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)]
|
|
|
|