use execkit::{HostKeyVerification, Session, SshAuth, SshConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let spec =
std::env::var("EXECKIT_SSH").map_err(|_| "set EXECKIT_SSH=\"user:password@host:port\"")?;
let (creds, hostport) = spec.split_once('@').ok_or("expected user:pass@host:port")?;
let (user, password) = creds.split_once(':').ok_or("expected user:password")?;
let (host, port) = hostport.split_once(':').ok_or("expected host:port")?;
let mut cfg = SshConfig::new(
host,
user,
SshAuth::Password(password.to_string()),
HostKeyVerification::KnownHosts("/tmp/execkit_known_hosts".into()),
);
cfg.port = port.parse()?;
let mut session = Session::ssh(cfg)?;
let r = session.exec("uname -a; whoami; pwd")?;
println!("{}", r.stdout);
session.exec("cd /tmp")?;
println!("cwd is now: {}", session.exec("pwd")?.cwd);
Ok(())
}