From 84b41d51eaf0b10a71fa92e7c5adde097a926990 Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Tue, 26 Sep 2023 14:41:30 +0100 Subject: [PATCH 1/4] Make tedge a multi-call binary Signed-off-by: James Rhodes --- Cargo.lock | 9 ++ Cargo.toml | 9 ++ crates/core/tedge/Cargo.toml | 12 +- crates/core/tedge/src/cli/mod.rs | 117 ++++++++++++++++-- crates/core/tedge/src/main.rs | 90 +++++++++++--- .../core/tedge_agent/src/{main.rs => lib.rs} | 5 +- crates/core/tedge_mapper/src/az/mapper.rs | 8 +- .../core/tedge_mapper/src/{main.rs => lib.rs} | 7 +- .../tedge_watchdog/src/{main.rs => lib.rs} | 5 +- .../src/{main.rs => lib.rs} | 12 +- .../src/{main.rs => lib.rs} | 10 +- plugins/c8y_remote_access_plugin/src/input.rs | 28 +++-- .../src/{main.rs => lib.rs} | 7 +- .../tedge_apt_plugin/src/{main.rs => lib.rs} | 21 ++-- .../tedge_log_plugin/src/{main.rs => lib.rs} | 12 +- 15 files changed, 251 insertions(+), 101 deletions(-) rename crates/core/tedge_agent/src/{main.rs => lib.rs} (95%) rename crates/core/tedge_mapper/src/{main.rs => lib.rs} (95%) rename crates/core/tedge_watchdog/src/{main.rs => lib.rs} (91%) rename plugins/c8y_configuration_plugin/src/{main.rs => lib.rs} (94%) rename plugins/c8y_firmware_plugin/src/{main.rs => lib.rs} (94%) rename plugins/c8y_remote_access_plugin/src/{main.rs => lib.rs} (98%) rename plugins/tedge_apt_plugin/src/{main.rs => lib.rs} (97%) rename plugins/tedge_log_plugin/src/{main.rs => lib.rs} (93%) diff --git a/Cargo.lock b/Cargo.lock index 90ea64e7c82..ca4052efdb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3496,10 +3496,14 @@ dependencies = [ name = "tedge" version = "0.12.0" dependencies = [ + "anstyle", "anyhow", "assert_cmd", "assert_matches", "base64 0.13.1", + "c8y-configuration-plugin", + "c8y-firmware-plugin", + "c8y-remote-access-plugin", "camino", "certificate", "clap", @@ -3516,6 +3520,11 @@ dependencies = [ "serde", "serde_json", "strum_macros", + "tedge-agent", + "tedge-apt-plugin", + "tedge-log-plugin", + "tedge-mapper", + "tedge-watchdog", "tedge_config", "tedge_utils", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index dc62134ec06..cd6e9e85477 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ homepage = "https://thin-edge.io" repository = "https://github.com/thin-edge/thin-edge.io" [workspace.dependencies] +anstyle = "1.0" anyhow = "1.0" assert-json-diff = "2.0" assert_cmd = "2.0" @@ -49,7 +50,10 @@ c8y_firmware_manager = { path = "crates/extensions/c8y_firmware_manager" } c8y_http_proxy = { path = "crates/extensions/c8y_http_proxy" } c8y_auth_proxy = { path = "crates/extensions/c8y_auth_proxy" } c8y_log_manager = { path = "crates/extensions/c8y_log_manager" } +c8y-configuration-plugin = { path = "plugins/c8y_configuration_plugin" } +c8y-firmware-plugin = { path = "plugins/c8y_firmware_plugin" } c8y_mapper_ext = { path = "crates/extensions/c8y_mapper_ext" } +c8y-remote-access-plugin = { path = "plugins/c8y_remote_access_plugin" } camino = "1.1" certificate = { path = "crates/common/certificate" } clap = { version = "4.4", features = ["cargo", "derive"] } @@ -127,6 +131,8 @@ strum_macros = "0.24" syn = { version = "2", features = ["full", "extra-traits"] } tedge_actors = { path = "crates/core/tedge_actors" } tedge_api = { path = "crates/core/tedge_api" } +tedge-apt-plugin = { path = "plugins/tedge_apt_plugin" } +tedge-agent = { path = "crates/core/tedge_agent" } tedge_config = { path = "crates/common/tedge_config" } tedge_config_macros = { path = "crates/common/tedge_config_macros" } tedge_config_macros-impl = { path = "crates/common/tedge_config_macros/impl" } @@ -136,11 +142,14 @@ tedge_file_system_ext = { path = "crates/extensions/tedge_file_system_ext" } tedge_health_ext = { path = "crates/extensions/tedge_health_ext" } tedge_http_ext = { path = "crates/extensions/tedge_http_ext" } tedge_log_manager = { path = "crates/extensions/tedge_log_manager" } +tedge-log-plugin = { path = "plugins/tedge_log_plugin" } +tedge-mapper = { path = "crates/core/tedge_mapper" } tedge_mqtt_ext = { path = "crates/extensions/tedge_mqtt_ext" } tedge_signal_ext = { path = "crates/extensions/tedge_signal_ext" } tedge_test_utils = { path = "crates/tests/tedge_test_utils" } tedge_timer_ext = { path = "crates/extensions/tedge_timer_ext" } tedge_utils = { path = "crates/common/tedge_utils" } +tedge-watchdog = { path = "crates/core/tedge_watchdog" } tempfile = "3.5" test-case = "2.2" thiserror = "1.0" diff --git a/crates/core/tedge/Cargo.toml b/crates/core/tedge/Cargo.toml index d84c25155f5..55bc54f4294 100644 --- a/crates/core/tedge/Cargo.toml +++ b/crates/core/tedge/Cargo.toml @@ -11,11 +11,15 @@ repository = { workspace = true } readme = "README.md" [dependencies] +anstyle = { workspace = true } anyhow = { workspace = true } base64 = { workspace = true } +c8y-configuration-plugin = { workspace = true } +c8y-firmware-plugin = { workspace = true } +c8y-remote-access-plugin = { workspace = true } camino = { workspace = true } certificate = { workspace = true } -clap = { workspace = true, features = ["cargo", "derive"] } +clap = { workspace = true, features = ["cargo", "derive", "string", "unstable-styles"] } doku = { workspace = true } hyper = { workspace = true, default-features = false } pad = { workspace = true } @@ -30,9 +34,15 @@ rumqttc = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } strum_macros = { workspace = true } +tedge-agent = { workspace = true } +tedge-apt-plugin = { workspace = true } +tedge-log-plugin = { workspace = true } +tedge-mapper = { workspace = true } +tedge-watchdog = { workspace = true } tedge_config = { workspace = true } tedge_utils = { workspace = true } thiserror = { workspace = true } +tokio = { workspace = true, features = ["macros"] } toml = { workspace = true } tracing = { workspace = true } url = { workspace = true } diff --git a/crates/core/tedge/src/cli/mod.rs b/crates/core/tedge/src/cli/mod.rs index 33bb7dfc8e3..7fc28afca37 100644 --- a/crates/core/tedge/src/cli/mod.rs +++ b/crates/core/tedge/src/cli/mod.rs @@ -4,11 +4,17 @@ pub use self::certificate::*; use crate::command::BuildCommand; use crate::command::BuildContext; use crate::command::Command; +use c8y_configuration_plugin::ConfigPluginOpt; +use c8y_firmware_plugin::FirmwarePluginOpt; +use c8y_remote_access_plugin::C8yRemoteAccessPluginOpt; pub use connect::*; +use tedge_agent::AgentOpt; use tedge_config::DEFAULT_TEDGE_CONFIG_PATH; +use tedge_log_plugin::LogfilePluginOpt; +use tedge_mapper::MapperOpt; +use tedge_watchdog::WatchdogOpt; use self::init::TEdgeInitCmd; - mod certificate; mod common; pub mod config; @@ -23,22 +29,47 @@ mod reconnect; name = clap::crate_name!(), version = clap::crate_version!(), about = clap::crate_description!(), - arg_required_else_help(true) + arg_required_else_help(true), + allow_external_subcommands(true), + styles(styles()), + multicall(true), )] +pub enum TEdgeOptMulticall { + Tedge { + #[clap(subcommand)] + cmd: TEdgeOpt, -pub struct Opt { - /// Initialize the tedge - #[clap(long)] - pub init: bool, + #[clap(long = "config-dir", default_value = DEFAULT_TEDGE_CONFIG_PATH, global = true)] + config_dir: PathBuf, + }, - #[clap(long = "config-dir", default_value = DEFAULT_TEDGE_CONFIG_PATH)] - pub config_dir: PathBuf, + #[clap(flatten)] + Component(Component), +} - #[clap(subcommand)] - pub tedge: Option, +#[derive(clap::Parser, Debug)] +pub enum Component { + TedgeMapper(MapperOpt), + + TedgeAgent(AgentOpt), + + TedgeLogPlugin(LogfilePluginOpt), + + C8yConfigurationPlugin(ConfigPluginOpt), + + C8yFirmwarePlugin(FirmwarePluginOpt), + + TedgeWatchdog(WatchdogOpt), + + C8yRemoteAccessPlugin(C8yRemoteAccessPluginOpt), } #[derive(clap::Subcommand, Debug)] +#[clap( + name = clap::crate_name!(), + version = clap::crate_version!(), + about = clap::crate_description!(), +)] pub enum TEdgeOpt { /// Initialize Thin Edge Init { @@ -76,6 +107,44 @@ pub enum TEdgeOpt { Mqtt(mqtt::TEdgeMqttCli), } +fn styles() -> clap::builder::Styles { + clap::builder::Styles::styled() + .usage( + anstyle::Style::new() + .bold() + .underline() + .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))), + ) + .header( + anstyle::Style::new() + .bold() + .underline() + .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow))), + ) + .literal( + anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))), + ) + .invalid( + anstyle::Style::new() + .bold() + .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))), + ) + .error( + anstyle::Style::new() + .bold() + .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Red))), + ) + .valid( + anstyle::Style::new() + .bold() + .underline() + .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))), + ) + .placeholder( + anstyle::Style::new().fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::White))), + ) +} + impl BuildCommand for TEdgeOpt { fn build_command(self, context: BuildContext) -> Result, crate::ConfigError> { match self { @@ -89,3 +158,31 @@ impl BuildCommand for TEdgeOpt { } } } + +#[cfg(test)] +mod tests { + use crate::Component; + use crate::TEdgeOptMulticall; + use clap::Parser; + + #[test] + fn tedge_mapper_rejects_with_missing_argument() { + assert!(TEdgeOptMulticall::try_parse_from(["tedge-mapper"]).is_err()); + } + + #[test] + fn tedge_mapper_accepts_with_argument() { + assert!(matches!( + TEdgeOptMulticall::parse_from(["tedge-mapper", "c8y"]), + TEdgeOptMulticall::Component(Component::TedgeMapper(_)) + )); + } + + #[test] + fn tedge_agent_runs_with_no_additional_arguments() { + assert!(matches!( + TEdgeOptMulticall::parse_from(["tedge-agent"]), + TEdgeOptMulticall::Component(Component::TedgeAgent(_)) + )); + } +} diff --git a/crates/core/tedge/src/main.rs b/crates/core/tedge/src/main.rs index e6dc5faafa8..55cb5617abb 100644 --- a/crates/core/tedge/src/main.rs +++ b/crates/core/tedge/src/main.rs @@ -3,37 +3,87 @@ use anyhow::Context; use clap::Parser; +use std::future::Future; +use std::path::PathBuf; use tedge::command::BuildCommand; use tedge::command::BuildContext; +use tedge::Component; +use tedge::TEdgeOptMulticall; +use tedge_apt_plugin::AptCli; use tedge_config::system_services::set_log_level; -use tracing::log::warn; fn main() -> anyhow::Result<()> { - set_log_level(tracing::Level::WARN); + let executable_name = executable_name(); - let opt = tedge::cli::Opt::parse(); - - if opt.init { - warn!("This --init option has been deprecated and will be removed in a future release. Use the `tedge init` command instead"); + if executable_name.as_deref() == Some("apt") { + let try_opt = AptCli::try_parse(); + tedge_apt_plugin::run(try_opt); return Ok(()); } - let tedge_config_location = tedge_config::TEdgeConfigLocation::from_custom_root(opt.config_dir); - let config_repository = tedge_config::TEdgeConfigRepository::new(tedge_config_location.clone()); + let opt = parse_multicall_if_known(&executable_name); + match opt { + TEdgeOptMulticall::Component(Component::TedgeMapper(mapper_opt)) => { + block_on(tedge_mapper::run(mapper_opt)) + } + TEdgeOptMulticall::Component(Component::TedgeAgent(opt)) => block_on(tedge_agent::run(opt)), + TEdgeOptMulticall::Component(Component::TedgeLogPlugin(opt)) => { + block_on(tedge_log_plugin::run(opt)) + } + TEdgeOptMulticall::Component(Component::C8yConfigurationPlugin(cp_opt)) => { + block_on(c8y_configuration_plugin::run(cp_opt)) + } + TEdgeOptMulticall::Component(Component::C8yFirmwarePlugin(fp_opt)) => { + block_on(c8y_firmware_plugin::run(fp_opt)) + } + TEdgeOptMulticall::Component(Component::C8yRemoteAccessPlugin(opt)) => { + block_on(c8y_remote_access_plugin::run(opt)).unwrap(); + Ok(()) + } + TEdgeOptMulticall::Component(Component::TedgeWatchdog(opt)) => { + block_on(tedge_watchdog::run(opt)) + } + TEdgeOptMulticall::Tedge { cmd, config_dir } => { + set_log_level(tracing::Level::WARN); - let build_context = BuildContext { - config_repository, - config_location: tedge_config_location, - }; + let tedge_config_location = + tedge_config::TEdgeConfigLocation::from_custom_root(config_dir); + let config_repository = + tedge_config::TEdgeConfigRepository::new(tedge_config_location.clone()); - if let Some(tedge_opt) = opt.tedge { - let cmd = tedge_opt - .build_command(build_context) - .with_context(|| "missing configuration parameter")?; + let build_context = BuildContext { + config_repository, + config_location: tedge_config_location, + }; + let cmd = cmd + .build_command(build_context) + .with_context(|| "missing configuration parameter")?; - cmd.execute() - .with_context(|| format!("failed to {}", cmd.description())) - } else { - Ok(()) + cmd.execute() + .with_context(|| format!("failed to {}", cmd.description())) + } } } + +fn block_on(future: impl Future) -> T { + tokio::runtime::Runtime::new().unwrap().block_on(future) +} + +fn executable_name() -> Option { + Some( + PathBuf::from(std::env::args_os().next()?) + .file_stem()? + .to_str()? + .to_owned(), + ) +} + +fn parse_multicall_if_known(executable_name: &Option) -> T { + let cmd = T::command(); + + let is_known_subcommand = executable_name + .as_deref() + .map_or(false, |name| cmd.find_subcommand(name).is_some()); + let cmd = cmd.multicall(is_known_subcommand); + T::from_arg_matches(&cmd.get_matches()).expect("get_matches panics if invalid arguments are provided, so we won't have arg matches to convert") +} diff --git a/crates/core/tedge_agent/src/main.rs b/crates/core/tedge_agent/src/lib.rs similarity index 95% rename from crates/core/tedge_agent/src/main.rs rename to crates/core/tedge_agent/src/lib.rs index 44641671fc7..19387d2cd14 100644 --- a/crates/core/tedge_agent/src/main.rs +++ b/crates/core/tedge_agent/src/lib.rs @@ -15,7 +15,6 @@ use std::sync::Arc; use agent::AgentConfig; use camino::Utf8PathBuf; -use clap::Parser; use tedge_config::system_services::get_log_level; use tedge_config::system_services::set_log_level; use tedge_config::DEFAULT_TEDGE_CONFIG_PATH; @@ -62,9 +61,7 @@ pub struct AgentOpt { pub mqtt_topic_root: Option>, } -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - let agent_opt = AgentOpt::parse(); +pub async fn run(agent_opt: AgentOpt) -> Result<(), anyhow::Error> { let tedge_config_location = tedge_config::TEdgeConfigLocation::from_custom_root(agent_opt.config_dir.clone()); diff --git a/crates/core/tedge_mapper/src/az/mapper.rs b/crates/core/tedge_mapper/src/az/mapper.rs index bdeec00bd9f..6a17a0bf341 100644 --- a/crates/core/tedge_mapper/src/az/mapper.rs +++ b/crates/core/tedge_mapper/src/az/mapper.rs @@ -14,13 +14,7 @@ use tracing::warn; const AZURE_MAPPER_NAME: &str = "tedge-mapper-az"; -pub struct AzureMapper {} - -impl AzureMapper { - pub fn new() -> AzureMapper { - AzureMapper {} - } -} +pub struct AzureMapper; #[async_trait] impl TEdgeComponent for AzureMapper { diff --git a/crates/core/tedge_mapper/src/main.rs b/crates/core/tedge_mapper/src/lib.rs similarity index 95% rename from crates/core/tedge_mapper/src/main.rs rename to crates/core/tedge_mapper/src/lib.rs index 3700b1ca18d..995ee6cbc8d 100644 --- a/crates/core/tedge_mapper/src/main.rs +++ b/crates/core/tedge_mapper/src/lib.rs @@ -20,7 +20,7 @@ mod core; fn lookup_component(component_name: &MapperName) -> Box { match component_name { - MapperName::Az => Box::new(AzureMapper::new()), + MapperName::Az => Box::new(AzureMapper), MapperName::Aws => Box::new(AwsMapper), MapperName::Collectd => Box::new(CollectdMapper), MapperName::C8y => Box::new(CumulocityMapper), @@ -80,10 +80,7 @@ impl fmt::Display for MapperName { } } -#[tokio::main] -async fn main() -> anyhow::Result<()> { - let mapper_opt = MapperOpt::parse(); - +pub async fn run(mapper_opt: MapperOpt) -> anyhow::Result<()> { let component = lookup_component(&mapper_opt.name); let tedge_config_location = diff --git a/crates/core/tedge_watchdog/src/main.rs b/crates/core/tedge_watchdog/src/lib.rs similarity index 91% rename from crates/core/tedge_watchdog/src/main.rs rename to crates/core/tedge_watchdog/src/lib.rs index 4bb06b201cd..a86f8031b42 100644 --- a/crates/core/tedge_watchdog/src/main.rs +++ b/crates/core/tedge_watchdog/src/lib.rs @@ -1,4 +1,3 @@ -use clap::Parser; use std::path::PathBuf; use tedge_config::system_services::*; use tedge_config::DEFAULT_TEDGE_CONFIG_PATH; @@ -38,9 +37,7 @@ pub struct WatchdogOpt { pub config_dir: PathBuf, } -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - let watchdog_opt = WatchdogOpt::parse(); +pub async fn run(watchdog_opt: WatchdogOpt) -> Result<(), anyhow::Error> { let tedge_config_location = tedge_config::TEdgeConfigLocation::from_custom_root(watchdog_opt.config_dir.clone()); diff --git a/plugins/c8y_configuration_plugin/src/main.rs b/plugins/c8y_configuration_plugin/src/lib.rs similarity index 94% rename from plugins/c8y_configuration_plugin/src/main.rs rename to plugins/c8y_configuration_plugin/src/lib.rs index f23d8c6146c..b938d983486 100644 --- a/plugins/c8y_configuration_plugin/src/main.rs +++ b/plugins/c8y_configuration_plugin/src/lib.rs @@ -2,7 +2,6 @@ use c8y_config_manager::ConfigManagerBuilder; use c8y_config_manager::ConfigManagerConfig; use c8y_http_proxy::credentials::C8YJwtRetriever; use c8y_http_proxy::C8YHttpProxyBuilder; -use clap::Parser; use std::path::Path; use std::path::PathBuf; use tedge_actors::Runtime; @@ -54,9 +53,7 @@ pub struct ConfigPluginOpt { pub config_dir: PathBuf, } -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - let config_plugin_opt = ConfigPluginOpt::parse(); +pub async fn run(config_plugin_opt: ConfigPluginOpt) -> Result<(), anyhow::Error> { let config_dir = config_plugin_opt.config_dir; // Load tedge config from the provided location @@ -76,11 +73,14 @@ async fn main() -> Result<(), anyhow::Error> { warn!("This --init option has been deprecated and will be removed in a future release"); Ok(()) } else { - run(config_dir, tedge_config).await + run_with(config_dir, tedge_config).await } } -async fn run(config_dir: impl AsRef, tedge_config: TEdgeConfig) -> Result<(), anyhow::Error> { +async fn run_with( + config_dir: impl AsRef, + tedge_config: TEdgeConfig, +) -> Result<(), anyhow::Error> { let runtime_events_logger = None; let mut runtime = Runtime::try_new(runtime_events_logger).await?; diff --git a/plugins/c8y_firmware_plugin/src/main.rs b/plugins/c8y_firmware_plugin/src/lib.rs similarity index 94% rename from plugins/c8y_firmware_plugin/src/main.rs rename to plugins/c8y_firmware_plugin/src/lib.rs index 3be516ca8ee..f00445437ab 100644 --- a/plugins/c8y_firmware_plugin/src/main.rs +++ b/plugins/c8y_firmware_plugin/src/lib.rs @@ -1,7 +1,6 @@ use c8y_firmware_manager::FirmwareManagerBuilder; use c8y_firmware_manager::FirmwareManagerConfig; use c8y_http_proxy::credentials::C8YJwtRetriever; -use clap::Parser; use std::path::PathBuf; use tedge_actors::Runtime; use tedge_config::system_services::get_log_level; @@ -50,10 +49,7 @@ pub struct FirmwarePluginOpt { pub config_dir: PathBuf, } -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - let firmware_plugin_opt = FirmwarePluginOpt::parse(); - +pub async fn run(firmware_plugin_opt: FirmwarePluginOpt) -> Result<(), anyhow::Error> { // Load tedge config from the provided location let tedge_config_location = tedge_config::TEdgeConfigLocation::from_custom_root(&firmware_plugin_opt.config_dir); @@ -72,11 +68,11 @@ async fn main() -> Result<(), anyhow::Error> { warn!("This --init option has been deprecated and will be removed in a future release"); Ok(()) } else { - run(tedge_config).await + run_with(tedge_config).await } } -async fn run(tedge_config: TEdgeConfig) -> Result<(), anyhow::Error> { +async fn run_with(tedge_config: TEdgeConfig) -> Result<(), anyhow::Error> { let runtime_events_logger = None; let mut runtime = Runtime::try_new(runtime_events_logger).await?; diff --git a/plugins/c8y_remote_access_plugin/src/input.rs b/plugins/c8y_remote_access_plugin/src/input.rs index 077730ba240..082cb5d7445 100644 --- a/plugins/c8y_remote_access_plugin/src/input.rs +++ b/plugins/c8y_remote_access_plugin/src/input.rs @@ -18,7 +18,7 @@ pub struct RemoteAccessConnect { key: String, } -#[derive(Parser)] +#[derive(Parser, Debug)] #[clap(group(ArgGroup::new("install").args(&["init", "cleanup", "connect_string", "child"])))] #[clap( name = clap::crate_name!(), @@ -26,7 +26,7 @@ version = clap::crate_version!(), about = clap::crate_description!(), arg_required_else_help(true), )] -pub struct Cli { +pub struct C8yRemoteAccessPluginOpt { #[arg(long = "config-dir", default_value = DEFAULT_TEDGE_CONFIG_PATH)] config_dir: PathBuf, @@ -47,7 +47,7 @@ pub struct Cli { child: Option, } -impl Cli { +impl C8yRemoteAccessPluginOpt { pub fn get_config_location(&self) -> TEdgeConfigLocation { TEdgeConfigLocation::from_custom_root(&self.config_dir) } @@ -61,21 +61,21 @@ pub enum Command { Connect(RemoteAccessConnect), } -pub fn parse_arguments(cli: Cli) -> miette::Result { +pub fn parse_arguments(cli: C8yRemoteAccessPluginOpt) -> miette::Result { cli.try_into() } -impl TryFrom for Command { +impl TryFrom for Command { type Error = miette::Error; - fn try_from(arguments: Cli) -> Result { + fn try_from(arguments: C8yRemoteAccessPluginOpt) -> Result { match arguments { - Cli { init: true, .. } => Ok(Command::Init), - Cli { cleanup: true, .. } => Ok(Command::Cleanup), - Cli { + C8yRemoteAccessPluginOpt { init: true, .. } => Ok(Command::Init), + C8yRemoteAccessPluginOpt { cleanup: true, .. } => Ok(Command::Cleanup), + C8yRemoteAccessPluginOpt { connect_string: Some(message), .. } => Ok(Command::SpawnChild(message)), - Cli { + C8yRemoteAccessPluginOpt { child: Some(message), .. } => RemoteAccessConnect::deserialize_smartrest(&message).map(Command::Connect), @@ -149,9 +149,11 @@ mod tests { } fn try_parse_arguments(arguments: &[&str]) -> miette::Result { - Cli::try_parse_from(iter::once(&"c8y-remote-access-plugin").chain(arguments)) - .into_diagnostic()? - .try_into() + C8yRemoteAccessPluginOpt::try_parse_from( + iter::once(&"c8y-remote-access-plugin").chain(arguments), + ) + .into_diagnostic()? + .try_into() } #[test] diff --git a/plugins/c8y_remote_access_plugin/src/main.rs b/plugins/c8y_remote_access_plugin/src/lib.rs similarity index 98% rename from plugins/c8y_remote_access_plugin/src/main.rs rename to plugins/c8y_remote_access_plugin/src/lib.rs index 869adcd0cde..c9f5fa4e43a 100644 --- a/plugins/c8y_remote_access_plugin/src/main.rs +++ b/plugins/c8y_remote_access_plugin/src/lib.rs @@ -3,7 +3,6 @@ use std::process::Stdio; use camino::Utf8Path; use camino::Utf8PathBuf; -use clap::Parser; use futures::future::try_select; use futures::future::Either; use input::parse_arguments; @@ -20,6 +19,7 @@ use toml::Table; use url::Url; use crate::auth::Jwt; +pub use crate::input::C8yRemoteAccessPluginOpt; use crate::input::Command; use crate::input::RemoteAccessConnect; use crate::proxy::WebsocketSocketProxy; @@ -29,10 +29,7 @@ mod csv; mod input; mod proxy; -#[tokio::main] -async fn main() -> miette::Result<()> { - let opt = input::Cli::parse(); - +pub async fn run(opt: C8yRemoteAccessPluginOpt) -> miette::Result<()> { let config_dir = opt.get_config_location(); let tedge_config = TEdgeConfigRepository::new(config_dir.clone()) diff --git a/plugins/tedge_apt_plugin/src/main.rs b/plugins/tedge_apt_plugin/src/lib.rs similarity index 97% rename from plugins/tedge_apt_plugin/src/main.rs rename to plugins/tedge_apt_plugin/src/lib.rs index 99e734777b8..59f9633f3ef 100644 --- a/plugins/tedge_apt_plugin/src/main.rs +++ b/plugins/tedge_apt_plugin/src/lib.rs @@ -3,7 +3,6 @@ mod module_check; use crate::error::InternalError; use crate::module_check::PackageMetadata; -use clap::Parser; use log::warn; use regex::Regex; use serde::Deserialize; @@ -17,14 +16,14 @@ use tedge_config::TEdgeConfigLocation; use tedge_config::TEdgeConfigRepository; use tedge_config::DEFAULT_TEDGE_CONFIG_PATH; -#[derive(Parser, Debug)] +#[derive(clap::Parser, Debug)] #[clap( name = clap::crate_name!(), version = clap::crate_version!(), about = clap::crate_description!(), arg_required_else_help(true) )] -struct AptCli { +pub struct AptCli { #[clap(long = "config-dir", default_value = DEFAULT_TEDGE_CONFIG_PATH)] config_dir: PathBuf, @@ -87,7 +86,7 @@ struct SoftwareModuleUpdate { pub path: Option, } -fn run(operation: PluginOp) -> Result { +fn run_op(operation: PluginOp) -> Result { let status = match operation { PluginOp::List { name, maintainer } => { let dpkg_query = Command::new("dpkg-query") @@ -303,8 +302,8 @@ fn get_config(config_dir: PathBuf) -> Option { } } -fn main() { - let mut apt = match AptCli::try_parse() { +pub fn run(cli: Result) { + let mut apt = match cli { Ok(aptcli) => aptcli, Err(err) => { err.print().expect("Failed to print help message"); @@ -313,11 +312,7 @@ fn main() { } }; - if let PluginOp::List { - ref mut name, - ref mut maintainer, - } = apt.operation - { + if let PluginOp::List { name, maintainer } = &mut apt.operation { if let Some(config) = get_config(apt.config_dir) { if name.is_none() { *name = config.apt.name.or_none().cloned(); @@ -329,7 +324,7 @@ fn main() { } } - match run(apt.operation) { + match run_op(apt.operation) { Ok(status) if status.success() => { std::process::exit(0); } @@ -372,6 +367,6 @@ mod tests { name: Some("".into()), maintainer: Some("".into()), }; - assert!(run(filters).is_ok()) + assert!(run_op(filters).is_ok()) } } diff --git a/plugins/tedge_log_plugin/src/main.rs b/plugins/tedge_log_plugin/src/lib.rs similarity index 93% rename from plugins/tedge_log_plugin/src/main.rs rename to plugins/tedge_log_plugin/src/lib.rs index d4b26c54533..3066f9c9a10 100644 --- a/plugins/tedge_log_plugin/src/main.rs +++ b/plugins/tedge_log_plugin/src/lib.rs @@ -51,10 +51,7 @@ pub struct LogfilePluginOpt { mqtt_device_topic_id: Option>, } -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - let logfile_opt = LogfilePluginOpt::parse(); - +pub async fn run(logfile_opt: LogfilePluginOpt) -> Result<(), anyhow::Error> { // Load tedge config from the provided location let tedge_config_location = TEdgeConfigLocation::from_custom_root(&logfile_opt.config_dir); @@ -70,10 +67,13 @@ async fn main() -> Result<(), anyhow::Error> { let tedge_config = TEdgeConfigRepository::new(tedge_config_location).load()?; - run(tedge_config, logfile_opt).await + run_with(tedge_config, logfile_opt).await } -async fn run(tedge_config: TEdgeConfig, cliopts: LogfilePluginOpt) -> Result<(), anyhow::Error> { +async fn run_with( + tedge_config: TEdgeConfig, + cliopts: LogfilePluginOpt, +) -> Result<(), anyhow::Error> { let runtime_events_logger = None; let mut runtime = Runtime::try_new(runtime_events_logger).await?; From 9a677e332d1c1eb59a83669c3525b50546463513 Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Tue, 26 Sep 2023 14:56:24 +0100 Subject: [PATCH 2/4] Add thin binary wrappers around new libraries for backwards compatibility Signed-off-by: James Rhodes --- crates/core/tedge/src/main.rs | 3 +-- crates/core/tedge_agent/src/main.rs | 7 +++++++ crates/core/tedge_mapper/src/main.rs | 7 +++++++ crates/core/tedge_watchdog/src/main.rs | 7 +++++++ plugins/c8y_configuration_plugin/src/main.rs | 8 ++++++++ plugins/c8y_firmware_plugin/src/main.rs | 7 +++++++ plugins/c8y_remote_access_plugin/src/main.rs | 9 +++++++++ plugins/tedge_apt_plugin/src/lib.rs | 2 +- plugins/tedge_apt_plugin/src/main.rs | 6 ++++++ plugins/tedge_log_plugin/src/main.rs | 7 +++++++ 10 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 crates/core/tedge_agent/src/main.rs create mode 100644 crates/core/tedge_mapper/src/main.rs create mode 100644 crates/core/tedge_watchdog/src/main.rs create mode 100644 plugins/c8y_configuration_plugin/src/main.rs create mode 100644 plugins/c8y_firmware_plugin/src/main.rs create mode 100644 plugins/c8y_remote_access_plugin/src/main.rs create mode 100644 plugins/tedge_apt_plugin/src/main.rs create mode 100644 plugins/tedge_log_plugin/src/main.rs diff --git a/crates/core/tedge/src/main.rs b/crates/core/tedge/src/main.rs index 55cb5617abb..b1ac5f6fe01 100644 --- a/crates/core/tedge/src/main.rs +++ b/crates/core/tedge/src/main.rs @@ -17,8 +17,7 @@ fn main() -> anyhow::Result<()> { if executable_name.as_deref() == Some("apt") { let try_opt = AptCli::try_parse(); - tedge_apt_plugin::run(try_opt); - return Ok(()); + tedge_apt_plugin::run_and_exit(try_opt); } let opt = parse_multicall_if_known(&executable_name); diff --git a/crates/core/tedge_agent/src/main.rs b/crates/core/tedge_agent/src/main.rs new file mode 100644 index 00000000000..0efbe96a006 --- /dev/null +++ b/crates/core/tedge_agent/src/main.rs @@ -0,0 +1,7 @@ +use clap::Parser; + +#[tokio::main] +async fn main() -> Result<(), anyhow::Error> { + let agent_opt = tedge_agent::AgentOpt::parse(); + tedge_agent::run(agent_opt).await +} diff --git a/crates/core/tedge_mapper/src/main.rs b/crates/core/tedge_mapper/src/main.rs new file mode 100644 index 00000000000..a1ccaa45a55 --- /dev/null +++ b/crates/core/tedge_mapper/src/main.rs @@ -0,0 +1,7 @@ +use clap::Parser; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let mapper_opt = tedge_mapper::MapperOpt::parse(); + tedge_mapper::run(mapper_opt).await +} diff --git a/crates/core/tedge_watchdog/src/main.rs b/crates/core/tedge_watchdog/src/main.rs new file mode 100644 index 00000000000..2134b02d586 --- /dev/null +++ b/crates/core/tedge_watchdog/src/main.rs @@ -0,0 +1,7 @@ +use clap::Parser; + +#[tokio::main] +async fn main() { + let opt = tedge_watchdog::WatchdogOpt::parse(); + tedge_watchdog::run(opt).await.unwrap(); +} diff --git a/plugins/c8y_configuration_plugin/src/main.rs b/plugins/c8y_configuration_plugin/src/main.rs new file mode 100644 index 00000000000..26ad03a74b8 --- /dev/null +++ b/plugins/c8y_configuration_plugin/src/main.rs @@ -0,0 +1,8 @@ +use c8y_configuration_plugin::ConfigPluginOpt; +use clap::Parser; + +#[tokio::main] +async fn main() { + let opt = ConfigPluginOpt::parse(); + c8y_configuration_plugin::run(opt).await.unwrap(); +} diff --git a/plugins/c8y_firmware_plugin/src/main.rs b/plugins/c8y_firmware_plugin/src/main.rs new file mode 100644 index 00000000000..891c379e5d8 --- /dev/null +++ b/plugins/c8y_firmware_plugin/src/main.rs @@ -0,0 +1,7 @@ +use clap::Parser; + +#[tokio::main] +async fn main() { + let opt = c8y_firmware_plugin::FirmwarePluginOpt::parse(); + c8y_firmware_plugin::run(opt).await.unwrap(); +} diff --git a/plugins/c8y_remote_access_plugin/src/main.rs b/plugins/c8y_remote_access_plugin/src/main.rs new file mode 100644 index 00000000000..412c45e3a0f --- /dev/null +++ b/plugins/c8y_remote_access_plugin/src/main.rs @@ -0,0 +1,9 @@ +use c8y_remote_access_plugin::C8yRemoteAccessPluginOpt; +use clap::Parser; + +#[tokio::main] +async fn main() { + miette::set_panic_hook(); + let opt = C8yRemoteAccessPluginOpt::parse(); + c8y_remote_access_plugin::run(opt).await.unwrap(); +} diff --git a/plugins/tedge_apt_plugin/src/lib.rs b/plugins/tedge_apt_plugin/src/lib.rs index 59f9633f3ef..13c3e4bab6c 100644 --- a/plugins/tedge_apt_plugin/src/lib.rs +++ b/plugins/tedge_apt_plugin/src/lib.rs @@ -302,7 +302,7 @@ fn get_config(config_dir: PathBuf) -> Option { } } -pub fn run(cli: Result) { +pub fn run_and_exit(cli: Result) -> ! { let mut apt = match cli { Ok(aptcli) => aptcli, Err(err) => { diff --git a/plugins/tedge_apt_plugin/src/main.rs b/plugins/tedge_apt_plugin/src/main.rs new file mode 100644 index 00000000000..cb2be35b461 --- /dev/null +++ b/plugins/tedge_apt_plugin/src/main.rs @@ -0,0 +1,6 @@ +use clap::Parser; + +fn main() { + let cli = tedge_apt_plugin::AptCli::try_parse(); + tedge_apt_plugin::run_and_exit(cli); +} diff --git a/plugins/tedge_log_plugin/src/main.rs b/plugins/tedge_log_plugin/src/main.rs new file mode 100644 index 00000000000..30880c25ffe --- /dev/null +++ b/plugins/tedge_log_plugin/src/main.rs @@ -0,0 +1,7 @@ +use clap::Parser; + +#[tokio::main] +async fn main() { + let opt = tedge_log_plugin::LogfilePluginOpt::parse(); + tedge_log_plugin::run(opt).await.unwrap(); +} From 24cb26035d3bd9a1600258e620913495a895829e Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Fri, 29 Sep 2023 17:27:02 +0100 Subject: [PATCH 3/4] Extend tedge init to create symlinks to new multicall binary Signed-off-by: James Rhodes --- Cargo.lock | 1 + crates/core/tedge/Cargo.toml | 1 + crates/core/tedge/src/cli/init.rs | 82 ++++++++++++++++++++++++++++++- crates/core/tedge/src/cli/mod.rs | 16 +++++- crates/core/tedge/src/main.rs | 2 +- 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca4052efdb1..155ed5cdc1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3511,6 +3511,7 @@ dependencies = [ "hyper", "mockito", "mqtt_tests", + "nix", "pad", "pem", "predicates 2.1.5", diff --git a/crates/core/tedge/Cargo.toml b/crates/core/tedge/Cargo.toml index 55bc54f4294..e882802ef24 100644 --- a/crates/core/tedge/Cargo.toml +++ b/crates/core/tedge/Cargo.toml @@ -22,6 +22,7 @@ certificate = { workspace = true } clap = { workspace = true, features = ["cargo", "derive", "string", "unstable-styles"] } doku = { workspace = true } hyper = { workspace = true, default-features = false } +nix = { workspace = true } pad = { workspace = true } reqwest = { workspace = true, features = [ "blocking", diff --git a/crates/core/tedge/src/cli/init.rs b/crates/core/tedge/src/cli/init.rs index d963f31d1df..1d4c8bc8986 100644 --- a/crates/core/tedge/src/cli/init.rs +++ b/crates/core/tedge/src/cli/init.rs @@ -1,6 +1,11 @@ use crate::command::BuildContext; use crate::command::Command; +use crate::Component; +use anyhow::bail; use anyhow::Context; +use clap::Subcommand; +use std::os::unix::fs::MetadataExt; +use std::path::Path; use tedge_utils::file::create_directory; use tedge_utils::file::PermissionEntry; @@ -8,19 +13,94 @@ use tedge_utils::file::PermissionEntry; pub struct TEdgeInitCmd { user: String, group: String, + relative_links: bool, context: BuildContext, } impl TEdgeInitCmd { - pub fn new(user: String, group: String, context: BuildContext) -> Self { + pub fn new(user: String, group: String, relative_links: bool, context: BuildContext) -> Self { Self { user, group, + relative_links, context, } } fn initialize_tedge(&self) -> anyhow::Result<()> { + let executable_name = + std::env::current_exe().context("retrieving the current executable name")?; + let stat = std::fs::metadata(&executable_name).with_context(|| { + format!( + "reading metadata for the current executable ({})", + executable_name.display() + ) + })?; + let Some(executable_dir) = executable_name.parent() else { + bail!( + "current executable ({}) does not have a parent directory", + executable_name.display() + ) + }; + let Some(executable_file_name) = executable_name.file_name() else { + bail!( + "current executable ({}) does not have a file name", + executable_name.display() + ) + }; + + let component_subcommands: Vec = + Component::augment_subcommands(clap::Command::new("tedge")) + .get_subcommands() + .map(|c| c.get_name().to_owned()) + .chain(["tedge-apt-plugin".to_owned()]) + .collect(); + + for component in &component_subcommands { + let link = executable_dir.join(component); + match std::fs::symlink_metadata(&link) { + Err(e) if e.kind() != std::io::ErrorKind::NotFound => bail!( + "couldn't read metadata for {}. do you need to run with sudo?", + link.display() + ), + meta => { + let file_exists = meta.is_ok(); + if file_exists { + nix::unistd::unlink(&link).with_context(|| { + format!("removing old version of {component} at {}", link.display()) + })?; + } + + let tedge = if self.relative_links { + Path::new(executable_file_name) + } else { + &*executable_name + }; + std::os::unix::fs::symlink(tedge, &link).with_context(|| { + format!("creating symlink for {component} to {}", tedge.display()) + })?; + + let res = std::process::Command::new("chown") + .arg("--no-dereference") + .arg(&format!("{}:{}", stat.uid(), stat.gid())) + .arg(&link) + .output() + .with_context(|| { + format!( + "executing chown to change ownership of symlink at {}", + link.display() + ) + })?; + anyhow::ensure!( + res.status.success(), + "failed to change ownership of symlink at {}\n\nSTDERR: {}", + link.display(), + String::from_utf8_lossy(&res.stderr), + ) + } + } + } + let config_dir = self.context.config_location.tedge_config_root_path.clone(); create_directory( &config_dir, diff --git a/crates/core/tedge/src/cli/mod.rs b/crates/core/tedge/src/cli/mod.rs index 7fc28afca37..ea3d36e5851 100644 --- a/crates/core/tedge/src/cli/mod.rs +++ b/crates/core/tedge/src/cli/mod.rs @@ -80,6 +80,11 @@ pub enum TEdgeOpt { /// The group who will own the directories created #[clap(long, default_value = "tedge")] group: String, + + /// Create symlinks to the tedge binary using a relative path + /// (e.g. ./tedge) instead of an absolute path (e.g. /usr/bin/tedge) + #[clap(long)] + relative_links: bool, }, /// Create and manage device certificate @@ -148,7 +153,16 @@ fn styles() -> clap::builder::Styles { impl BuildCommand for TEdgeOpt { fn build_command(self, context: BuildContext) -> Result, crate::ConfigError> { match self { - TEdgeOpt::Init { user, group } => Ok(Box::new(TEdgeInitCmd::new(user, group, context))), + TEdgeOpt::Init { + user, + group, + relative_links, + } => Ok(Box::new(TEdgeInitCmd::new( + user, + group, + relative_links, + context, + ))), TEdgeOpt::Cert(opt) => opt.build_command(context), TEdgeOpt::Config(opt) => opt.build_command(context), TEdgeOpt::Connect(opt) => opt.build_command(context), diff --git a/crates/core/tedge/src/main.rs b/crates/core/tedge/src/main.rs index b1ac5f6fe01..5e97c7e0829 100644 --- a/crates/core/tedge/src/main.rs +++ b/crates/core/tedge/src/main.rs @@ -15,7 +15,7 @@ use tedge_config::system_services::set_log_level; fn main() -> anyhow::Result<()> { let executable_name = executable_name(); - if executable_name.as_deref() == Some("apt") { + if matches!(executable_name.as_deref(), Some("apt" | "tedge-apt-plugin")) { let try_opt = AptCli::try_parse(); tedge_apt_plugin::run_and_exit(try_opt); } From 49607e8b75caa568e96ee8413537ce1b3d7830d5 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Wed, 4 Oct 2023 20:01:47 +1000 Subject: [PATCH 4/4] use multi-call binary in packaging Signed-off-by: Reuben Miller --- ci/build_scripts/package.sh | 5 +++-- .../nfpm.c8y-configuration-plugin.yaml | 4 ---- .../package_manifests/nfpm.c8y-firmware-plugin.yaml | 7 +++---- .../nfpm.c8y-remote-access-plugin.yaml | 10 ---------- configuration/package_manifests/nfpm.tedge-agent.yaml | 6 ++---- .../package_manifests/nfpm.tedge-apt-plugin.yaml | 6 ++---- .../package_manifests/nfpm.tedge-log-plugin.yaml | 6 ++---- configuration/package_manifests/nfpm.tedge-mapper.yaml | 4 ---- .../package_manifests/nfpm.tedge-watchdog.yaml | 6 ++---- 9 files changed, 14 insertions(+), 40 deletions(-) diff --git a/ci/build_scripts/package.sh b/ci/build_scripts/package.sh index bd25a8ad3b1..22766b18e4c 100755 --- a/ci/build_scripts/package.sh +++ b/ci/build_scripts/package.sh @@ -227,15 +227,16 @@ build_tarball() { tar_type="bsdtar" fi + # Only include the tedge binary as it is a multi-call binary case "$tar_type" in bsdtar) # bsd tar requires different options to prevent adding extra "AppleDouble" files, e.g. `._` files, to the archive echo "Using bsdtar, but please consider using gnu-tar instead. Install via: brew install gnu-tar" - COPYFILE_DISABLE=1 tar cfz "$TAR_FILE" --no-xattrs --no-mac-metadata -C "$source_dir" --files-from <(printf "%s\n" "${PACKAGES[@]}") + COPYFILE_DISABLE=1 tar cfz "$TAR_FILE" --no-xattrs --no-mac-metadata -C "$source_dir" --files-from <(printf "%s\n" "tedge") ;; *) # Default to gnu tar (as this is generally the default) - "$tar_cmd" cfz "$TAR_FILE" --no-xattrs --owner=0 --group=0 --mode='0755' -C "$source_dir" --files-from <(printf "%s\n" "${PACKAGES[@]}") + "$tar_cmd" cfz "$TAR_FILE" --no-xattrs --owner=0 --group=0 --mode='0755' -C "$source_dir" --files-from <(printf "%s\n" "tedge") ;; esac diff --git a/configuration/package_manifests/nfpm.c8y-configuration-plugin.yaml b/configuration/package_manifests/nfpm.c8y-configuration-plugin.yaml index f0f549e7b7e..1af877db4a6 100644 --- a/configuration/package_manifests/nfpm.c8y-configuration-plugin.yaml +++ b/configuration/package_manifests/nfpm.c8y-configuration-plugin.yaml @@ -28,10 +28,6 @@ deb: - c8y_configuration_plugin (<= 0.8.1) contents: - # binary - - src: .build/c8y-configuration-plugin - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/c8y-configuration-plugin.service dst: /lib/systemd/system/ diff --git a/configuration/package_manifests/nfpm.c8y-firmware-plugin.yaml b/configuration/package_manifests/nfpm.c8y-firmware-plugin.yaml index e840b0e014f..24786f7669a 100644 --- a/configuration/package_manifests/nfpm.c8y-firmware-plugin.yaml +++ b/configuration/package_manifests/nfpm.c8y-firmware-plugin.yaml @@ -14,6 +14,9 @@ vendor: "thin-edge.io" homepage: "https://thin-edge.io" license: "Apache-2.0" +depends: + - tedge + deb: fields: Vcs-Browser: ${CI_PROJECT_URL} @@ -21,10 +24,6 @@ deb: compression: xz contents: - # binary - - src: .build/c8y-firmware-plugin - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/c8y-firmware-plugin.service dst: /lib/systemd/system/ diff --git a/configuration/package_manifests/nfpm.c8y-remote-access-plugin.yaml b/configuration/package_manifests/nfpm.c8y-remote-access-plugin.yaml index 310e024b716..c436d591500 100644 --- a/configuration/package_manifests/nfpm.c8y-remote-access-plugin.yaml +++ b/configuration/package_manifests/nfpm.c8y-remote-access-plugin.yaml @@ -21,18 +21,8 @@ deb: compression: xz depends: - # Requires tedge user to create the supported operation file. - # The tedge user is created by the tedge package - # so it must be run before this package's postinst. - # Debian seems to work without this depends, however the rpm package - # seems to use another sorting order if the dependency is not defined. - tedge -contents: - # binary - - src: .build/c8y-remote-access-plugin - dst: /usr/bin/ - overrides: apk: scripts: diff --git a/configuration/package_manifests/nfpm.tedge-agent.yaml b/configuration/package_manifests/nfpm.tedge-agent.yaml index dc02745a98a..feab780b9f2 100644 --- a/configuration/package_manifests/nfpm.tedge-agent.yaml +++ b/configuration/package_manifests/nfpm.tedge-agent.yaml @@ -14,6 +14,8 @@ vendor: "thin-edge.io" homepage: "https://thin-edge.io" license: "Apache-2.0" +depends: + - tedge replaces: - tedge_agent provides: @@ -30,10 +32,6 @@ deb: - tedge_agent (<= 0.8.1) contents: - # binary - - src: .build/tedge-agent - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/tedge-agent.service dst: /lib/systemd/system/tedge-agent.service diff --git a/configuration/package_manifests/nfpm.tedge-apt-plugin.yaml b/configuration/package_manifests/nfpm.tedge-apt-plugin.yaml index abad5243902..a37ac6011d3 100644 --- a/configuration/package_manifests/nfpm.tedge-apt-plugin.yaml +++ b/configuration/package_manifests/nfpm.tedge-apt-plugin.yaml @@ -14,6 +14,8 @@ vendor: "thin-edge.io" homepage: "https://thin-edge.io" license: "Apache-2.0" +depends: + - tedge replaces: - tedge_apt_plugin conflicts: @@ -28,10 +30,6 @@ deb: - tedge_apt_plugin (<= 0.8.1) contents: - # binary - - src: .build/tedge-apt-plugin - dst: /usr/bin/ - # Symlink to sm plugin dir - src: /usr/bin/tedge-apt-plugin dst: /etc/tedge/sm-plugins/apt diff --git a/configuration/package_manifests/nfpm.tedge-log-plugin.yaml b/configuration/package_manifests/nfpm.tedge-log-plugin.yaml index 10a6f9ba9de..665818d7218 100644 --- a/configuration/package_manifests/nfpm.tedge-log-plugin.yaml +++ b/configuration/package_manifests/nfpm.tedge-log-plugin.yaml @@ -14,6 +14,8 @@ vendor: "thin-edge.io" homepage: "https://thin-edge.io" license: "Apache-2.0" +depends: + - tedge replaces: - c8y_log_plugin - c8y-log-plugin @@ -31,10 +33,6 @@ deb: - c8y-log-plugin contents: - # binary - - src: .build/tedge-log-plugin - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/tedge-log-plugin.service dst: /lib/systemd/system/ diff --git a/configuration/package_manifests/nfpm.tedge-mapper.yaml b/configuration/package_manifests/nfpm.tedge-mapper.yaml index 5372f221316..a787f2e2510 100644 --- a/configuration/package_manifests/nfpm.tedge-mapper.yaml +++ b/configuration/package_manifests/nfpm.tedge-mapper.yaml @@ -32,10 +32,6 @@ deb: - tedge_mapper (<= 0.8.1) contents: - # binary - - src: .build/tedge-mapper - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/tedge-mapper-aws.service dst: /lib/systemd/system/tedge-mapper-aws.service diff --git a/configuration/package_manifests/nfpm.tedge-watchdog.yaml b/configuration/package_manifests/nfpm.tedge-watchdog.yaml index 7fede4be953..a51590019a4 100644 --- a/configuration/package_manifests/nfpm.tedge-watchdog.yaml +++ b/configuration/package_manifests/nfpm.tedge-watchdog.yaml @@ -14,6 +14,8 @@ vendor: "thin-edge.io" homepage: "https://thin-edge.io" license: "Apache-2.0" +depends: + - tedge replaces: - tedge_watchdog conflicts: @@ -28,10 +30,6 @@ deb: - tedge_watchdog (<= 0.8.1) contents: - # binary - - src: .build/tedge-watchdog - dst: /usr/bin/ - # service definitions - src: ./configuration/init/systemd/tedge-watchdog.service dst: /lib/systemd/system/