2019-06-05 11:44:28 +03:00
|
|
|
#![allow(clippy::cognitive_complexity)]
|
2018-06-28 12:16:54 +03:00
|
|
|
mod config;
|
2018-10-17 14:07:58 +03:00
|
|
|
mod ctrlc;
|
2018-12-11 16:43:26 +02:00
|
|
|
mod error;
|
2018-08-26 16:12:59 +03:00
|
|
|
mod executor;
|
2018-06-03 18:04:58 +03:00
|
|
|
mod report;
|
2018-11-26 14:27:19 +02:00
|
|
|
#[cfg(feature = "self-update")]
|
|
|
|
|
mod self_update;
|
2018-12-15 21:52:21 +02:00
|
|
|
mod steps;
|
2018-05-31 16:00:01 +03:00
|
|
|
mod terminal;
|
2018-06-17 11:43:25 +03:00
|
|
|
mod utils;
|
2018-05-30 07:53:19 +03:00
|
|
|
|
2019-11-04 22:55:06 +02:00
|
|
|
use self::config::{CommandLineArgs, Config, Step};
|
2019-12-11 23:05:38 +02:00
|
|
|
#[cfg(all(windows, feature = "self-update"))]
|
|
|
|
|
use self::error::Upgraded;
|
|
|
|
|
use self::error::{SkipStep, StepFailed};
|
2018-08-24 21:52:17 +03:00
|
|
|
use self::report::Report;
|
2018-12-15 21:52:21 +02:00
|
|
|
use self::steps::*;
|
2018-12-09 10:30:41 +02:00
|
|
|
use self::terminal::*;
|
2019-12-11 23:05:38 +02:00
|
|
|
use anyhow::{anyhow, Result};
|
2019-08-22 22:08:28 +03:00
|
|
|
use log::debug;
|
2019-06-02 10:02:13 +03:00
|
|
|
#[cfg(feature = "self-update")]
|
|
|
|
|
use openssl_probe;
|
2018-08-25 22:19:38 +03:00
|
|
|
use std::borrow::Cow;
|
2018-06-20 21:05:49 +03:00
|
|
|
use std::env;
|
2019-01-13 23:20:32 +02:00
|
|
|
use std::fmt::Debug;
|
2018-12-11 16:43:26 +02:00
|
|
|
use std::io;
|
2018-06-17 11:43:25 +03:00
|
|
|
use std::process::exit;
|
2019-11-04 22:55:06 +02:00
|
|
|
use structopt::StructOpt;
|
2018-05-29 23:48:30 +03:00
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
fn execute<'a, F, M>(report: &mut Report<'a>, key: M, func: F, no_retry: bool) -> Result<()>
|
2019-01-13 23:20:32 +02:00
|
|
|
where
|
2019-12-11 23:05:38 +02:00
|
|
|
F: Fn() -> Result<()>,
|
2019-01-13 23:20:32 +02:00
|
|
|
M: Into<Cow<'a, str>> + Debug,
|
|
|
|
|
{
|
2020-01-03 10:26:21 +02:00
|
|
|
let key = key.into();
|
2019-08-15 09:23:22 +03:00
|
|
|
debug!("Step {:?}", key);
|
2019-01-13 23:20:32 +02:00
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
match func() {
|
|
|
|
|
Ok(()) => {
|
|
|
|
|
report.push_result(Some((key, true)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-12-11 23:05:38 +02:00
|
|
|
Err(e) if e.downcast_ref::<SkipStep>().is_some() => {
|
2019-01-13 23:20:32 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
let interrupted = ctrlc::interrupted();
|
|
|
|
|
if interrupted {
|
|
|
|
|
ctrlc::unset_interrupted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let should_ask = interrupted || !no_retry;
|
2020-01-03 10:26:21 +02:00
|
|
|
let should_retry = should_ask && should_retry(interrupted, key.as_ref())?;
|
2019-01-13 23:20:32 +02:00
|
|
|
|
|
|
|
|
if !should_retry {
|
|
|
|
|
report.push_result(Some((key, false)));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
fn run() -> Result<()> {
|
2018-10-17 14:07:58 +03:00
|
|
|
ctrlc::set_handler();
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
let base_dirs = directories::BaseDirs::new().ok_or_else(|| anyhow!("No base directories"))?;
|
2018-09-06 14:42:56 +03:00
|
|
|
|
2019-11-04 22:55:06 +02:00
|
|
|
let opt = CommandLineArgs::from_args();
|
|
|
|
|
if opt.edit_config() {
|
2019-08-22 22:29:31 +03:00
|
|
|
Config::edit(&base_dirs)?;
|
|
|
|
|
return Ok(());
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-04 22:55:06 +02:00
|
|
|
let config = Config::load(&base_dirs, opt)?;
|
|
|
|
|
terminal::set_title(config.set_title());
|
|
|
|
|
|
2019-06-13 09:21:39 +03:00
|
|
|
if config.run_in_tmux() && env::var("TOPGRADE_INSIDE_TMUX").is_err() {
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
2019-11-06 07:27:01 +02:00
|
|
|
tmux::run_in_tmux(config.tmux_arguments());
|
2018-06-20 21:05:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 21:52:21 +02:00
|
|
|
let git = git::Git::new();
|
|
|
|
|
let mut git_repos = git::Repositories::new(&git);
|
2018-11-07 14:31:44 +02:00
|
|
|
|
2018-08-24 21:52:17 +03:00
|
|
|
let mut report = Report::new();
|
2018-05-30 07:53:19 +03:00
|
|
|
|
2019-12-12 20:24:22 +02:00
|
|
|
#[cfg(unix)]
|
2019-08-20 14:02:13 +02:00
|
|
|
let sudo = utils::sudo();
|
2019-01-22 22:37:32 +02:00
|
|
|
let run_type = executor::RunType::new(config.dry_run());
|
2018-06-11 08:29:40 +03:00
|
|
|
|
2018-11-12 21:27:49 +02:00
|
|
|
#[cfg(feature = "self-update")]
|
|
|
|
|
{
|
2019-06-02 10:02:13 +03:00
|
|
|
openssl_probe::init_ssl_cert_env_vars();
|
2018-12-31 14:05:15 +02:00
|
|
|
if !run_type.dry() && env::var("TOPGRADE_NO_SELF_UPGRADE").is_err() {
|
2019-06-03 09:41:25 +03:00
|
|
|
let result = self_update::self_update();
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
if let Err(e) = &result {
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
{
|
|
|
|
|
if e.downcast_ref::<Upgraded>().is_some() {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-06-03 09:41:25 +03:00
|
|
|
}
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning(format!("Self update error: {}", e));
|
2018-11-12 21:27:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-07 14:31:44 +02:00
|
|
|
|
2018-06-20 20:26:08 +03:00
|
|
|
if let Some(commands) = config.pre_commands() {
|
|
|
|
|
for (name, command) in commands {
|
2019-12-11 23:05:38 +02:00
|
|
|
generic::run_custom_command(&name, &command, run_type)?;
|
2018-06-20 20:26:08 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 21:36:57 +03:00
|
|
|
let powershell = powershell::Powershell::new();
|
2019-09-05 20:43:18 +03:00
|
|
|
let should_run_powershell = powershell.profile().is_some() && config.should_run(Step::Shell);
|
2019-02-27 09:47:20 +02:00
|
|
|
|
2019-06-04 09:35:29 +03:00
|
|
|
#[cfg(windows)]
|
|
|
|
|
execute(&mut report, "WSL", || windows::run_wsl_topgrade(run_type), true)?;
|
|
|
|
|
|
2019-06-05 14:15:45 +03:00
|
|
|
if let Some(topgrades) = config.remote_topgrades() {
|
2019-07-01 08:53:53 +03:00
|
|
|
if config.should_run(Step::Remotes) {
|
|
|
|
|
for remote_topgrade in topgrades {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
remote_topgrade,
|
2019-09-01 20:45:44 +02:00
|
|
|
|| {
|
|
|
|
|
generic::run_remote_topgrade(
|
|
|
|
|
run_type,
|
|
|
|
|
remote_topgrade,
|
|
|
|
|
config.ssh_arguments(),
|
|
|
|
|
config.run_in_tmux(),
|
2019-11-06 07:27:01 +02:00
|
|
|
config.tmux_arguments(),
|
2019-09-01 20:45:44 +02:00
|
|
|
)
|
|
|
|
|
},
|
2019-07-01 08:53:53 +03:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2019-06-05 14:15:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 10:46:38 +03:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
let distribution = linux::Distribution::detect();
|
|
|
|
|
|
2018-08-22 22:18:48 +03:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::System) {
|
2018-10-02 11:36:10 +03:00
|
|
|
match &distribution {
|
2018-10-02 10:46:38 +03:00
|
|
|
Ok(distribution) => {
|
2019-02-11 14:10:06 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"System update",
|
2019-10-03 08:12:43 +03:00
|
|
|
|| distribution.upgrade(&sudo, run_type, &config),
|
2019-01-22 22:37:32 +02:00
|
|
|
config.no_retry(),
|
2019-02-11 14:10:06 +02:00
|
|
|
)?;
|
2018-10-02 10:46:38 +03:00
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
println!("Error detecting current distribution: {}", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-25 15:10:28 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"etc-update",
|
|
|
|
|
|| linux::run_etc_update(sudo.as_ref(), run_type),
|
2019-01-13 23:20:32 +02:00
|
|
|
config.no_retry(),
|
2019-02-25 15:10:28 +02:00
|
|
|
)?;
|
2018-08-22 22:18:48 +03:00
|
|
|
}
|
2018-06-28 07:47:51 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-22 22:18:48 +03:00
|
|
|
#[cfg(windows)]
|
2019-09-28 14:49:24 +03:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::PackageManagers) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Chocolatey",
|
|
|
|
|
|| windows::run_chocolatey(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2018-08-22 22:18:48 +03:00
|
|
|
|
2019-09-28 14:49:24 +03:00
|
|
|
execute(&mut report, "Scoop", || windows::run_scoop(run_type), config.no_retry())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-17 13:57:30 +03:00
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[cfg(unix)]
|
2019-09-28 14:49:24 +03:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::PackageManagers) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"brew",
|
|
|
|
|
|| unix::run_homebrew(config.cleanup(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
|
2019-11-04 23:04:35 +02:00
|
|
|
execute(&mut report, "nix", || unix::run_nix(run_type), config.no_retry())?;
|
2019-11-11 22:16:40 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"home-manager",
|
|
|
|
|
|| unix::run_home_manager(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2019-11-04 23:04:35 +02:00
|
|
|
}
|
2019-09-28 14:49:24 +03:00
|
|
|
}
|
|
|
|
|
|
2019-06-25 22:47:36 -07:00
|
|
|
#[cfg(target_os = "dragonfly")]
|
2019-09-28 14:49:24 +03:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::PackageManagers) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"DragonFly BSD Packages",
|
|
|
|
|
|| dragonfly::upgrade_packages(sudo.as_ref(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 11:13:43 +02:00
|
|
|
#[cfg(target_os = "freebsd")]
|
2019-09-28 14:49:24 +03:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::PackageManagers) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"FreeBSD Packages",
|
|
|
|
|
|| freebsd::upgrade_packages(sudo.as_ref(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-03-12 08:54:19 +02:00
|
|
|
let emacs = emacs::Emacs::new(&base_dirs);
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::Emacs) {
|
2019-03-12 08:54:19 +02:00
|
|
|
if let Some(directory) = emacs.directory() {
|
|
|
|
|
git_repos.insert(directory);
|
2019-01-27 20:04:46 +02:00
|
|
|
}
|
2019-12-26 22:30:09 +02:00
|
|
|
git_repos.insert(base_dirs.home_dir().join(".doom.d"));
|
2018-09-05 11:17:15 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::Vim) {
|
2018-12-09 16:58:13 +09:00
|
|
|
git_repos.insert(base_dirs.home_dir().join(".vim"));
|
|
|
|
|
git_repos.insert(base_dirs.home_dir().join(".config/nvim"));
|
|
|
|
|
}
|
2018-05-30 07:53:19 +03:00
|
|
|
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
2019-10-01 20:50:44 +03:00
|
|
|
git_repos.insert(zsh::zshrc(&base_dirs));
|
2018-07-07 02:18:19 +03:00
|
|
|
git_repos.insert(base_dirs.home_dir().join(".tmux"));
|
|
|
|
|
git_repos.insert(base_dirs.home_dir().join(".config/fish"));
|
2018-08-27 15:22:44 +03:00
|
|
|
git_repos.insert(base_dirs.config_dir().join("openbox"));
|
2019-02-26 16:05:10 +02:00
|
|
|
git_repos.insert(base_dirs.config_dir().join("bspwm"));
|
2019-03-14 21:38:24 +02:00
|
|
|
git_repos.insert(base_dirs.config_dir().join("i3"));
|
2019-12-19 13:46:16 +01:00
|
|
|
git_repos.insert(base_dirs.config_dir().join("sway"));
|
2018-06-08 18:19:07 +03:00
|
|
|
}
|
2018-05-30 07:53:19 +03:00
|
|
|
|
2019-11-27 22:23:44 +02:00
|
|
|
#[cfg(windows)]
|
|
|
|
|
git_repos.insert(
|
|
|
|
|
base_dirs
|
|
|
|
|
.data_local_dir()
|
|
|
|
|
.join("Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState"),
|
|
|
|
|
);
|
|
|
|
|
|
2019-08-14 21:36:57 +03:00
|
|
|
if let Some(profile) = powershell.profile() {
|
|
|
|
|
git_repos.insert(profile);
|
2018-08-23 22:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::GitRepos) {
|
2018-09-03 11:51:09 -04:00
|
|
|
if let Some(custom_git_repos) = config.git_repos() {
|
|
|
|
|
for git_repo in custom_git_repos {
|
2019-08-11 12:41:09 +03:00
|
|
|
git_repos.glob_insert(git_repo);
|
2018-09-03 11:51:09 -04:00
|
|
|
}
|
2018-05-30 07:53:19 +03:00
|
|
|
}
|
2019-07-01 09:20:48 +03:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Git repositories",
|
2019-09-04 21:31:23 +03:00
|
|
|
|| git.multi_pull(&git_repos, run_type, config.git_arguments()),
|
2019-07-01 09:20:48 +03:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2018-05-30 07:53:19 +03:00
|
|
|
}
|
2018-05-31 15:59:45 +03:00
|
|
|
|
2019-08-14 21:36:57 +03:00
|
|
|
if should_run_powershell {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Powershell Modules Update",
|
|
|
|
|
|| powershell.update_modules(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2019-03-11 10:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
2019-09-05 13:38:45 -04:00
|
|
|
if config.should_run(Step::Shell) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"zr",
|
2019-10-01 20:50:44 +03:00
|
|
|
|| zsh::run_zr(&base_dirs, run_type),
|
2019-09-05 13:38:45 -04:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
2019-10-01 10:27:11 -07:00
|
|
|
&mut report,
|
|
|
|
|
"antigen",
|
2019-10-01 20:50:44 +03:00
|
|
|
|| zsh::run_antigen(&base_dirs, run_type),
|
2019-10-01 10:27:11 -07:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
2019-09-05 13:38:45 -04:00
|
|
|
&mut report,
|
|
|
|
|
"zplug",
|
2019-10-01 20:50:44 +03:00
|
|
|
|| zsh::run_zplug(&base_dirs, run_type),
|
2019-09-05 13:38:45 -04:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2019-12-01 06:40:23 +00:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"zplugin",
|
|
|
|
|
|| zsh::run_zplugin(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2019-09-05 13:38:45 -04:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"oh-my-zsh",
|
2019-10-01 20:50:44 +03:00
|
|
|
|| zsh::run_oh_my_zsh(&base_dirs, run_type),
|
2019-09-05 13:38:45 -04:00
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"fisher",
|
|
|
|
|
|| unix::run_fisher(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"tmux",
|
|
|
|
|
|| tmux::run_tpm(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2020-01-05 22:56:18 +02:00
|
|
|
|
|
|
|
|
if config.should_run(Step::Tldr) {
|
|
|
|
|
execute(&mut report, "TLDR", || unix::run_tldr(run_type), config.no_retry())?;
|
|
|
|
|
}
|
2018-05-31 16:17:22 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-19 20:15:01 +03:00
|
|
|
if config.should_run(Step::Rustup) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"rustup",
|
|
|
|
|
|| generic::run_rustup(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Cargo) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"cargo",
|
|
|
|
|
|| generic::run_cargo_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2018-09-05 11:17:15 +03:00
|
|
|
|
2019-11-20 13:35:41 +02:00
|
|
|
if config.should_run(Step::Flutter) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Flutter",
|
|
|
|
|
|| generic::run_flutter_upgrade(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-20 14:41:05 +02:00
|
|
|
if config.should_run(Step::Go) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Go",
|
|
|
|
|
|| generic::run_go(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::Emacs) {
|
2019-03-12 08:54:19 +02:00
|
|
|
execute(&mut report, "Emacs", || emacs.upgrade(run_type), config.no_retry())?;
|
2018-09-05 11:17:15 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-04 23:04:35 +02:00
|
|
|
if config.should_run(Step::Opam) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"opam",
|
|
|
|
|
|| generic::run_opam_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Vcpkg) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"vcpkg",
|
|
|
|
|
|| generic::run_vcpkg_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Pipx) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"pipx",
|
|
|
|
|
|| generic::run_pipx_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Stack) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"stack",
|
|
|
|
|
|| generic::run_stack_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 20:24:22 +02:00
|
|
|
if config.should_run(Step::Tlmgr) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"tlmgr",
|
|
|
|
|
|| {
|
|
|
|
|
generic::run_tlmgr_update(
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
&sudo,
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
|
&None,
|
|
|
|
|
run_type,
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 23:04:35 +02:00
|
|
|
if config.should_run(Step::Myrepos) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"myrepos",
|
|
|
|
|
|| generic::run_myrepos_update(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 08:47:01 +02:00
|
|
|
#[cfg(unix)]
|
2019-11-04 23:04:35 +02:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::Pearl) {
|
|
|
|
|
execute(&mut report, "pearl", || unix::run_pearl(run_type), config.no_retry())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Jetpack) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"jetpak",
|
|
|
|
|
|| generic::run_jetpack(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2019-01-22 22:37:32 +02:00
|
|
|
|
|
|
|
|
if config.should_run(Step::Vim) {
|
2019-03-10 21:48:49 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"vim",
|
2019-11-20 13:34:12 +02:00
|
|
|
|| vim::upgrade_vim(&base_dirs, run_type, config.cleanup()),
|
2019-01-13 23:20:32 +02:00
|
|
|
config.no_retry(),
|
2019-03-10 21:48:49 +02:00
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Neovim",
|
2019-11-20 13:34:12 +02:00
|
|
|
|| vim::upgrade_neovim(&base_dirs, run_type, config.cleanup()),
|
2019-01-22 22:37:32 +02:00
|
|
|
config.no_retry(),
|
2019-03-10 21:48:49 +02:00
|
|
|
)?;
|
2019-10-05 10:19:07 -07:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"voom",
|
|
|
|
|
|| vim::run_voom(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2018-12-09 16:58:13 +09:00
|
|
|
}
|
|
|
|
|
|
2019-09-04 12:57:22 +02:00
|
|
|
if config.should_run(Step::Node) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"NPM",
|
|
|
|
|
|| node::run_npm_upgrade(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"composer",
|
|
|
|
|
|| generic::run_composer_update(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"yarn",
|
|
|
|
|
|| node::yarn_global_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2018-10-04 11:26:51 +03:00
|
|
|
|
2018-10-29 14:32:33 +02:00
|
|
|
#[cfg(not(any(
|
|
|
|
|
target_os = "freebsd",
|
|
|
|
|
target_os = "openbsd",
|
|
|
|
|
target_os = "netbsd",
|
|
|
|
|
target_os = "dragonfly"
|
|
|
|
|
)))]
|
2019-11-04 23:04:35 +02:00
|
|
|
{
|
|
|
|
|
if config.should_run(Step::Atom) {
|
|
|
|
|
execute(&mut report, "apm", || generic::run_apm(run_type), config.no_retry())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-13 14:10:23 +00:00
|
|
|
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::Gem) {
|
2019-01-13 23:20:32 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"gem",
|
|
|
|
|
|| generic::run_gem(&base_dirs, run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2019-01-13 14:10:23 +00:00
|
|
|
}
|
2018-06-06 11:27:43 +03:00
|
|
|
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
2019-09-28 14:49:24 +03:00
|
|
|
if config.should_run(Step::PackageManagers) {
|
2019-09-05 02:32:30 -04:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Flatpak",
|
|
|
|
|
|| linux::flatpak_update(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"snap",
|
|
|
|
|
|| linux::run_snap(sudo.as_ref(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2018-06-14 13:24:52 +03:00
|
|
|
}
|
|
|
|
|
|
2018-06-11 08:38:29 +03:00
|
|
|
if let Some(commands) = config.commands() {
|
|
|
|
|
for (name, command) in commands {
|
2019-03-10 22:01:01 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
name,
|
|
|
|
|
|| generic::run_custom_command(&name, &command, run_type),
|
2019-01-22 22:37:32 +02:00
|
|
|
config.no_retry(),
|
2019-03-10 22:01:01 +02:00
|
|
|
)?;
|
2018-06-11 08:38:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
2019-11-04 23:04:35 +02:00
|
|
|
if config.should_run(Step::System) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"pihole",
|
|
|
|
|
|| linux::run_pihole_update(sudo.as_ref(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Firmware) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Firmware upgrades",
|
|
|
|
|
|| linux::run_fwupdmgr(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.should_run(Step::Restarts) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Restarts",
|
|
|
|
|
|| linux::run_needrestart(sudo.as_ref(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
2018-05-31 09:19:27 +03:00
|
|
|
}
|
|
|
|
|
|
2018-06-27 23:04:39 +03:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::System) {
|
2020-01-28 16:22:17 +02:00
|
|
|
execute(&mut report, "App Store", || macos::run_mas(run_type), config.no_retry())?;
|
|
|
|
|
|
2019-03-10 21:48:49 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
2020-01-28 16:22:17 +02:00
|
|
|
"System upgrade",
|
2019-03-10 21:48:49 +02:00
|
|
|
|| macos::upgrade_macos(run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
2018-08-13 14:39:29 +03:00
|
|
|
}
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
2018-11-12 11:13:43 +02:00
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
|
{
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::System) {
|
2019-03-10 22:01:01 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"FreeBSD Upgrade",
|
2019-03-13 11:46:32 +02:00
|
|
|
|| freebsd::upgrade_freebsd(sudo.as_ref(), run_type),
|
2019-01-22 22:37:32 +02:00
|
|
|
config.no_retry(),
|
2019-03-10 22:01:01 +02:00
|
|
|
)?;
|
2018-11-12 11:13:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 22:18:48 +03:00
|
|
|
#[cfg(windows)]
|
|
|
|
|
{
|
2019-01-22 22:37:32 +02:00
|
|
|
if config.should_run(Step::System) {
|
2019-02-11 20:38:51 +02:00
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"Windows update",
|
2019-11-27 22:19:30 +02:00
|
|
|
|| powershell::Powershell::windows_powershell().windows_update(run_type),
|
2019-01-13 23:20:32 +02:00
|
|
|
config.no_retry(),
|
2019-02-11 20:38:51 +02:00
|
|
|
)?;
|
2018-08-22 22:18:48 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 12:19:47 +02:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
|
|
|
|
if config.should_run(Step::Sdkman) {
|
|
|
|
|
execute(
|
|
|
|
|
&mut report,
|
|
|
|
|
"SDKMAN!",
|
|
|
|
|
|| unix::run_sdkman(&base_dirs, config.cleanup(), run_type),
|
|
|
|
|
config.no_retry(),
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 21:52:17 +03:00
|
|
|
if !report.data().is_empty() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Summary");
|
2018-06-03 18:04:58 +03:00
|
|
|
|
2018-08-24 21:52:17 +03:00
|
|
|
for (key, succeeded) in report.data() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_result(key, *succeeded);
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
2018-10-02 11:36:10 +03:00
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
if let Ok(distribution) = &distribution {
|
|
|
|
|
distribution.show_summary();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-15 11:37:08 +02:00
|
|
|
|
|
|
|
|
#[cfg(target_os = "freebsd")]
|
2018-11-15 15:54:24 +02:00
|
|
|
freebsd::audit_packages(&sudo).ok();
|
2019-06-25 22:47:36 -07:00
|
|
|
|
|
|
|
|
#[cfg(target_os = "dragonfly")]
|
|
|
|
|
dragonfly::audit_packages(&sudo).ok();
|
2018-05-29 23:48:30 +03:00
|
|
|
}
|
|
|
|
|
|
2019-06-16 09:09:05 +03:00
|
|
|
if config.keep_at_end() {
|
2019-08-04 09:25:35 +03:00
|
|
|
print_info("\n(R)eboot\n(S)hell\n(Q)uit");
|
|
|
|
|
loop {
|
|
|
|
|
match get_char() {
|
|
|
|
|
's' | 'S' => {
|
|
|
|
|
run_shell();
|
|
|
|
|
}
|
|
|
|
|
'r' | 'R' => {
|
|
|
|
|
reboot();
|
|
|
|
|
}
|
|
|
|
|
'q' | 'Q' => (),
|
|
|
|
|
_ => {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-06-13 22:05:18 +03:00
|
|
|
}
|
2019-08-04 09:25:35 +03:00
|
|
|
break;
|
2019-06-13 22:05:18 +03:00
|
|
|
}
|
2019-06-13 09:21:39 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-24 21:52:17 +03:00
|
|
|
if report.data().iter().all(|(_, succeeded)| *succeeded) {
|
2018-06-11 08:57:55 +03:00
|
|
|
Ok(())
|
|
|
|
|
} else {
|
2019-12-11 23:05:38 +02:00
|
|
|
Err(StepFailed.into())
|
2018-06-11 08:57:55 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
match run() {
|
|
|
|
|
Ok(()) => {
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
Err(error) => {
|
2019-06-03 09:41:25 +03:00
|
|
|
#[cfg(all(windows, feature = "self-update"))]
|
|
|
|
|
{
|
2019-12-11 23:05:38 +02:00
|
|
|
if let Some(Upgraded(status)) = error.downcast_ref::<Upgraded>() {
|
2019-06-03 09:41:25 +03:00
|
|
|
exit(status.code().unwrap());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
let skip_print = (error.downcast_ref::<StepFailed>().is_some())
|
|
|
|
|
|| (error
|
|
|
|
|
.downcast_ref::<io::Error>()
|
2018-12-11 16:43:26 +02:00
|
|
|
.filter(|io_error| io_error.kind() == io::ErrorKind::Interrupted)
|
2019-12-11 23:05:38 +02:00
|
|
|
.is_some());
|
2018-12-11 16:43:26 +02:00
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
if !skip_print {
|
2018-12-11 16:43:26 +02:00
|
|
|
println!("Error: {}", error);
|
2018-10-17 14:07:58 +03:00
|
|
|
}
|
2018-06-11 08:57:55 +03:00
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-29 23:48:30 +03:00
|
|
|
}
|