From 6ce5897b8b915fc3780487bfe35bd7e4dc7ee000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sch=C3=B6nauer?= <37108907+DottoDev@users.noreply.github.com> Date: Wed, 28 Dec 2022 07:47:49 +0000 Subject: [PATCH] Adds Pclinuxos support (#283) --- src/main.rs | 6 +++--- src/report.rs | 2 +- src/steps/generic.rs | 2 +- src/steps/git.rs | 6 +++--- src/steps/os/linux.rs | 30 ++++++++++++++++++++++++++++++ src/steps/os/os_release/pclinuxos | 9 +++++++++ src/steps/os/windows.rs | 4 ++-- src/steps/powershell.rs | 2 +- src/steps/remote/ssh.rs | 8 ++++---- src/steps/remote/vagrant.rs | 2 +- src/steps/toolbx.rs | 2 +- src/terminal.rs | 14 +++++++------- src/utils.rs | 2 +- 13 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 src/steps/os/os_release/pclinuxos diff --git a/src/main.rs b/src/main.rs index c071b8a1..fa9416be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,7 +147,7 @@ fn run() -> Result<()> { if let Some(topgrades) = config.remote_topgrades() { for remote_topgrade in topgrades.iter().filter(|t| config.should_execute_remote(t)) { - runner.execute(Step::Remotes, format!("Remote ({})", remote_topgrade), || { + runner.execute(Step::Remotes, format!("Remote ({remote_topgrade})"), || { remote::ssh::ssh_step(&ctx, remote_topgrade) })?; } @@ -163,7 +163,7 @@ fn run() -> Result<()> { runner.execute(Step::System, "System update", || distribution.upgrade(&ctx))?; } Err(e) => { - println!("Error detecting current distribution: {}", e); + println!("Error detecting current distribution: {e}"); } } runner.execute(Step::ConfigUpdate, "config-update", || linux::run_config_update(&ctx))?; @@ -550,7 +550,7 @@ fn main() { // The `Debug` implementation of `eyre::Result` prints a multi-line // error message that includes all the 'causes' added with // `.with_context(...)` calls. - println!("Error: {:?}", error); + println!("Error: {error:?}"); } exit(1); } diff --git a/src/report.rs b/src/report.rs index a8efbea9..77e0d57a 100644 --- a/src/report.rs +++ b/src/report.rs @@ -34,7 +34,7 @@ impl<'a> Report<'a> { if let Some((key, success)) = result { let key = key.into(); - debug_assert!(!self.data.iter().any(|(k, _)| k == &key), "{} already reported", key); + debug_assert!(!self.data.iter().any(|(k, _)| k == &key), "{key} already reported"); self.data.push((key, success)); } } diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 541ea2e9..06e9fce8 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -435,7 +435,7 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> { let composer_home = Command::new(&composer) .args(["global", "config", "--absolute", "--quiet", "home"]) .output_checked_utf8() - .map_err(|e| (SkipStep(format!("Error getting the composer directory: {}", e)))) + .map_err(|e| (SkipStep(format!("Error getting the composer directory: {e}")))) .map(|s| PathBuf::from(s.stdout.trim()))? .require()?; diff --git a/src/steps/git.rs b/src/steps/git.rs index 4bd0cbad..0a053982 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -71,7 +71,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) - if let Err(message) = &result { println!("{} pulling {}", style("Failed").red().bold(), &repo); - print!("{}", message); + print!("{message}"); } else { let after_revision = get_head_revision(git, &repo); @@ -87,7 +87,7 @@ async fn pull_repository(repo: String, git: &Path, ctx: &ExecutionContext<'_>) - "log", "--no-decorate", "--oneline", - &format!("{}..{}", before, after), + &format!("{before}..{after}"), ]) .status_checked()?; println!(); @@ -187,7 +187,7 @@ impl Git { repositories .bad_patterns .iter() - .for_each(|pattern| print_warning(format!("Path {} did not contain any git repositories", pattern))); + .for_each(|pattern| print_warning(format!("Path {pattern} did not contain any git repositories"))); self.multi_pull(repositories, ctx) } diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 20d3653f..2db06683 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -29,6 +29,7 @@ pub enum Distribution { Debian, Gentoo, OpenMandriva, + PCLinuxOS, Suse, Void, Solus, @@ -57,6 +58,7 @@ impl Distribution { Some("nixos") => Distribution::NixOS, Some("neon") => Distribution::KDENeon, Some("openmandriva") => Distribution::OpenMandriva, + Some("pclinuxos") => Distribution::PCLinuxOS, _ => { if let Some(id_like) = id_like { if id_like.contains(&"debian") || id_like.contains(&"ubuntu") { @@ -110,6 +112,7 @@ impl Distribution { Distribution::KDENeon => upgrade_neon(ctx), Distribution::Bedrock => update_bedrock(ctx), Distribution::OpenMandriva => upgrade_openmandriva(ctx), + Distribution::PCLinuxOS => upgrade_pclinuxos(ctx), } } @@ -246,6 +249,33 @@ fn upgrade_openmandriva(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +fn upgrade_pclinuxos(ctx: &ExecutionContext) -> Result<()> { + if let Some(sudo) = &ctx.sudo() { + let mut command_update = ctx.run_type().execute(sudo); + + command_update.arg(&which("apt-get").unwrap()).arg("update"); + + if let Some(args) = ctx.config().dnf_arguments() { + command_update.args(args.split_whitespace()); + } + + if ctx.config().yes(Step::System) { + command_update.arg("-y"); + } + + command_update.status_checked()?; + + ctx.run_type() + .execute(sudo) + .arg(&which("apt-get").unwrap()) + .arg("dist-upgrade") + .status_checked()?; + } else { + print_warning("No sudo detected. Skipping system upgrade"); + } + + Ok(()) +} fn upgrade_void(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { diff --git a/src/steps/os/os_release/pclinuxos b/src/steps/os/os_release/pclinuxos new file mode 100644 index 00000000..2b1680c6 --- /dev/null +++ b/src/steps/os/os_release/pclinuxos @@ -0,0 +1,9 @@ +NAME="PCLinuxOS" +VERSION="2022" +ID=pclinuxos +VERSION_ID=2022 +ID_LIKE="mandriva" +PRETTY_NAME="PCLinuxOS 2022" +ANSI_COLOR="1;37" +HOME_URL="http://www.pclinuxos.com/" +SUPPORT_URL="http://www.pclinuxos.com/" diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 987704aa..85aa7d05 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -48,7 +48,7 @@ pub fn run_winget(ctx: &ExecutionContext) -> Result<()> { } ctx.run_type() - .execute(&winget) + .execute(winget) .args(["upgrade", "--all"]) .status_checked() } @@ -86,7 +86,7 @@ fn upgrade_wsl_distribution(wsl: &Path, dist: &str, ctx: &ExecutionContext) -> R let mut command = ctx.run_type().execute(wsl); command .args(["-d", dist, "bash", "-c"]) - .arg(format!("TOPGRADE_PREFIX={} exec {}", dist, topgrade)); + .arg(format!("TOPGRADE_PREFIX={dist} exec {topgrade}")); if ctx.config().yes(Step::Wsl) { command.arg("-y"); diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index f6fe50e3..6be22493 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -50,7 +50,7 @@ impl Powershell { .args([ "-NoProfile", "-Command", - &format!("Get-Module -ListAvailable {}", command), + &format!("Get-Module -ListAvailable {command}"), ]) .output_checked_utf8() .map(|result| !result.stdout.is_empty()) diff --git a/src/steps/remote/ssh.rs b/src/steps/remote/ssh.rs index c274766d..6a9f244c 100644 --- a/src/steps/remote/ssh.rs +++ b/src/steps/remote/ssh.rs @@ -19,7 +19,7 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> { args.extend(ssh_arguments.split_whitespace()); } - let env = format!("TOPGRADE_PREFIX={}", hostname); + let env = format!("TOPGRADE_PREFIX={hostname}"); args.extend(["env", &env, "$SHELL", "-lc", topgrade]); if ctx.config().run_in_tmux() && !ctx.run_type().dry() { @@ -43,11 +43,11 @@ pub fn ssh_step(ctx: &ExecutionContext, hostname: &str) -> Result<()> { args.extend(ssh_arguments.split_whitespace()); } - let env = format!("TOPGRADE_PREFIX={}", hostname); + let env = format!("TOPGRADE_PREFIX={hostname}"); args.extend(["env", &env, "$SHELL", "-lc", topgrade]); - print_separator(format!("Remote ({})", hostname)); - println!("Connecting to {}...", hostname); + print_separator(format!("Remote ({hostname})")); + println!("Connecting to {hostname}..."); ctx.run_type().execute(ssh).args(&args).status_checked() } diff --git a/src/steps/remote/vagrant.rs b/src/steps/remote/vagrant.rs index b7fbfb18..dc022797 100644 --- a/src/steps/remote/vagrant.rs +++ b/src/steps/remote/vagrant.rs @@ -183,7 +183,7 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) -> let mut _poweron = None; if !vagrant_box.initial_status.powered_on() { if !(ctx.config().vagrant_power_on().unwrap_or(true)) { - return Err(SkipStep(format!("Skipping powered off box {}", vagrant_box)).into()); + return Err(SkipStep(format!("Skipping powered off box {vagrant_box}")).into()); } else { print_separator(seperator); _poweron = Some(vagrant.temporary_power_on(vagrant_box, ctx)?); diff --git a/src/steps/toolbx.rs b/src/steps/toolbx.rs index 1c8a7583..8525efb8 100644 --- a/src/steps/toolbx.rs +++ b/src/steps/toolbx.rs @@ -42,7 +42,7 @@ pub fn run_toolbx(ctx: &ExecutionContext) -> Result<()> { let topgrade_path = topgrade_path.to_str().unwrap(); for tb in toolboxes.iter() { - let topgrade_prefix = format!("TOPGRADE_PREFIX='Toolbx {}'", tb); + let topgrade_prefix = format!("TOPGRADE_PREFIX='Toolbx {tb}'"); let mut args = vec![ "run", "-c", diff --git a/src/terminal.rs b/src/terminal.rs index 92a57d13..ab2ba3b1 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -60,7 +60,7 @@ impl Terminal { width: term.size_checked().map(|(_, w)| w), term, prefix: env::var("TOPGRADE_PREFIX") - .map(|prefix| format!("({}) ", prefix)) + .map(|prefix| format!("({prefix}) ")) .unwrap_or_else(|_| String::new()), set_title: true, display_time: true, @@ -159,7 +159,7 @@ impl Terminal { .ok(); } None => { - self.term.write_fmt(format_args!("―― {} ――\n", message)).ok(); + self.term.write_fmt(format_args!("―― {message} ――\n")).ok(); } } } @@ -171,7 +171,7 @@ impl Terminal { self.term .write_fmt(format_args!( "{} {}", - style(format!("{} failed:", key)).red().bold(), + style(format!("{key} failed:")).red().bold(), message )) .ok(); @@ -215,7 +215,7 @@ impl Terminal { self.term .write_fmt(format_args!( "{}", - style(format!("{} (y)es/(N)o", question,)).yellow().bold() + style(format!("{question} (y)es/(N)o",)).yellow().bold() )) .ok(); @@ -238,14 +238,14 @@ impl Terminal { } if self.desktop_notification { - self.notify_desktop(format!("{} failed", step_name), None); + self.notify_desktop(format!("{step_name} failed"), None); } let prompt_inner = style(format!("{}Retry? (y)es/(N)o/(s)hell/(q)uit", self.prefix)) .yellow() .bold(); - self.term.write_fmt(format_args!("\n{}", prompt_inner)).ok(); + self.term.write_fmt(format_args!("\n{prompt_inner}")).ok(); let answer = loop { match self.term.read_key() { @@ -253,7 +253,7 @@ impl Terminal { Ok(Key::Char('s')) | Ok(Key::Char('S')) => { println!("\n\nDropping you to shell. Fix what you need and then exit the shell.\n"); if let Err(err) = run_shell().context("Failed to run shell") { - self.term.write_fmt(format_args!("{err:?}\n{}", prompt_inner)).ok(); + self.term.write_fmt(format_args!("{err:?}\n{prompt_inner}")).ok(); } else { break Ok(true); } diff --git a/src/utils.rs b/src/utils.rs index 486bab1f..23ec64ca 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -149,6 +149,6 @@ pub fn hostname() -> Result { Command::new("hostname") .output_checked_utf8() - .map_err(|err| SkipStep(format!("Failed to get hostname: {}", err)).into()) + .map_err(|err| SkipStep(format!("Failed to get hostname: {err}")).into()) .map(|output| output.stdout.trim().to_owned()) }