30 lines
804 B
Rust
30 lines
804 B
Rust
use crate::app_config::AppConfig;
|
|
use crate::constants;
|
|
use std::path::Path;
|
|
|
|
/// Check out whether NAT hook has been installed or not
|
|
pub fn is_installed() -> anyhow::Result<bool> {
|
|
let hook_file = Path::new(constants::NAT_HOOK_PATH);
|
|
|
|
if !hook_file.exists() {
|
|
return Ok(false);
|
|
}
|
|
|
|
let exe = std::env::current_exe()?;
|
|
let hook_content = std::fs::read_to_string(hook_file)?;
|
|
|
|
Ok(hook_content.contains(exe.to_string_lossy().as_ref()))
|
|
}
|
|
|
|
/// Get nat hook expected content
|
|
pub fn hook_content() -> anyhow::Result<String> {
|
|
let exe = std::env::current_exe()?;
|
|
|
|
Ok(format!(
|
|
"#!/bin/bash\n\
|
|
NAT_MODE=1 {} --storage {} --network-name \"$1\" --operation \"$2\" --sub-operation \"$3\"",
|
|
exe.to_string_lossy(),
|
|
AppConfig::get().storage
|
|
))
|
|
}
|