Add OS specific modules
This commit is contained in:
@@ -46,12 +46,6 @@ cache:
|
|||||||
- C:\Users\appveyor\.cargo\registry
|
- C:\Users\appveyor\.cargo\registry
|
||||||
- target
|
- target
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
# Release tags
|
|
||||||
- /^v\d+\.\d+\.\d+.*$/
|
|
||||||
- master
|
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
- provider: Email
|
- provider: Email
|
||||||
on_build_success: false
|
on_build_success: false
|
||||||
|
|||||||
46
src/linux.rs
46
src/linux.rs
@@ -138,3 +138,49 @@ pub fn upgrade_debian(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run_needrestart(sudo: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&sudo)
|
||||||
|
.arg("needrestart")
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_fwupdmgr(fwupdmgr: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&fwupdmgr)
|
||||||
|
.arg("refresh")
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Command::new(&fwupdmgr)
|
||||||
|
.arg("get-updates")
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_flatpak(flatpak: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&flatpak)
|
||||||
|
.arg("update")
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_snap(sudo: &PathBuf, snap: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&sudo)
|
||||||
|
.args(&[snap.to_str().unwrap(), "refresh"])
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
13
src/macos.rs
Normal file
13
src/macos.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use super::utils::Check;
|
||||||
|
use failure;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub fn upgrade_macos() -> Result<(), failure::Error> {
|
||||||
|
Command::new("softwareupdate")
|
||||||
|
.args(&["--install", "--all"])
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
63
src/main.rs
63
src/main.rs
@@ -16,10 +16,17 @@ extern crate env_logger;
|
|||||||
extern crate term_size;
|
extern crate term_size;
|
||||||
extern crate termcolor;
|
extern crate termcolor;
|
||||||
|
|
||||||
mod config;
|
|
||||||
mod git;
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod linux;
|
mod linux;
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod macos;
|
||||||
|
#[cfg(unix)]
|
||||||
|
mod unix;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
mod windows;
|
||||||
|
|
||||||
|
mod config;
|
||||||
|
mod git;
|
||||||
mod npm;
|
mod npm;
|
||||||
mod report;
|
mod report;
|
||||||
mod steps;
|
mod steps;
|
||||||
@@ -34,13 +41,7 @@ use git::{Git, Repositories};
|
|||||||
use report::{Report, Reporter};
|
use report::{Report, Reporter};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::env::home_dir;
|
use std::env::home_dir;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::os::unix::process::CommandExt;
|
|
||||||
#[cfg(unix)]
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::process::Command;
|
|
||||||
use steps::*;
|
use steps::*;
|
||||||
use terminal::Terminal;
|
use terminal::Terminal;
|
||||||
use utils::{home_path, is_ancestor};
|
use utils::{home_path, is_ancestor};
|
||||||
@@ -49,17 +50,6 @@ use utils::{home_path, is_ancestor};
|
|||||||
#[fail(display = "A step failed")]
|
#[fail(display = "A step failed")]
|
||||||
struct StepFailed;
|
struct StepFailed;
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
fn tpm() -> Option<PathBuf> {
|
|
||||||
let mut path = home_dir().unwrap();
|
|
||||||
path.push(".tmux/plugins/tpm/bin/update_plugins");
|
|
||||||
if path.exists() {
|
|
||||||
Some(path)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run() -> Result<(), Error> {
|
fn run() -> Result<(), Error> {
|
||||||
let matches = App::new("Topgrade")
|
let matches = App::new("Topgrade")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
@@ -75,22 +65,7 @@ fn run() -> Result<(), Error> {
|
|||||||
if matches.is_present("tmux") && !env::var("TMUX").is_ok() {
|
if matches.is_present("tmux") && !env::var("TMUX").is_ok() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
let tmux = utils::which("tmux").expect("Could not find tmux");
|
unix::run_in_tmux();
|
||||||
let err = Command::new(tmux)
|
|
||||||
.args(&[
|
|
||||||
"new-session",
|
|
||||||
"-s",
|
|
||||||
"topgrade",
|
|
||||||
"-n",
|
|
||||||
"topgrade",
|
|
||||||
&env::args().collect::<Vec<String>>().join(" "),
|
|
||||||
";",
|
|
||||||
"set",
|
|
||||||
"remain-on-exit",
|
|
||||||
"on",
|
|
||||||
])
|
|
||||||
.exec();
|
|
||||||
panic!("{:?}", err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +116,7 @@ fn run() -> Result<(), Error> {
|
|||||||
{
|
{
|
||||||
if let Some(choco) = utils::which("choco") {
|
if let Some(choco) = utils::which("choco") {
|
||||||
terminal.print_separator("Chocolatey");
|
terminal.print_separator("Chocolatey");
|
||||||
run_chocolatey(&choco).report("Chocolatey", &mut reports);
|
windows::run_chocolatey(&choco).report("Chocolatey", &mut reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,13 +148,13 @@ fn run() -> Result<(), Error> {
|
|||||||
if let Some(zsh) = utils::which("zsh") {
|
if let Some(zsh) = utils::which("zsh") {
|
||||||
if home_path(".zplug").exists() {
|
if home_path(".zplug").exists() {
|
||||||
terminal.print_separator("zplug");
|
terminal.print_separator("zplug");
|
||||||
run_zplug(&zsh).report("zplug", &mut reports);
|
unix::run_zplug(&zsh).report("zplug", &mut reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tpm) = tpm() {
|
if let Some(tpm) = unix::tpm_path() {
|
||||||
terminal.print_separator("tmux plugins");
|
terminal.print_separator("tmux plugins");
|
||||||
run_tpm(&tpm).report("tmux", &mut reports);
|
unix::run_tpm(&tpm).report("tmux", &mut reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,13 +205,13 @@ fn run() -> Result<(), Error> {
|
|||||||
{
|
{
|
||||||
if let Some(flatpak) = utils::which("flatpak") {
|
if let Some(flatpak) = utils::which("flatpak") {
|
||||||
terminal.print_separator("Flatpak");
|
terminal.print_separator("Flatpak");
|
||||||
run_flatpak(&flatpak).report("Flatpak", &mut reports);
|
linux::run_flatpak(&flatpak).report("Flatpak", &mut reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
if let Some(snap) = utils::which("snap") {
|
if let Some(snap) = utils::which("snap") {
|
||||||
terminal.print_separator("snap");
|
terminal.print_separator("snap");
|
||||||
run_snap(&sudo, &snap).report("snap", &mut reports);
|
linux::run_snap(&sudo, &snap).report("snap", &mut reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,13 +227,13 @@ fn run() -> Result<(), Error> {
|
|||||||
{
|
{
|
||||||
if let Some(fwupdmgr) = utils::which("fwupdmgr") {
|
if let Some(fwupdmgr) = utils::which("fwupdmgr") {
|
||||||
terminal.print_separator("Firmware upgrades");
|
terminal.print_separator("Firmware upgrades");
|
||||||
run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
linux::run_fwupdmgr(&fwupdmgr).report("Firmware upgrade", &mut reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
if let Some(_) = utils::which("needrestart") {
|
if let Some(_) = utils::which("needrestart") {
|
||||||
terminal.print_separator("Check for needed restarts");
|
terminal.print_separator("Check for needed restarts");
|
||||||
run_needrestart(&sudo).report("Restarts", &mut reports);
|
linux::run_needrestart(&sudo).report("Restarts", &mut reports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +241,7 @@ fn run() -> Result<(), Error> {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
terminal.print_separator("App Store");
|
terminal.print_separator("App Store");
|
||||||
upgrade_macos().report("App Store", &mut reports);;
|
macos::upgrade_macos().report("App Store", &mut reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reports.is_empty() {
|
if !reports.is_empty() {
|
||||||
|
|||||||
90
src/steps.rs
90
src/steps.rs
@@ -7,24 +7,6 @@ use utils::is_ancestor;
|
|||||||
|
|
||||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn run_zplug(zsh: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(zsh)
|
|
||||||
.args(&["-c", "source ~/.zshrc && zplug update"])
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn run_tpm(tpm: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&tpm).arg("all").spawn()?.wait()?.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_cargo_update(cargo_update: &PathBuf) -> Result<(), failure::Error> {
|
pub fn run_cargo_update(cargo_update: &PathBuf) -> Result<(), failure::Error> {
|
||||||
Command::new(&cargo_update)
|
Command::new(&cargo_update)
|
||||||
.args(&["install-update", "--git", "--all"])
|
.args(&["install-update", "--git", "--all"])
|
||||||
@@ -88,34 +70,6 @@ pub fn run_apm(apm: &PathBuf) -> Result<(), failure::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub fn run_needrestart(sudo: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&sudo)
|
|
||||||
.arg("needrestart")
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub fn run_fwupdmgr(fwupdmgr: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&fwupdmgr)
|
|
||||||
.arg("refresh")
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Command::new(&fwupdmgr)
|
|
||||||
.arg("get-updates")
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> {
|
pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> {
|
||||||
if is_ancestor(&home_dir().unwrap(), &rustup) {
|
if is_ancestor(&home_dir().unwrap(), &rustup) {
|
||||||
Command::new(rustup)
|
Command::new(rustup)
|
||||||
@@ -130,28 +84,6 @@ pub fn run_rustup(rustup: &PathBuf) -> Result<(), failure::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
pub fn upgrade_macos() -> Result<(), failure::Error> {
|
|
||||||
Command::new("softwareupdate")
|
|
||||||
.args(&["--install", "--all"])
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub fn run_chocolatey(choco: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&choco)
|
|
||||||
.args(&["upgrade", "all"])
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_homebrew(homebrew: &PathBuf) -> Result<(), failure::Error> {
|
pub fn run_homebrew(homebrew: &PathBuf) -> Result<(), failure::Error> {
|
||||||
Command::new(&homebrew)
|
Command::new(&homebrew)
|
||||||
.arg("update")
|
.arg("update")
|
||||||
@@ -178,25 +110,3 @@ pub fn run_custom_command(command: &str) -> Result<(), failure::Error> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub fn run_flatpak(flatpak: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&flatpak)
|
|
||||||
.arg("update")
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub fn run_snap(sudo: &PathBuf, snap: &PathBuf) -> Result<(), failure::Error> {
|
|
||||||
Command::new(&sudo)
|
|
||||||
.args(&[snap.to_str().unwrap(), "refresh"])
|
|
||||||
.spawn()?
|
|
||||||
.wait()?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
53
src/unix.rs
Normal file
53
src/unix.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use super::utils;
|
||||||
|
use super::utils::Check;
|
||||||
|
use failure;
|
||||||
|
use std::env;
|
||||||
|
use std::env::home_dir;
|
||||||
|
use std::os::unix::process::CommandExt;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub fn run_zplug(zsh: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(zsh)
|
||||||
|
.args(&["-c", "source ~/.zshrc && zplug update"])
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_tpm(tpm: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&tpm).arg("all").spawn()?.wait()?.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tpm_path() -> Option<PathBuf> {
|
||||||
|
let mut path = home_dir().unwrap();
|
||||||
|
path.push(".tmux/plugins/tpm/bin/update_plugins");
|
||||||
|
if path.exists() {
|
||||||
|
Some(path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_in_tmux() -> ! {
|
||||||
|
let tmux = utils::which("tmux").expect("Could not find tmux");
|
||||||
|
let err = Command::new(tmux)
|
||||||
|
.args(&[
|
||||||
|
"new-session",
|
||||||
|
"-s",
|
||||||
|
"topgrade",
|
||||||
|
"-n",
|
||||||
|
"topgrade",
|
||||||
|
&env::args().collect::<Vec<String>>().join(" "),
|
||||||
|
";",
|
||||||
|
"set",
|
||||||
|
"remain-on-exit",
|
||||||
|
"on",
|
||||||
|
])
|
||||||
|
.exec();
|
||||||
|
panic!("{:?}", err);
|
||||||
|
}
|
||||||
14
src/windows.rs
Normal file
14
src/windows.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use super::utils::Check;
|
||||||
|
use failure;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub fn run_chocolatey(choco: &PathBuf) -> Result<(), failure::Error> {
|
||||||
|
Command::new(&choco)
|
||||||
|
.args(&["upgrade", "all"])
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user