aboutsummaryrefslogtreecommitdiff
path: root/src/wgcmd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/wgcmd.rs')
-rw-r--r--src/wgcmd.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/wgcmd.rs b/src/wgcmd.rs
new file mode 100644
index 0000000..32a23a6
--- /dev/null
+++ b/src/wgcmd.rs
@@ -0,0 +1,25 @@
1use crate::wg::config::WireguardConfig;
2use std::process::Command;
3use anyhow::{anyhow, Result, Context};
4
5pub fn run(wg_conf: &WireguardConfig) -> Result<()> {
6 let wg = Command::new("wg")
7 .env("WG_COLOR_MODE", "always")
8 .output()
9 .context("could not run 'wg', is it installed?")?;
10
11 if !wg.status.success() {
12 let err = String::from_utf8(wg.stderr)?;
13 return Err(anyhow!("error running 'wg': {}", err));
14 }
15
16 let mut out = String::from_utf8(wg.stdout).context("error parsing stdout")?;
17
18 for peer in wg_conf.peers.iter() {
19 out = out.replace(peer.public_key.as_str(), peer.name.as_str());
20 }
21
22 println!("{}", out);
23
24 Ok(())
25}