Move the package manager step to the beginning (fixes #19)
This commit is contained in:
18
README.md
18
README.md
@@ -14,12 +14,17 @@ Other systems users can either use `cargo install` or use the compiled binaries
|
||||
## Usage
|
||||
Just invoke `topgrade`. It will invoke the following steps:
|
||||
|
||||
* Invoke the system package manager:
|
||||
* *Arch*: Invoke [yay](https://github.com/Jguer/yay) or fall back to pacman
|
||||
* *CentOS/RHEL*: Invoke `yum upgrade`
|
||||
* *Fedora* - Invoke `dnf upgrade`
|
||||
* *Debian/Ubuntu*: Invoke `apt update && apt dist-upgrade`
|
||||
* *macOS*: Invoke `brew update && brew upgrade`
|
||||
* Check if the following paths are tracked by Git. If so, pull them:
|
||||
* ~/.emacs.d (Should work whether you use [Spacemacs](http://spacemacs.org/) or a custom configuration)
|
||||
* ~/.zshrc
|
||||
* [~/.oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
|
||||
* ~/.tmux
|
||||
|
||||
* *Unix*: Invoke [zplug](https://github.com/zplug/zplug) update
|
||||
* *Unix*: Upgrade tmux plugins with [TPM](https://github.com/tmux-plugins/tpm)
|
||||
* Invoke Cargo [install-update](https://github.com/nabijaczleweli/cargo-update)
|
||||
@@ -30,12 +35,7 @@ Just invoke `topgrade`. It will invoke the following steps:
|
||||
* [Plug](https://github.com/junegunn/vim-plug)
|
||||
* Upgrade NPM globally installed packages
|
||||
* Upgrade Atom packages
|
||||
* *Linux*: Invoke the system package manager:
|
||||
* *Arch*: Invoke [yay](https://github.com/Jguer/yay) or fall back to pacman
|
||||
* *CentOS/RHEL*: Invoke `yum upgrade`
|
||||
* *Fedora* - Invoke `dnf upgrade`
|
||||
* *Debian/Ubuntu*: Invoke `apt update && apt dist-upgrade`
|
||||
* *Linux*: Invoke [fwupdmgr](https://github.com/hughsie/fwupd) to show firmware upgrade. (View only. No upgrades will actually be performed)
|
||||
* *Linux*: Run [needrestart](https://github.com/liske/needrestart)
|
||||
* *macOS*: Upgrade [Homebrew](https://brew.sh/) packages
|
||||
* *macOS*: Upgrade App Store applications
|
||||
* Final stage
|
||||
* *Linux*: Run [needrestart](https://github.com/liske/needrestart)
|
||||
* *macOS*: Upgrade App Store applications
|
||||
|
||||
64
src/main.rs
64
src/main.rs
@@ -84,6 +84,39 @@ fn main() -> Result<(), Error> {
|
||||
let mut reports = Report::new();
|
||||
let config = Config::read()?;
|
||||
|
||||
let sudo = if cfg!(target_os = "linux") {
|
||||
which("sudo").ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
terminal.print_separator("System update");
|
||||
match linux::Distribution::detect() {
|
||||
Ok(distribution) => {
|
||||
match distribution {
|
||||
linux::Distribution::Arch => upgrade_arch_linux(&sudo, &terminal),
|
||||
linux::Distribution::CentOS => upgrade_redhat(&sudo, &terminal),
|
||||
linux::Distribution::Fedora => upgrade_fedora(&sudo, &terminal),
|
||||
linux::Distribution::Ubuntu | linux::Distribution::Debian => {
|
||||
upgrade_debian(&sudo, &terminal)
|
||||
}
|
||||
}.report("System upgrade", &mut reports);
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
println!("Error detecting current distribution: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos") {
|
||||
if let Ok(brew) = which("brew") {
|
||||
terminal.print_separator("Homebrew");
|
||||
run_homebrew(&brew).report("Homebrew", &mut reports);
|
||||
}
|
||||
}
|
||||
|
||||
git_repos.insert(home_path(".emacs.d"));
|
||||
|
||||
if cfg!(unix) {
|
||||
@@ -163,32 +196,12 @@ fn main() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
let sudo = which("sudo");
|
||||
|
||||
terminal.print_separator("System update");
|
||||
match linux::Distribution::detect() {
|
||||
Ok(distribution) => {
|
||||
match distribution {
|
||||
linux::Distribution::Arch => upgrade_arch_linux(&sudo, &terminal),
|
||||
linux::Distribution::CentOS => upgrade_redhat(&sudo, &terminal),
|
||||
linux::Distribution::Fedora => upgrade_fedora(&sudo, &terminal),
|
||||
linux::Distribution::Ubuntu | linux::Distribution::Debian => {
|
||||
upgrade_debian(&sudo, &terminal)
|
||||
}
|
||||
}.report("System upgrade", &mut reports);
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
println!("Error detecting current distribution: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(fwupdmgr) = which("fwupdmgr") {
|
||||
terminal.print_separator("Firmware upgrades");
|
||||
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
||||
}
|
||||
|
||||
if let Ok(sudo) = &sudo {
|
||||
if let Some(sudo) = &sudo {
|
||||
if let Ok(_) = which("needrestart") {
|
||||
terminal.print_separator("Check for needed restarts");
|
||||
run_needrestart(&sudo).report("Restarts", &mut reports);
|
||||
@@ -197,13 +210,8 @@ fn main() -> Result<(), Error> {
|
||||
}
|
||||
|
||||
if cfg!(target_os = "macos") {
|
||||
if let Ok(brew) = which("brew") {
|
||||
terminal.print_separator("Homebrew");
|
||||
run_homebrew(&brew).report("Homebrew", &mut reports);
|
||||
}
|
||||
|
||||
terminal.print_separator("System update");
|
||||
upgrade_macos().report("System upgrade", &mut reports);;
|
||||
terminal.print_separator("App Store");
|
||||
upgrade_macos().report("App Store", &mut reports);;
|
||||
}
|
||||
|
||||
if let Some(commands) = config.commands() {
|
||||
|
||||
25
src/steps.rs
25
src/steps.rs
@@ -144,13 +144,13 @@ pub fn run_homebrew(homebrew: &PathBuf) -> Result<(), failure::Error> {
|
||||
}
|
||||
|
||||
pub fn upgrade_arch_linux(
|
||||
sudo: &Result<PathBuf, which::Error>,
|
||||
sudo: &Option<PathBuf>,
|
||||
terminal: &Terminal,
|
||||
) -> Result<(), failure::Error> {
|
||||
if let Ok(yay) = which("yay") {
|
||||
Command::new(yay).spawn()?.wait()?.check()?;
|
||||
} else {
|
||||
if let Ok(sudo) = &sudo {
|
||||
if let Some(sudo) = &sudo {
|
||||
Command::new(&sudo)
|
||||
.args(&["pacman", "-Syu"])
|
||||
.spawn()?
|
||||
@@ -164,11 +164,8 @@ pub fn upgrade_arch_linux(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn upgrade_redhat(
|
||||
sudo: &Result<PathBuf, which::Error>,
|
||||
terminal: &Terminal,
|
||||
) -> Result<(), failure::Error> {
|
||||
if let Ok(sudo) = &sudo {
|
||||
pub fn upgrade_redhat(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||
if let Some(sudo) = &sudo {
|
||||
Command::new(&sudo)
|
||||
.args(&["yum", "upgrade"])
|
||||
.spawn()?
|
||||
@@ -181,11 +178,8 @@ pub fn upgrade_redhat(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn upgrade_fedora(
|
||||
sudo: &Result<PathBuf, which::Error>,
|
||||
terminal: &Terminal,
|
||||
) -> Result<(), failure::Error> {
|
||||
if let Ok(sudo) = &sudo {
|
||||
pub fn upgrade_fedora(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||
if let Some(sudo) = &sudo {
|
||||
Command::new(&sudo)
|
||||
.args(&["dnf", "upgrade"])
|
||||
.spawn()?
|
||||
@@ -198,11 +192,8 @@ pub fn upgrade_fedora(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn upgrade_debian(
|
||||
sudo: &Result<PathBuf, which::Error>,
|
||||
terminal: &Terminal,
|
||||
) -> Result<(), failure::Error> {
|
||||
if let Ok(sudo) = &sudo {
|
||||
pub fn upgrade_debian(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||
if let Some(sudo) = &sudo {
|
||||
Command::new(&sudo)
|
||||
.args(&["apt", "update"])
|
||||
.spawn()?
|
||||
|
||||
Reference in New Issue
Block a user