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;
|
2021-02-02 22:28:22 +02:00
|
|
|
use crate::{error::SkipStep, steps::git::Repositories};
|
2021-02-11 06:31:59 +02:00
|
|
|
use crate::{execution_context::ExecutionContext, utils::require_option};
|
2019-12-11 23:05:38 +02:00
|
|
|
use anyhow::Result;
|
2021-02-02 22:28:22 +02:00
|
|
|
use log::debug;
|
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::{ffi::OsStr, process::Command};
|
2018-06-28 12:16:54 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2020-08-21 21:10:54 +03:00
|
|
|
pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
|
2019-06-04 09:35:29 +03:00
|
|
|
let wsl = require("wsl")?;
|
|
|
|
|
let topgrade = Command::new(&wsl)
|
2021-02-13 07:05:58 +02:00
|
|
|
.args(&["bash", "-lc", "which topgrade"])
|
2019-06-04 09:35:29 +03:00
|
|
|
.check_output()
|
2020-08-21 23:04:36 +03:00
|
|
|
.map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?;
|
2019-06-04 09:35:29 +03:00
|
|
|
|
2020-08-21 21:10:54 +03:00
|
|
|
let mut command = ctx.run_type().execute(&wsl);
|
|
|
|
|
command
|
2019-06-04 09:35:29 +03:00
|
|
|
.args(&["bash", "-c"])
|
2020-08-21 21:10:54 +03:00
|
|
|
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade));
|
|
|
|
|
|
|
|
|
|
if ctx.config().yes() {
|
|
|
|
|
command.arg("-y");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command.check_run()
|
2019-06-04 09:35:29 +03:00
|
|
|
}
|
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()
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 06:31:59 +02:00
|
|
|
pub fn upgrade_store_apps(ctx: &ExecutionContext) -> Result<()> {
|
|
|
|
|
let powershell = powershell::Powershell::windows_powershell();
|
|
|
|
|
|
|
|
|
|
let path = powershell.path().as_ref().unwrap();
|
|
|
|
|
let sudo = require_option(ctx.sudo().as_ref(), String::from("Sudo is required"))?;
|
2021-02-18 14:20:30 +02:00
|
|
|
print_separator("Microsoft Store");
|
|
|
|
|
println!("Updating Microsoft Store applications in the background");
|
2021-02-11 06:31:59 +02:00
|
|
|
|
2021-02-22 10:37:35 +02:00
|
|
|
ctx.run_type().execute(sudo).arg(path).args(&["-NoProfile", "-Command", "(Get-WmiObject -Namespace 'root\\cimv2\\mdm\\dmmap' -Class 'MDM_EnterpriseModernAppManagement_AppManagement01').UpdateScanMethod() > $null"]).check_run()
|
2021-02-11 06:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 22:05:18 +03:00
|
|
|
pub fn reboot() {
|
|
|
|
|
Command::new("shutdown").args(&["/R", "/T", "0"]).spawn().ok();
|
|
|
|
|
}
|
2021-02-02 22:28:22 +02:00
|
|
|
|
|
|
|
|
pub fn insert_startup_scripts(ctx: &ExecutionContext, git_repos: &mut Repositories) -> Result<()> {
|
|
|
|
|
let startup_dir = ctx
|
|
|
|
|
.base_dirs()
|
|
|
|
|
.data_dir()
|
|
|
|
|
.join("Microsoft\\Windows\\Start Menu\\Programs\\Startup");
|
|
|
|
|
for entry in std::fs::read_dir(&startup_dir)? {
|
|
|
|
|
if let Ok(entry) = entry {
|
|
|
|
|
let path = entry.path();
|
|
|
|
|
if path.extension().and_then(OsStr::to_str) == Some("lnk") {
|
|
|
|
|
if let Ok(lnk) = parselnk::Lnk::try_from(Path::new(&path)) {
|
|
|
|
|
debug!("Startup link: {:?}", lnk);
|
|
|
|
|
if let Some(path) = lnk.relative_path() {
|
|
|
|
|
git_repos.insert_if_repo(&startup_dir.join(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|