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
|
## Usage
|
||||||
Just invoke `topgrade`. It will invoke the following steps:
|
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:
|
* 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)
|
* ~/.emacs.d (Should work whether you use [Spacemacs](http://spacemacs.org/) or a custom configuration)
|
||||||
* ~/.zshrc
|
* ~/.zshrc
|
||||||
* [~/.oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
|
* [~/.oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
|
||||||
* ~/.tmux
|
* ~/.tmux
|
||||||
|
|
||||||
* *Unix*: Invoke [zplug](https://github.com/zplug/zplug) update
|
* *Unix*: Invoke [zplug](https://github.com/zplug/zplug) update
|
||||||
* *Unix*: Upgrade tmux plugins with [TPM](https://github.com/tmux-plugins/tpm)
|
* *Unix*: Upgrade tmux plugins with [TPM](https://github.com/tmux-plugins/tpm)
|
||||||
* Invoke Cargo [install-update](https://github.com/nabijaczleweli/cargo-update)
|
* 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)
|
* [Plug](https://github.com/junegunn/vim-plug)
|
||||||
* Upgrade NPM globally installed packages
|
* Upgrade NPM globally installed packages
|
||||||
* Upgrade Atom 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*: 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)
|
* Final stage
|
||||||
* *macOS*: Upgrade [Homebrew](https://brew.sh/) packages
|
* *Linux*: Run [needrestart](https://github.com/liske/needrestart)
|
||||||
* *macOS*: Upgrade App Store applications
|
* *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 mut reports = Report::new();
|
||||||
let config = Config::read()?;
|
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"));
|
git_repos.insert(home_path(".emacs.d"));
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
@@ -163,32 +196,12 @@ fn main() -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(target_os = "linux") {
|
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") {
|
if let Ok(fwupdmgr) = which("fwupdmgr") {
|
||||||
terminal.print_separator("Firmware upgrades");
|
terminal.print_separator("Firmware upgrades");
|
||||||
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
if let Ok(_) = which("needrestart") {
|
if let Ok(_) = which("needrestart") {
|
||||||
terminal.print_separator("Check for needed restarts");
|
terminal.print_separator("Check for needed restarts");
|
||||||
run_needrestart(&sudo).report("Restarts", &mut reports);
|
run_needrestart(&sudo).report("Restarts", &mut reports);
|
||||||
@@ -197,13 +210,8 @@ fn main() -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
if let Ok(brew) = which("brew") {
|
terminal.print_separator("App Store");
|
||||||
terminal.print_separator("Homebrew");
|
upgrade_macos().report("App Store", &mut reports);;
|
||||||
run_homebrew(&brew).report("Homebrew", &mut reports);
|
|
||||||
}
|
|
||||||
|
|
||||||
terminal.print_separator("System update");
|
|
||||||
upgrade_macos().report("System upgrade", &mut reports);;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(commands) = config.commands() {
|
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(
|
pub fn upgrade_arch_linux(
|
||||||
sudo: &Result<PathBuf, which::Error>,
|
sudo: &Option<PathBuf>,
|
||||||
terminal: &Terminal,
|
terminal: &Terminal,
|
||||||
) -> Result<(), failure::Error> {
|
) -> Result<(), failure::Error> {
|
||||||
if let Ok(yay) = which("yay") {
|
if let Ok(yay) = which("yay") {
|
||||||
Command::new(yay).spawn()?.wait()?.check()?;
|
Command::new(yay).spawn()?.wait()?.check()?;
|
||||||
} else {
|
} else {
|
||||||
if let Ok(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
Command::new(&sudo)
|
Command::new(&sudo)
|
||||||
.args(&["pacman", "-Syu"])
|
.args(&["pacman", "-Syu"])
|
||||||
.spawn()?
|
.spawn()?
|
||||||
@@ -164,11 +164,8 @@ pub fn upgrade_arch_linux(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upgrade_redhat(
|
pub fn upgrade_redhat(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||||
sudo: &Result<PathBuf, which::Error>,
|
if let Some(sudo) = &sudo {
|
||||||
terminal: &Terminal,
|
|
||||||
) -> Result<(), failure::Error> {
|
|
||||||
if let Ok(sudo) = &sudo {
|
|
||||||
Command::new(&sudo)
|
Command::new(&sudo)
|
||||||
.args(&["yum", "upgrade"])
|
.args(&["yum", "upgrade"])
|
||||||
.spawn()?
|
.spawn()?
|
||||||
@@ -181,11 +178,8 @@ pub fn upgrade_redhat(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upgrade_fedora(
|
pub fn upgrade_fedora(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||||
sudo: &Result<PathBuf, which::Error>,
|
if let Some(sudo) = &sudo {
|
||||||
terminal: &Terminal,
|
|
||||||
) -> Result<(), failure::Error> {
|
|
||||||
if let Ok(sudo) = &sudo {
|
|
||||||
Command::new(&sudo)
|
Command::new(&sudo)
|
||||||
.args(&["dnf", "upgrade"])
|
.args(&["dnf", "upgrade"])
|
||||||
.spawn()?
|
.spawn()?
|
||||||
@@ -198,11 +192,8 @@ pub fn upgrade_fedora(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upgrade_debian(
|
pub fn upgrade_debian(sudo: &Option<PathBuf>, terminal: &Terminal) -> Result<(), failure::Error> {
|
||||||
sudo: &Result<PathBuf, which::Error>,
|
if let Some(sudo) = &sudo {
|
||||||
terminal: &Terminal,
|
|
||||||
) -> Result<(), failure::Error> {
|
|
||||||
if let Ok(sudo) = &sudo {
|
|
||||||
Command::new(&sudo)
|
Command::new(&sudo)
|
||||||
.args(&["apt", "update"])
|
.args(&["apt", "update"])
|
||||||
.spawn()?
|
.spawn()?
|
||||||
|
|||||||
Reference in New Issue
Block a user