2022-11-08 05:54:35 -05:00
|
|
|
use crate::command::CommandExt;
|
2020-02-27 15:32:13 +02:00
|
|
|
use crate::execution_context::ExecutionContext;
|
2020-06-15 15:43:59 +03:00
|
|
|
use crate::terminal::{print_separator, prompt_yesno};
|
2023-06-13 22:15:57 +08:00
|
|
|
use crate::utils::{require_option, REQUIRE_SUDO};
|
2022-11-08 05:54:35 -05:00
|
|
|
use crate::{utils::require, Step};
|
2022-11-11 09:39:29 -05:00
|
|
|
use color_eyre::eyre::Result;
|
2022-06-17 11:10:21 +03:00
|
|
|
use std::fs;
|
2021-04-28 10:55:54 +03:00
|
|
|
use std::process::Command;
|
2022-11-16 13:43:57 -05:00
|
|
|
use tracing::debug;
|
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")?;
|
2023-06-13 22:15:57 +08:00
|
|
|
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
|
|
|
|
|
|
2020-02-27 20:28:50 +02:00
|
|
|
print_separator("MacPorts");
|
2022-11-08 05:54:35 -05:00
|
|
|
ctx.run_type()
|
|
|
|
|
.execute(sudo)
|
|
|
|
|
.args(["port", "selfupdate"])
|
|
|
|
|
.status_checked()?;
|
2020-02-27 20:28:50 +02:00
|
|
|
ctx.run_type()
|
|
|
|
|
.execute(sudo)
|
2022-11-03 04:26:20 +08:00
|
|
|
.args(["port", "-u", "upgrade", "outdated"])
|
2022-11-08 05:54:35 -05:00
|
|
|
.status_checked()?;
|
2020-02-27 20:28:50 +02:00
|
|
|
if ctx.config().cleanup() {
|
|
|
|
|
ctx.run_type()
|
|
|
|
|
.execute(sudo)
|
2022-11-03 04:26:20 +08:00
|
|
|
.args(["port", "-N", "reclaim"])
|
2022-11-08 05:54:35 -05:00
|
|
|
.status_checked()?;
|
2020-02-27 20:28:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-25 15:09:23 +08:00
|
|
|
pub fn run_mas(ctx: &ExecutionContext) -> Result<()> {
|
2020-01-28 16:22:17 +02:00
|
|
|
let mas = require("mas")?;
|
|
|
|
|
print_separator("macOS App Store");
|
|
|
|
|
|
2023-05-25 15:09:23 +08:00
|
|
|
ctx.run_type().execute(mas).arg("upgrade").status_checked()
|
2020-01-28 16:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2021-12-06 14:44:20 +02:00
|
|
|
let should_ask = !(ctx.config().yes(Step::System)) || (ctx.config().dry_run());
|
2020-06-15 15:43:59 +03:00
|
|
|
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");
|
2022-11-03 04:26:20 +08:00
|
|
|
command.args(["--install", "--all"]);
|
2020-06-15 15:43:59 +03:00
|
|
|
|
|
|
|
|
if should_ask {
|
|
|
|
|
command.arg("--no-scan");
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 05:54:35 -05:00
|
|
|
command.status_checked()
|
2020-06-15 15:43:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn system_update_available() -> Result<bool> {
|
2022-11-08 05:54:35 -05:00
|
|
|
let output = Command::new("softwareupdate").arg("--list").output_checked_utf8()?;
|
|
|
|
|
|
2020-06-15 15:43:59 +03:00
|
|
|
debug!("{:?}", output);
|
|
|
|
|
|
2022-11-08 05:54:35 -05:00
|
|
|
Ok(!output.stderr.contains("No new software available"))
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
2022-06-17 11:10:21 +03:00
|
|
|
|
|
|
|
|
pub fn run_sparkle(ctx: &ExecutionContext) -> Result<()> {
|
|
|
|
|
let sparkle = require("sparkle")?;
|
|
|
|
|
|
|
|
|
|
print_separator("Sparkle");
|
|
|
|
|
|
|
|
|
|
for application in (fs::read_dir("/Applications")?).flatten() {
|
|
|
|
|
let probe = Command::new(&sparkle)
|
2022-11-03 04:26:20 +08:00
|
|
|
.args(["--probe", "--application"])
|
2022-06-17 11:10:21 +03:00
|
|
|
.arg(application.path())
|
2022-11-08 05:54:35 -05:00
|
|
|
.output_checked_utf8();
|
2022-06-17 11:10:21 +03:00
|
|
|
if probe.is_ok() {
|
|
|
|
|
let mut command = ctx.run_type().execute(&sparkle);
|
2022-11-03 04:26:20 +08:00
|
|
|
command.args(["bundle", "--check-immediately", "--application"]);
|
2022-06-17 11:10:21 +03:00
|
|
|
command.arg(application.path());
|
2022-11-08 05:54:35 -05:00
|
|
|
command.status_checked()?;
|
2022-06-17 11:10:21 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|