From f73e393a75fcad939a240ff3b72cbc75813e90e3 Mon Sep 17 00:00:00 2001 From: notgne2 Date: Mon, 28 Sep 2020 14:37:43 -0700 Subject: Add missing files --- src/utils/deploy.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/utils/deploy.rs (limited to 'src/utils/deploy.rs') diff --git a/src/utils/deploy.rs b/src/utils/deploy.rs new file mode 100644 index 0000000..7260e55 --- /dev/null +++ b/src/utils/deploy.rs @@ -0,0 +1,57 @@ +use super::data; + + +use tokio::process::Command; + +pub async fn deploy_profile( + profile: &data::Profile, + profile_name: &str, + node: &data::Node, + node_name: &str, + merged_settings: &data::GenericSettings, + deploy_data: &super::DeployData<'_>, +) -> Result<(), Box> { + info!( + "Activating profile `{}` for node `{}`", + profile_name, node_name + ); + + let mut self_activate_command = format!( + "{} activate '{}' '{}'", + deploy_data.current_exe.as_path().to_str().unwrap(), + deploy_data.profile_path, + profile.profile_settings.path, + ); + + if let Some(sudo_cmd) = &deploy_data.sudo { + self_activate_command = format!("{} {}", sudo_cmd, self_activate_command); + } + + if let Some(ref bootstrap_cmd) = profile.profile_settings.bootstrap { + self_activate_command = format!( + "{} --bootstrap-cmd '{}'", + self_activate_command, bootstrap_cmd + ); + } + + if let Some(ref activate_cmd) = profile.profile_settings.activate { + self_activate_command = format!( + "{} --activate-cmd '{}'", + self_activate_command, activate_cmd + ); + } + + let mut c = Command::new("ssh"); + let mut ssh_command = c.arg(format!( + "ssh://{}@{}", + deploy_data.ssh_user, node.node_settings.hostname + )); + + for ssh_opt in &merged_settings.ssh_opts { + ssh_command = ssh_command.arg(ssh_opt); + } + + ssh_command.arg(self_activate_command).spawn()?.await?; + + Ok(()) +} -- cgit v1.2.3