2020-02-27 15:32:13 +02:00
|
|
|
use crate::execution_context::ExecutionContext;
|
2020-10-01 14:31:36 +03:00
|
|
|
use crate::executor::RunType;
|
2020-06-15 15:43:59 +03:00
|
|
|
use crate::terminal::{print_separator, prompt_yesno};
|
2021-04-28 10:55:54 +03:00
|
|
|
use crate::{error::TopgradeError, utils::require};
|
2019-12-11 23:05:38 +02:00
|
|
|
use anyhow::Result;
|
2020-06-15 15:43:59 +03:00
|
|
|
use log::debug;
|
2021-04-28 10:55:54 +03:00
|
|
|
use std::process::Command;
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2020-02-27 20:28:50 +02:00
|
|
|
pub fn run_macports(ctx: &ExecutionContext) -> Result<()> {
|
|
|
|
|
require("port")?;
|
|
|
|
|
let sudo = ctx.sudo().as_ref().unwrap();
|
|
|
|
|
print_separator("MacPorts");
|
|
|
|
|
ctx.run_type().execute(sudo).args(&["port", "selfupdate"]).check_run()?;
|
|
|
|
|
ctx.run_type()
|
|
|
|
|
.execute(sudo)
|
|
|
|
|
.args(&["port", "-u", "upgrade", "outdated"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
if ctx.config().cleanup() {
|
|
|
|
|
ctx.run_type()
|
|
|
|
|
.execute(sudo)
|
|
|
|
|
.args(&["port", "-N", "reclaim"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 16:22:17 +02:00
|
|
|
pub fn run_mas(run_type: RunType) -> Result<()> {
|
|
|
|
|
let mas = require("mas")?;
|
|
|
|
|
print_separator("macOS App Store");
|
|
|
|
|
|
|
|
|
|
run_type.execute(mas).arg("upgrade").check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 15:43:59 +03:00
|
|
|
pub fn upgrade_macos(ctx: &ExecutionContext) -> Result<()> {
|
2020-01-28 16:22:17 +02:00
|
|
|
print_separator("macOS system update");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2020-06-15 15:43:59 +03:00
|
|
|
let should_ask = !(ctx.config().yes()) || (ctx.config().dry_run());
|
|
|
|
|
if should_ask {
|
|
|
|
|
println!("Finding available software");
|
|
|
|
|
if system_update_available()? {
|
|
|
|
|
let answer = prompt_yesno("A system update is available. Do you wish to install it?")?;
|
|
|
|
|
if !answer {
|
2020-08-21 23:04:36 +03:00
|
|
|
return Ok(());
|
2020-06-15 15:43:59 +03:00
|
|
|
}
|
|
|
|
|
println!();
|
|
|
|
|
} else {
|
|
|
|
|
println!("No new software available.");
|
2020-08-11 10:49:33 +03:00
|
|
|
return Ok(());
|
2020-06-15 15:43:59 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut command = ctx.run_type().execute("softwareupdate");
|
|
|
|
|
command.args(&["--install", "--all"]);
|
|
|
|
|
|
|
|
|
|
if should_ask {
|
|
|
|
|
command.arg("--no-scan");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command.check_run()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn system_update_available() -> Result<bool> {
|
|
|
|
|
let output = Command::new("softwareupdate").arg("--list").output()?;
|
|
|
|
|
debug!("{:?}", output);
|
|
|
|
|
|
|
|
|
|
let status = output.status;
|
|
|
|
|
if !status.success() {
|
|
|
|
|
return Err(TopgradeError::ProcessFailed(status).into());
|
|
|
|
|
}
|
|
|
|
|
let string_output = String::from_utf8(output.stderr)?;
|
|
|
|
|
debug!("{:?}", string_output);
|
|
|
|
|
Ok(!string_output.contains("No new software available"))
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|