From 4716cb7c943a039cf17887fccb4f5ca67c7f31b4 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Thu, 9 Dec 2021 15:16:42 +0200 Subject: [PATCH] Add Bedrock Linux support (fix #745) (#747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bedrock Linux (fix #745) * Add more distributions * fix * fix * Fix * Merge * Move pacnew to the correct location * Version bump * Correct spelling for GNOME Shell extensions update (#778) * fix gnome shell extensions update object path (#788) * config: ArchPackageManager should be snake_case (#784) * config: ArchPackageManager should be snake_case * Remove unnecessary strum macro * Add arch_package_manager to config.example.toml * Add release pipeline * Run GNOME update only when using GNOME * Delete travis file and appveyor * Bump * Support rust 1.51.0 (#789) * Cross compilation * Bump * fix: GNOME detection for customized version (#790) Signed-off-by: Noel Georgi * Add a flag to disable showing Arch Linux news (fix #786) * Bump * Update pacstall (fix #769) * Add an option to force vim plug update (#795) * Add an option to force vim plug update (fix #751) * Rustfmt * Update src/config.rs Co-authored-by: M*C*O Co-authored-by: M*C*O * Add new step pacdiff (#796) * Add Support for Spicetify (#798) * Look for ~/.config/emacs directory in Windows (fix #766) * Pass --force to doom when -y is set (fix #799) * Implement cleanup for flatpak (#801) * Cleanup flatpak * Fix compile error * Make sure we only move our values at the very end * Access config.cleanup() through ExecutionContext * Improve man page (#803) Wordings & argument format * Avoid running remote topgrade on the current host (fix #804) (#807) * Merge the command line and the configuration flags of --only and --disable (fix #805) (#806) * Merge the command line and the configuration flags of --only and --disable (fix #805) * Fix * Fix rust requirement in the readme * Selective yes (fix #802) (#808) * Selective yes flag (fix #802) * Selective yes flag (fix #802) * selective yes * MacOS * Fix bedrock detection * Bedrock fixes * format * Fedora fixes Co-authored-by: Björn Daase Co-authored-by: modularTaco <37046961+modularTaco@users.noreply.github.com> Co-authored-by: M*C*O Co-authored-by: Noel Georgi Co-authored-by: Manuel Hässig Co-authored-by: Janek <27jf@pm.me> --- src/steps/os/archlinux.rs | 4 +- src/steps/os/linux.rs | 91 +++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/steps/os/archlinux.rs b/src/steps/os/archlinux.rs index cee133aa..7c339956 100644 --- a/src/steps/os/archlinux.rs +++ b/src/steps/os/archlinux.rs @@ -141,7 +141,7 @@ impl ArchPackageManager for Pacman { impl Pacman { pub fn get(ctx: &ExecutionContext) -> Option { Some(Self { - executable: which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman")), + executable: which("powerpill").unwrap_or_else(|| PathBuf::from("pacman")), sudo: ctx.sudo().to_owned()?, }) } @@ -152,7 +152,7 @@ fn box_pacakge_manager(package_manager: P) -> B } pub fn get_arch_package_manager(ctx: &ExecutionContext) -> Option> { - let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman")); + let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("pacman")); match ctx.config().arch_package_manager() { config::ArchPackageManager::Autodetect => YayParu::get("paru", &pacman) diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 8784ff85..ad1bbff7 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -7,7 +7,7 @@ use crate::utils::{require, require_option, which, PathExt}; use crate::Step; use anyhow::Result; use ini::Ini; -use log::debug; +use log::{debug, warn}; use serde::Deserialize; use std::path::{Path, PathBuf}; use std::process::Command; @@ -26,6 +26,7 @@ struct OsRelease { pub enum Distribution { Alpine, Arch, + Bedrock, CentOS, ClearLinux, Fedora, @@ -80,6 +81,10 @@ impl Distribution { } pub fn detect() -> Result { + if PathBuf::from("/bedrock").exists() { + return Ok(Distribution::Bedrock); + } + if PathBuf::from(OS_RELEASE_PATH).exists() { let os_release = Ini::load_from_file(OS_RELEASE_PATH)?; @@ -105,6 +110,7 @@ impl Distribution { Distribution::Exherbo => upgrade_exherbo(ctx), Distribution::NixOS => upgrade_nixos(ctx), Distribution::KDENeon => upgrade_neon(ctx), + Distribution::Bedrock => update_bedrock(ctx), } } @@ -119,6 +125,31 @@ impl Distribution { } } +fn update_bedrock(ctx: &ExecutionContext) -> Result<()> { + let sudo = require_option(ctx.sudo().as_ref(), String::from("Sudo required"))?; + + ctx.run_type().execute(sudo).args(&["brl", "update"]); + + let output = Command::new("brl").arg("list").output()?; + debug!("brl list: {:?} {:?}", output.stdout, output.stderr); + + let parsed_output = String::from_utf8(output.stdout).unwrap(); + for distribution in parsed_output.trim().split('\n') { + debug!("Bedrock distribution {}", distribution); + match distribution { + "arch" => archlinux::upgrade_arch_linux(ctx)?, + "debian" | "ubuntu" => upgrade_debian(ctx)?, + "centos" | "fedora" => upgrade_redhat(ctx)?, + "bedrock" => upgrade_bedrock_strata(ctx)?, + _ => { + warn!("Unknown distribution {}", distribution); + } + } + } + + Ok(()) +} + fn is_wsl() -> Result { let output = Command::new("uname").arg("-r").check_output()?; debug!("Uname output: {}", output); @@ -134,7 +165,7 @@ fn upgrade_alpine_linux(ctx: &ExecutionContext) -> Result<()> { } fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { - let _ = if let Some(ostree) = Path::new("/usr/bin/rpm-ostree").if_exists() { + let _ = if let Some(ostree) = Path::new("rpm-ostree").if_exists() { if ctx.config().rpm_ostree() { let mut command = ctx.run_type().execute(ostree); command.arg("upgrade"); @@ -149,11 +180,7 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { let mut command = ctx.run_type().execute(&sudo); command - .arg( - Path::new("/usr/bin/dnf-3") - .if_exists() - .unwrap_or_else(|| Path::new("/usr/bin/yum")), - ) + .arg(which("dnf").unwrap_or_else(|| Path::new("yum").to_path_buf())) .arg(if ctx.config().redhat_distro_sync() { "distro-sync" } else { @@ -176,16 +203,23 @@ fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +fn upgrade_bedrock_strata(ctx: &ExecutionContext) -> Result<()> { + if let Some(sudo) = ctx.sudo() { + ctx.run_type().execute(&sudo).args(&["brl", "update"]).check_run()?; + } else { + print_warning("No sudo detected. Skipping system upgrade"); + } + + Ok(()) +} + fn upgrade_suse(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type() - .execute(&sudo) - .args(&["/usr/bin/zypper", "refresh"]) - .check_run()?; + ctx.run_type().execute(&sudo).args(&["zypper", "refresh"]).check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/zypper", "dist-upgrade"]) + .args(&["zypper", "dist-upgrade"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -198,12 +232,12 @@ fn upgrade_void(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/xbps-install", "-Su", "xbps"]) + .args(&["xbps-install", "-Su", "xbps"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/xbps-install", "-u"]) + .args(&["xbps-install", "-u"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); @@ -223,7 +257,7 @@ fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { println!("Syncing portage"); run_type .execute(&sudo) - .args(&["/usr/bin/emerge", "--sync"]) + .args(&["emerge", "--sync"]) .args( ctx.config() .emerge_sync_flags() @@ -238,7 +272,7 @@ fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { run_type .execute(&sudo) - .arg("/usr/bin/emerge") + .arg("emerge") .args( ctx.config() .emerge_update_flags() @@ -255,7 +289,7 @@ fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { - let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("/usr/bin/apt-get")); + let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("apt-get")); ctx.run_type().execute(&sudo).arg(&apt).arg("update").check_run()?; let mut command = ctx.run_type().execute(&sudo); @@ -287,10 +321,7 @@ fn upgrade_debian(ctx: &ExecutionContext) -> Result<()> { fn upgrade_solus(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type() - .execute(&sudo) - .args(&["/usr/bin/eopkg", "upgrade"]) - .check_run()?; + ctx.run_type().execute(&sudo).args(&["eopkg", "upgrade"]).check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); } @@ -314,10 +345,7 @@ pub fn run_pacstall(ctx: &ExecutionContext) -> Result<()> { fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = &ctx.sudo() { - ctx.run_type() - .execute(&sudo) - .args(&["/usr/bin/swupd", "update"]) - .check_run()?; + ctx.run_type().execute(&sudo).args(&["swupd", "update"]).check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade"); } @@ -327,31 +355,28 @@ fn upgrade_clearlinux(ctx: &ExecutionContext) -> Result<()> { fn upgrade_exherbo(ctx: &ExecutionContext) -> Result<()> { if let Some(sudo) = ctx.sudo() { - ctx.run_type() - .execute(&sudo) - .args(&["/usr/bin/cave", "sync"]) - .check_run()?; + ctx.run_type().execute(&sudo).args(&["cave", "sync"]).check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) + .args(&["cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"]) .check_run()?; if ctx.config().cleanup() { ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "purge", "-x"]) + .args(&["cave", "purge", "-x"]) .check_run()?; } ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"]) + .args(&["cave", "fix-linkage", "-x", "--", "-Cs"]) .check_run()?; ctx.run_type() .execute(&sudo) - .args(&["/usr/bin/eclectic", "config", "interactive"]) + .args(&["eclectic", "config", "interactive"]) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade");