Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add Bedrock Linux support (fix #745) (#747)
Browse files Browse the repository at this point in the history
* 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 <git@frezbo.dev>

* 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 <mcofficer@gmx.de>

Co-authored-by: M*C*O <mcofficer@gmx.de>

* 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 <bjoern.daase@gmail.com>
Co-authored-by: modularTaco <37046961+modularTaco@users.noreply.github.com>
Co-authored-by: M*C*O <mcofficer@gmx.de>
Co-authored-by: Noel Georgi <git@frezbo.dev>
Co-authored-by: Manuel Hässig <mhaessig@users.noreply.github.com>
Co-authored-by: Janek <27jf@pm.me>
  • Loading branch information
7 people authored Dec 9, 2021
1 parent ab3ff0e commit 4716cb7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/steps/os/archlinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl ArchPackageManager for Pacman {
impl Pacman {
pub fn get(ctx: &ExecutionContext) -> Option<Self> {
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()?,
})
}
Expand All @@ -152,7 +152,7 @@ fn box_pacakge_manager<P: 'static + ArchPackageManager>(package_manager: P) -> B
}

pub fn get_arch_package_manager(ctx: &ExecutionContext) -> Option<Box<dyn ArchPackageManager>> {
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)
Expand Down
91 changes: 58 additions & 33 deletions src/steps/os/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +26,7 @@ struct OsRelease {
pub enum Distribution {
Alpine,
Arch,
Bedrock,
CentOS,
ClearLinux,
Fedora,
Expand Down Expand Up @@ -80,6 +81,10 @@ impl Distribution {
}

pub fn detect() -> Result<Self> {
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)?;

Expand All @@ -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),
}
}

Expand All @@ -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<bool> {
let output = Command::new("uname").arg("-r").check_output()?;
debug!("Uname output: {}", output);
Expand All @@ -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");
Expand All @@ -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 {
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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);
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand All @@ -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");
Expand Down

0 comments on commit 4716cb7

Please sign in to comment.