Files
topgrade/src/steps/os/windows.rs

83 lines
2.1 KiB
Rust
Raw Normal View History

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;
use anyhow::Result;
2018-06-28 12:16:54 +03:00
use std::process::Command;
pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> {
2019-02-11 20:38:51 +02:00
let choco = require("choco")?;
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-07-10 11:21:19 +03:00
let mut cmd = &choco;
let mut args = vec!["upgrade", "all"];
2020-07-10 11:21:19 +03:00
if let Some(sudo) = ctx.sudo() {
cmd = sudo;
args.insert(0, "choco");
}
let mut command = ctx.run_type().execute(&cmd);
command.args(&args);
if yes {
command.arg("--yes");
}
command.check_run()
2018-06-28 12:16:54 +03:00
}
2018-08-22 22:01:06 +03: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()?;
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
}
pub fn run_wsl_topgrade(run_type: RunType) -> Result<()> {
let wsl = require("wsl")?;
let topgrade = Command::new(&wsl)
2020-08-18 08:39:13 +03:00
.args(&["which", "topgrade"])
.check_output()
.map_err(|_| SkipStep)?;
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();
}