partition_sim/commands/
ssh.rs

1use std::{net::IpAddr, process::Command};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum SshCommands {
5    CopyId {
6        ip_addr: IpAddr,
7        path_to_key: String,
8    },
9}
10
11impl SshCommands {
12    pub fn build(&self) -> std::process::Command {
13        match self {
14            Self::CopyId {
15                ip_addr,
16                path_to_key,
17            } => {
18                let mut command = Command::new("sshpass");
19                command.arg("-f");
20                command.arg("/password.txt");
21                command.arg("ssh-copy-id");
22                command.arg("-i");
23                command.arg(path_to_key);
24                command.arg("-o");
25                command.arg("StrictHostKeyChecking=no");
26                command.arg("-o");
27                command.arg("UserKnownHostsFile=/dev/null");
28                command.arg("-f");
29                command.arg(format!("root@{}", ip_addr));
30                command
31            }
32        }
33    }
34}