diff options
author | PradeepKiruvale <pradeepkumar.kj@softwareag.com> | 2022-04-11 15:13:32 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 15:13:32 +0530 |
commit | 34ffb846e67b7ccee34348e1d899c12b9bda3756 (patch) | |
tree | b4bab320e381ba2fa482a156f85fe4eab3cdbb1b /crates/core/tedge | |
parent | a718ea43f89d3d7494624da4b226d2eff101acb0 (diff) |
Closes #1040 use config-dir feature for initalize and run (#1059)
Diffstat (limited to 'crates/core/tedge')
-rw-r--r-- | crates/core/tedge/src/main.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/core/tedge/src/main.rs b/crates/core/tedge/src/main.rs index 5b384e35..eab007f6 100644 --- a/crates/core/tedge/src/main.rs +++ b/crates/core/tedge/src/main.rs @@ -1,6 +1,8 @@ #![forbid(unsafe_code)] #![deny(clippy::mem_forget)] +use std::path::PathBuf; + use anyhow::Context; use clap::Parser; use tedge_users::UserManager; @@ -18,7 +20,7 @@ fn main() -> anyhow::Result<()> { let opt = cli::Opt::parse(); if opt.init { - initialize_tedge()?; + initialize_tedge(&opt.config_dir)?; return Ok(()); } @@ -45,12 +47,23 @@ fn main() -> anyhow::Result<()> { } } -fn initialize_tedge() -> anyhow::Result<()> { - create_directory_with_user_group("/etc/tedge", "tedge", "tedge", 0o775)?; +fn initialize_tedge(cfg_dir: &PathBuf) -> anyhow::Result<()> { + let config_dir = cfg_dir.as_path().display().to_string(); + create_directory_with_user_group(&config_dir, "tedge", "tedge", 0o775)?; create_directory_with_user_group("/var/log/tedge", "tedge", "tedge", 0o775)?; - create_directory_with_user_group("/etc/tedge/mosquitto-conf", "tedge", "tedge", 0o775)?; - create_directory_with_user_group("/etc/tedge/operations", "tedge", "tedge", 0o775)?; - create_directory_with_user_group("/etc/tedge/plugins", "tedge", "tedge", 0o775)?; - create_directory_with_user_group("/etc/tedge/device-certs", "mosquitto", "mosquitto", 0o775)?; + create_directory_with_user_group( + &format!("{config_dir}/mosquitto-conf"), + "tedge", + "tedge", + 0o775, + )?; + create_directory_with_user_group(&format!("{config_dir}/operations"), "tedge", "tedge", 0o775)?; + create_directory_with_user_group(&format!("{config_dir}/plugins"), "tedge", "tedge", 0o775)?; + create_directory_with_user_group( + &format!("{config_dir}/device-certs"), + "mosquitto", + "mosquitto", + 0o775, + )?; Ok(()) } |