2019-12-11 23:05:38 +02:00
|
|
|
use crate::error::SkipStep;
|
2020-02-27 22:06:14 +02:00
|
|
|
use crate::execution_context::ExecutionContext;
|
2019-01-01 22:22:07 +02:00
|
|
|
use crate::executor::{CommandExt, RunType};
|
2020-02-27 22:06:14 +02:00
|
|
|
use crate::powershell;
|
2019-08-14 21:36:57 +03:00
|
|
|
use crate::terminal::print_separator;
|
2020-07-10 11:21:19 +03:00
|
|
|
use crate::utils::require;
|
2019-12-11 23:05:38 +02:00
|
|
|
use anyhow::Result;
|
2018-06-28 12:16:54 +03:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
2020-06-30 11:55:39 +03:00
|
|
|
pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> {
|
2019-02-11 20:38:51 +02:00
|
|
|
let choco = require("choco")?;
|
2020-06-30 11:55:39 +03:00
|
|
|
let yes = ctx.config().yes();
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2019-02-11 20:38:51 +02:00
|
|
|
print_separator("Chocolatey");
|
2020-06-30 11:55:39 +03:00
|
|
|
|
2020-07-10 11:21:19 +03:00
|
|
|
let mut cmd = &choco;
|
2020-07-06 13:36:45 +02:00
|
|
|
let mut args = vec!["upgrade", "all"];
|
2020-06-30 11:55:39 +03:00
|
|
|
|
2020-07-10 11:21:19 +03:00
|
|
|
if let Some(sudo) = ctx.sudo() {
|
|
|
|
|
cmd = sudo;
|
|
|
|
|
args.insert(0, "choco");
|
2020-07-06 13:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut command = ctx.run_type().execute(&cmd);
|
|
|
|
|
|
|
|
|
|
command.args(&args);
|
2020-06-30 11:55:39 +03:00
|
|
|
|
|
|
|
|
if yes {
|
|
|
|
|
command.arg("--yes");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command.check_run()
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
2018-08-22 22:01:06 +03:00
|
|
|
|
2020-01-30 20:32:37 +02:00
|
|
|
pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> {
|
2019-02-11 20:38:51 +02:00
|
|
|
let scoop = require("scoop")?;
|
2018-10-17 13:57:30 +03:00
|
|
|
|
2019-02-11 20:38:51 +02:00
|
|
|
print_separator("Scoop");
|
2018-10-17 13:57:30 +03:00
|
|
|
|
2019-02-11 20:38:51 +02:00
|
|
|
run_type.execute(&scoop).args(&["update"]).check_run()?;
|
2020-01-30 20:32:37 +02:00
|
|
|
run_type.execute(&scoop).args(&["update", "*"]).check_run()?;
|
|
|
|
|
|
|
|
|
|
if cleanup {
|
|
|
|
|
run_type.execute(&scoop).args(&["cleanup", "*"]).check_run()?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
2018-10-17 13:57:30 +03:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 23:05:38 +02:00
|
|
|
pub fn run_wsl_topgrade(run_type: RunType) -> Result<()> {
|
2019-06-04 09:35:29 +03:00
|
|
|
let wsl = require("wsl")?;
|
|
|
|
|
let topgrade = Command::new(&wsl)
|
|
|
|
|
.args(&["bash", "-l", "which", "topgrade"])
|
|
|
|
|
.check_output()
|
2019-12-11 23:05:38 +02:00
|
|
|
.map_err(|_| SkipStep)?;
|
2019-06-04 09:35:29 +03:00
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&wsl)
|
|
|
|
|
.args(&["bash", "-c"])
|
|
|
|
|
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade))
|
|
|
|
|
.check_run()
|
|
|
|
|
}
|
2019-06-13 22:05:18 +03:00
|
|
|
|
2020-02-27 22:06:14 +02:00
|
|
|
pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
|
|
|
|
|
let powershell = powershell::Powershell::windows_powershell();
|
|
|
|
|
|
|
|
|
|
if powershell.supports_windows_update() {
|
|
|
|
|
print_separator("Windows Update");
|
|
|
|
|
return powershell.windows_update(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let usoclient = require("UsoClient")?;
|
|
|
|
|
|
|
|
|
|
print_separator("Windows Update");
|
|
|
|
|
println!("Running Windows Update. Check the control panel for progress.");
|
|
|
|
|
ctx.run_type().execute(&usoclient).arg("ScanInstallWait").check_run()?;
|
|
|
|
|
ctx.run_type().execute(&usoclient).arg("StartInstall").check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 22:05:18 +03:00
|
|
|
pub fn reboot() {
|
|
|
|
|
Command::new("shutdown").args(&["/R", "/T", "0"]).spawn().ok();
|
|
|
|
|
}
|