diff --git a/src/main.rs b/src/main.rs index a913e3e..698bea5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ use whoami; use bubble_flexrouter::admin::{AdminRegistration, start_admin}; use bubble_flexrouter::pass::init_password; use bubble_flexrouter::proxy::start_proxy; +use bubble_flexrouter::ssh::ssh_command; use bubble_flexrouter::util::read_required_env_var_argument; use bubble_flexrouter::util::read_required_env_var_argument_as_file; use bubble_flexrouter::util::read_path_to_string; @@ -149,6 +150,9 @@ async fn main() { info!("Starting bubble-flexrouter version {} ", VERSION); + // verify ssh command exists, this will panic and exit if an ssh command cannot be found + ssh_command(); + // todo: ensure we are running as root (or Administrator on Windows) info!("The current user is {}", whoami::username()); diff --git a/src/ssh.rs b/src/ssh.rs index dfb88eb..32ad6d1 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -4,6 +4,7 @@ * For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ */ +use std::path::Path; use std::process::exit; use std::process::{Command, Stdio, Child}; use std::io::Error; @@ -25,15 +26,39 @@ use whoami::{platform, Platform}; use crate::util::{HEADER_BUBBLE_SESSION, write_string_to_file, now_micros}; const SSH_WINDOWS: &'static str = "C:\\Windows\\System32\\OpenSSH\\ssh.exe"; +const SSH_WINDOWS_CYGWIN: &'static str = "C:\\cygwin64\\bin\\ssh.exe"; const SSH_MACOS: &'static str = "/usr/bin/ssh"; const SSH_LINUX: &'static str = "/usr/bin/ssh"; pub fn ssh_command() -> &'static str { let platform: Platform = platform(); return match platform { - Platform::Windows => SSH_WINDOWS, - Platform::MacOS => SSH_MACOS, - Platform::Linux => SSH_LINUX, + Platform::Windows => { + if Path::new(SSH_WINDOWS).exists() { + SSH_WINDOWS + } else if Path::new(SSH_WINDOWS_CYGWIN).exists() { + SSH_WINDOWS_CYGWIN + } else { + error!("ssh_command: ssh executable was not found in either {} or {}", SSH_WINDOWS, SSH_WINDOWS_CYGWIN); + exit(2) + } + }, + Platform::MacOS => { + if Path::new(SSH_MACOS).exists() { + SSH_MACOS + } else { + error!("ssh_command: ssh executable was not found: {}", SSH_MACOS); + exit(2) + } + }, + Platform::Linux => { + if Path::new(SSH_LINUX).exists() { + SSH_LINUX + } else { + error!("ssh_command: ssh executable was not found: {}", SSH_LINUX); + exit(2) + } + }, _ => { error!("ssh_command: unsupported platform: {:?}", platform); exit(2);