committed by
GitHub
parent
0251c2769b
commit
4230388017
@@ -60,17 +60,25 @@ pub fn run_scoop(cleanup: bool, run_type: RunType) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
|
fn get_wsl_distributions(wsl: &Path) -> Result<Vec<String>> {
|
||||||
let wsl = require("wsl")?;
|
let output = Command::new(wsl).args(&["--list", "-q"]).check_output()?;
|
||||||
|
Ok(output
|
||||||
|
.lines()
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|x| x.replace("\u{0}", "").replace('\r', ""))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn upgrade_wsl_distribution(wsl: &Path, dist: &str, ctx: &ExecutionContext) -> Result<()> {
|
||||||
let topgrade = Command::new(&wsl)
|
let topgrade = Command::new(&wsl)
|
||||||
.args(&["bash", "-lc", "which topgrade"])
|
.args(&["-d", dist, "bash", "-lc", "which topgrade"])
|
||||||
.check_output()
|
.check_output()
|
||||||
.map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?;
|
.map_err(|_| SkipStep(String::from("Could not find Topgrade installed in WSL")))?;
|
||||||
|
|
||||||
let mut command = ctx.run_type().execute(&wsl);
|
let mut command = ctx.run_type().execute(&wsl);
|
||||||
command
|
command
|
||||||
.args(&["bash", "-c"])
|
.args(&["-d", dist, "bash", "-c"])
|
||||||
.arg(format!("TOPGRADE_PREFIX=WSL exec {}", topgrade));
|
.arg(format!("TOPGRADE_PREFIX={} exec {}", dist, topgrade));
|
||||||
|
|
||||||
if ctx.config().yes(Step::Wsl) {
|
if ctx.config().yes(Step::Wsl) {
|
||||||
command.arg("-y");
|
command.arg("-y");
|
||||||
@@ -79,6 +87,31 @@ pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
command.check_run()
|
command.check_run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||||
|
let wsl = require("wsl")?;
|
||||||
|
let wsl_distributions = get_wsl_distributions(&wsl)?;
|
||||||
|
let mut ran = false;
|
||||||
|
|
||||||
|
debug!("WSL distributions: {:?}", wsl_distributions);
|
||||||
|
|
||||||
|
for distribution in wsl_distributions {
|
||||||
|
let result = upgrade_wsl_distribution(&wsl, &distribution, ctx);
|
||||||
|
debug!("Upgrading {:?}: {:?}", distribution, result);
|
||||||
|
if let Err(e) = result {
|
||||||
|
if e.is::<SkipStep>() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ran = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ran {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(SkipStep(String::from("Could not find Topgrade in any WSL disribution")).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
|
pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
|
||||||
let powershell = powershell::Powershell::windows_powershell();
|
let powershell = powershell::Powershell::windows_powershell();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user