aboutsummaryrefslogtreecommitdiff
path: root/src/utils/deploy.rs
diff options
context:
space:
mode:
authornotgne22020-09-28 14:37:43 -0700
committernotgne22020-09-28 14:37:43 -0700
commitf73e393a75fcad939a240ff3b72cbc75813e90e3 (patch)
tree39304318db967f39ed6925f5206174dd5b14dbab /src/utils/deploy.rs
parent73b99043a71f27f98bf11510fb8db46fa086383c (diff)
Add missing files
Diffstat (limited to '')
-rw-r--r--src/utils/deploy.rs57
1 files changed, 57 insertions, 0 deletions
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<dyn std::error::Error>> {
+ 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(())
+}