isothrum-machine 3.0.2

Machine-setup domain for Isothrum: check this computer's tools, Docker engines and WSL 2, and detect the Vagrant providers (hypervisors) it can drive.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
//! Installing and removing the tools a computer runs projects with: the container engine, Vagrant,
//! Terraform, the hypervisors, the cloud CLIs and the services they need. Each tool's row
//! ([`Dependency::row`]) says where it exists and what proves it installed; its install and its
//! removal are one exhaustive match per OS over the tool and the package manager, so a tool, an OS
//! or a package manager added is a compile error until each says what it does there. Every plan is
//! built on any OS, so the tests read every row.
//!
//! A plan is a list of [`Step`]s, each one program, run in order through the [`Context`]'s runner
//! ([`run_steps`]): the OS's own trusted flows, never a password prompt of the caller's (pkexec's
//! on Linux, or `sudo -n` when nobody is there to answer one: [`Elevation`]). Why a plan can't be
//! made ([`Refusal`]) and why a step failed ([`StepFailed`]) are codes a UI says in its own words.
//! What an install added, read before and after its plan runs, is [`added`]'s; what it leaves on
//! record, so a clean-up removes only what it added, [`record`]'s; the removal of only that,
//! [`removal`].

use serde::{Deserialize, Serialize};

use crate::context::Context;
use crate::host::{ALL_OSES, Arch, HostOs};
use crate::providers::{Provider, ProviderRow};

pub mod added;
pub mod brew;
pub mod exit_codes;
pub mod interaction;
pub mod linux;
pub(crate) mod mac_image;
pub mod macos;
mod pkexec;
pub mod record;
pub mod root;
mod steps;
mod vmware_utility;
pub mod windows;

pub use added::{Before, Installed, Item, before, items, there};
pub use interaction::{BROADCOM_DOWNLOADS, Interaction, OVFTOOL_PAGE, Prompt, VMWARE_FUSION_PAGE, VMWARE_WORKSTATION_PAGE, VendorPage, interactions};
pub use mac_image::set_app_name;
pub use steps::{Agreement, NotServed, Note, Step, StepFailed, command_line, run_step, run_steps, step};

/// A tool a setup installs.
#[derive(Deserialize, Serialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(any(test, feature = "ts-rs"), derive(ts_rs::TS))]
#[serde(rename_all = "lowercase")]
pub enum Dependency {
    /// Docker: Docker Desktop on macOS and Windows, Docker Engine on Linux.
    Docker,
    /// HashiCorp's Vagrant.
    Vagrant,
    /// HashiCorp's Terraform.
    Terraform,
    /// Oracle's VirtualBox.
    Virtualbox,
    /// QEMU.
    Qemu,
    /// UTM (macOS).
    Utm,
    /// libvirt, with what the vagrant-libvirt plugin builds against (Linux).
    Libvirt,
    /// The AWS CLI.
    Awscli,
    /// The Azure CLI.
    Azurecli,
    /// The Google Cloud CLI.
    Gcloud,
    /// Windows Subsystem for Linux (WSL 2), enabled through its own installer.
    Wsl,
    /// HashiCorp's Vagrant VMware Utility, the service VMware's Vagrant plugin drives VMware
    /// through.
    #[serde(rename = "vmware-utility")]
    VmwareUtility,
    /// Windows' Hyper-V feature, turned on through Windows' own servicing tool (DISM).
    Hyperv,
}

/// Where a tool exists.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Runs {
    /// On these OSes.
    On(&'static [HostOs]),
    /// Where this hypervisor does ([`ProviderRow::of`]): the one table of which OS a hypervisor
    /// belongs to.
    As(Provider),
}

/// A program and the arguments it answers with its version.
pub type Probe = (&'static str, &'static [&'static str]);

/// A tool's row of the setup's table ([`Dependency::row`]).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ToolRow {
    /// Where it exists.
    pub runs: Runs,
    /// The command that proves it installed, when there is one worth trusting (`wsl.exe` ships
    /// with Windows whether WSL is set up or not; UTM is an app; VMware's utility a service). A
    /// hypervisor has none here: its provider's ([`crate::providers::hypervisor_probe`]) is the one
    /// a setup and the provider's detection both read, so they never disagree.
    pub probe: Option<Probe>,
    /// The app bundle that proves it installed on macOS, also before its CLI is on `PATH`, once
    /// whole ([`present`]). Looked for in [`crate::host::Devices::applications`], by its name.
    pub mac_app: Option<&'static str>,
    /// Its winget package, when winget installs and removes it on Windows.
    pub winget: Option<&'static str>,
    /// Where its user installs it themselves when the setup can't (a Linux distribution without
    /// apt or dnf).
    pub own_url: Option<&'static str>,
    /// Where it runs, the CPUs its vendor ships no build for that a setup installs, each with the
    /// vendor's reason: refused there ([`Refusal::NoBuild`]), never offered.
    pub no_build: &'static [NoBuild],
}

/// An OS and CPU a tool's vendor ships no build for that a setup installs, and why.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NoBuild {
    /// The OS.
    pub os: HostOs,
    /// The CPU.
    pub arch: Arch,
    /// Why, as its vendor has it.
    pub why: &'static str,
}

/// Google Cloud CLI on Windows on Arm: Google's Windows installer (the one winget runs) puts no
/// Python on an Arm64 computer, and the CLI needs one, so its install stops ("you must have
/// Python installed", the installer's exit code 2). Google lists no Windows Arm64 build.
/// Vagrant on Linux arm64: HashiCorp ships no Linux arm64 build (its apt repository serves amd64
/// only), so apt installs the distribution's own (Debian 13: 2.3.7), older than the 2.4.0 a run
/// needs. Before 2.4.0 Vagrant reads no box's architecture: on an arm64 computer it adds a box's
/// `x86_64` build (checked: Debian's 2.3.7 on arm64 fetched `cloud-image/debian-13`'s
/// `libvirt/amd64` box), so every project's VM is of the wrong CPU, and Isothrum refuses it.
const VAGRANT_NO_BUILD: &[NoBuild] = &[NoBuild {
    os: HostOs::Linux,
    arch: Arch::Arm64,
    why: "HashiCorp ships no Linux arm64 build, and the distribution's Vagrant is older than the 2.4.0 a run needs (an older one adds a box's x86_64 build on an arm64 computer)",
}];

const GCLOUD_NO_BUILD: &[NoBuild] = &[NoBuild {
    os: HostOs::Windows,
    arch: Arch::Arm64,
    why: "Google ships no Windows on Arm build: its installer brings no Python there, which the CLI needs",
}];

impl Dependency {
    /// Every tool, in the setup's order.
    pub const ALL: [Dependency; 13] = [
        Dependency::Docker,
        Dependency::Vagrant,
        Dependency::Terraform,
        Dependency::Virtualbox,
        Dependency::Qemu,
        Dependency::Utm,
        Dependency::Libvirt,
        Dependency::Awscli,
        Dependency::Azurecli,
        Dependency::Gcloud,
        Dependency::Wsl,
        Dependency::VmwareUtility,
        Dependency::Hyperv,
    ];

    /// Its row of the setup's table.
    #[must_use]
    pub fn row(self) -> ToolRow {
        const ANY: Runs = Runs::On(&ALL_OSES);
        /// A row with no macOS app.
        const fn row(runs: Runs, probe: Option<Probe>, winget: Option<&'static str>, own_url: Option<&'static str>) -> ToolRow {
            ToolRow {
                runs,
                probe,
                mac_app: None,
                winget,
                own_url,
                no_build: &[],
            }
        }
        match self {
            Dependency::Docker => ToolRow {
                mac_app: Some("/Applications/Docker.app"),
                ..row(
                    ANY,
                    Some(("docker", &["--version"])),
                    Some("Docker.DockerDesktop"),
                    Some("https://docs.docker.com/engine/install/"),
                )
            },
            Dependency::Vagrant => ToolRow {
                no_build: VAGRANT_NO_BUILD,
                ..row(
                    ANY,
                    Some(("vagrant", &["--version"])),
                    Some("Hashicorp.Vagrant"),
                    Some("https://developer.hashicorp.com/vagrant/install"),
                )
            },
            Dependency::Terraform => row(ANY, Some(("terraform", &["version"])), Some("Hashicorp.Terraform"), None),
            Dependency::Virtualbox => ToolRow {
                mac_app: Some("/Applications/VirtualBox.app"),
                ..row(
                    Runs::As(Provider::Virtualbox),
                    None,
                    Some("Oracle.VirtualBox"),
                    Some("https://www.virtualbox.org/wiki/Linux_Downloads"),
                )
            },
            Dependency::Qemu => row(Runs::As(Provider::Qemu), None, None, Some("https://www.qemu.org/download/")),
            Dependency::Utm => ToolRow {
                mac_app: Some("/Applications/UTM.app"),
                ..row(Runs::As(Provider::Utm), None, None, None)
            },
            Dependency::Libvirt => row(Runs::As(Provider::Libvirt), None, None, Some("https://libvirt.org/")),
            Dependency::Awscli => row(ANY, Some(("aws", &["--version"])), Some("Amazon.AWSCLI"), None),
            Dependency::Azurecli => row(ANY, Some(("az", &["version"])), Some("Microsoft.AzureCLI"), None),
            Dependency::Gcloud => ToolRow {
                no_build: GCLOUD_NO_BUILD,
                ..row(ANY, Some(("gcloud", &["--version"])), Some("Google.CloudSDK"), None)
            },
            Dependency::Wsl => row(Runs::On(&[HostOs::Windows]), None, None, None),
            Dependency::VmwareUtility => row(ANY, None, None, Some("https://developer.hashicorp.com/vagrant/install/vmware")),
            Dependency::Hyperv => row(Runs::As(Provider::Hyperv), None, None, None),
        }
    }

    /// The tool a setup installs as hypervisor `provider`, where it does (the row that names it).
    #[must_use]
    pub fn of_hypervisor(provider: Provider) -> Option<Dependency> {
        Dependency::ALL.into_iter().find(|d| d.hypervisor() == Some(provider))
    }

    /// The hypervisor it serves without being it, when it does: VMware's utility serves VMware
    /// Workstation (or Fusion), whose installer it needs first (Windows' MSI refuses to run
    /// without it, exiting 1603; on Linux its service doesn't answer). A setup installs it once
    /// that hypervisor is installed, never before ([`crate::requirements::Plan::After`]).
    #[must_use]
    pub fn serves(self) -> Option<Provider> {
        match self {
            Dependency::VmwareUtility => Some(Provider::VmwareDesktop),
            _ => None,
        }
    }

    /// The hypervisor it is, when it is one.
    #[must_use]
    pub fn hypervisor(self) -> Option<Provider> {
        match self.row().runs {
            Runs::As(provider) => Some(provider),
            Runs::On(_) => None,
        }
    }

    /// Why its vendor ships no build of it for `os` on `arch` that a setup installs, when it
    /// doesn't ([`ToolRow::no_build`]).
    #[must_use]
    pub fn no_build(self, os: HostOs, arch: Arch) -> Option<&'static str> {
        self.row().no_build.iter().find(|n| n.os == os && n.arch == arch).map(|n| n.why)
    }

    /// Whether it exists on `os`: a hypervisor where its provider's row says, the rest by its own
    /// row. An install or a removal elsewhere is refused ([`Refusal::NotHere`]).
    #[must_use]
    pub fn runs_on(self, os: HostOs) -> bool {
        match self.row().runs {
            Runs::On(oses) => oses.contains(&os),
            Runs::As(provider) => ProviderRow::of(provider).oses.contains(&os),
        }
    }

    /// [`Dependency::runs_on`] as an install or a removal asks it: refused when it doesn't.
    pub(crate) fn runs_here(self, os: HostOs) -> Result<(), Refusal> {
        if self.runs_on(os) {
            Ok(())
        } else {
            Err(Refusal::NotHere { dependency: self, os })
        }
    }
}

/// The step that installs the Vagrant plugin `plugin` (for this account, no administrator), when
/// `plugin` names one: only ever a `vagrant-*` / `vagrant_*` identifier, never an option or a path.
#[must_use]
pub fn vagrant_plugin(plugin: &str) -> Option<Step> {
    let named = (plugin.starts_with("vagrant-") || plugin.starts_with("vagrant_"))
        && plugin.len() <= 64
        && plugin.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_');
    named.then(|| step("vagrant", &["plugin", "install", plugin]))
}

/// How a step that needs an administrator is elevated. With someone there to answer, the OS's
/// password prompt (pkexec's on Linux, macOS's own); with nobody (a script, a machine set up
/// unattended), no prompt may be raised: as is when the process is root already, else through
/// `sudo -n`, refused at once rather than waiting on a password.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Elevation {
    /// The OS's password prompt: pkexec's (Linux), macOS's administrator prompt.
    Prompt,
    /// Unattended, `root` when the process is root already.
    Unattended {
        /// Whether the process runs as root.
        root: bool,
    },
}

/// Why no administrator's step can run here: nobody can be asked, and nothing runs one without
/// asking ([`Elevation::here`]).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum NoElevation {
    /// Not root, `sudo` asks for a password, and no login session can show the OS's password
    /// prompt (an ssh session, a Linux machine without a desktop).
    NoPromptNorSudo,
}

impl std::fmt::Display for NoElevation {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            NoElevation::NoPromptNorSudo => f.write_str(
                "no administrator's step can run: sudo asks for a password, and no login session here can show the password prompt (an ssh session can't)",
            ),
        }
    }
}

impl std::error::Error for NoElevation {}

/// What macOS's `launchctl managername` says in a login session at the Mac's screen, where its
/// administrator prompt shows; an ssh session's is `Background`.
const MAC_LOGIN_SESSION: &str = "Aqua";

impl Elevation {
    /// How a root step is elevated on the context's host when nobody chose: as is when root;
    /// through `sudo -n` only when it runs a command without a password (`sudo -n true`); else
    /// through the OS's password prompt where a login session can show it (macOS's administrator
    /// prompt at the Mac's screen, `launchctl managername` saying `Aqua`; pkexec's on a Linux
    /// desktop, `desktop` saying one is there); else refused. Windows always asks through UAC.
    /// An app with someone at it asks through the prompt without this ([`Elevation::Prompt`]).
    ///
    /// # Errors
    ///
    /// [`NoElevation`]: why no root step can run here.
    pub async fn here(cx: &Context, desktop: bool) -> Result<Elevation, NoElevation> {
        if cx.host.os == HostOs::Windows {
            return Ok(Elevation::Prompt);
        }
        if cx.read_ok("id", &["-u"]).await.is_ok_and(|uid| uid.trim() == "0") {
            return Ok(Elevation::Unattended { root: true });
        }
        if cx.read_ok("sudo", &["-n", "true"]).await.is_ok() {
            return Ok(Elevation::Unattended { root: false });
        }
        let session = match cx.host.os {
            HostOs::Macos => cx.read_ok("launchctl", &["managername"]).await.is_ok_and(|m| m.trim() == MAC_LOGIN_SESSION),
            _ => desktop,
        };
        if session { Ok(Elevation::Prompt) } else { Err(NoElevation::NoPromptNorSudo) }
    }

    /// `program` with `args`, run as root this way.
    #[must_use]
    pub fn as_root(self, program: &str, args: &[String]) -> (String, Vec<String>) {
        let all = |prefix: &[&str]| {
            prefix
                .iter()
                .map(ToString::to_string)
                .chain(std::iter::once(program.to_owned()))
                .chain(args.iter().cloned())
                .collect()
        };
        match self {
            Elevation::Prompt => ("pkexec".into(), all(&[])),
            Elevation::Unattended { root: true } => (program.to_owned(), args.to_vec()),
            Elevation::Unattended { root: false } => ("sudo".into(), all(&["-n"])),
        }
    }
}

/// Why a plan can't be made here. A UI says each in its own words.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Refusal {
    /// The tool doesn't run on this OS: there is nothing of it to install or remove here.
    NotHere {
        /// The tool.
        dependency: Dependency,
        /// The OS.
        os: HostOs,
    },
    /// A Linux distribution with neither apt nor dnf: its user installs the tool themselves.
    WithoutPackages {
        /// The tool.
        dependency: Dependency,
    },
    /// A tool installed through apt only for now, on a dnf distribution.
    AptOnly {
        /// The tool.
        dependency: Dependency,
    },
    /// Homebrew isn't installed, which a macOS install goes through.
    NoHomebrew,
    /// Homebrew isn't installed, which this removal on macOS goes through.
    HomebrewNeeded,
    /// VirtualBox's removal on macOS without its installer image, whose uninstaller it runs
    /// ([`macos::virtualbox_image`]).
    NoVirtualboxImage,
    /// A Windows feature, which its user turns off in Windows Features.
    WindowsFeature {
        /// The tool.
        dependency: Dependency,
    },
    /// Windows on Arm, which this hypervisor (or the one this tool serves) isn't built for.
    NotOnWindowsOnArm {
        /// The tool.
        dependency: Dependency,
        /// The hypervisor.
        provider: Provider,
    },
    /// Its vendor ships no build for this OS and CPU that a setup installs ([`ToolRow::no_build`]).
    NoBuild {
        /// The tool.
        dependency: Dependency,
        /// The OS.
        os: HostOs,
        /// The CPU.
        arch: Arch,
        /// Why, as its vendor has it.
        why: &'static str,
    },
    /// The private file a root step's proxy settings go through couldn't be written: what the OS
    /// said.
    PrivateFile(String),
    /// A removal of nothing an install added ([`removal`]): what was there before an install is
    /// never removed.
    NothingAdded {
        /// The tool.
        dependency: Dependency,
    },
}

impl std::fmt::Display for Refusal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Refusal::NotHere { dependency, os } => write!(f, "{dependency:?} doesn't run on {}", crate::host::os_name(*os)),
            Refusal::WithoutPackages { dependency } => write!(f, "{dependency:?}: this distribution has neither apt nor dnf"),
            Refusal::AptOnly { dependency } => write!(f, "{dependency:?} installs through apt only"),
            Refusal::NoHomebrew | Refusal::HomebrewNeeded => f.write_str("Homebrew isn't installed"),
            Refusal::WindowsFeature { dependency } => write!(f, "{dependency:?} is turned off in Windows Features"),
            Refusal::NotOnWindowsOnArm { dependency, .. } => write!(f, "{dependency:?} doesn't run on Windows on Arm"),
            Refusal::NoBuild { dependency, os, arch, why } => write!(f, "{dependency:?} isn't offered on {} {arch:?}: {why}", crate::host::os_name(*os)),
            Refusal::NoVirtualboxImage => f.write_str("VirtualBox's installer image is needed to run its uninstaller"),
            Refusal::PrivateFile(why) => write!(f, "a root step's private file couldn't be written: {why}"),
            Refusal::NothingAdded { dependency } => write!(f, "nothing of {dependency:?} was added by an install, so nothing of it is removed"),
        }
    }
}

impl std::error::Error for Refusal {}

/// The install of `dep` on `host`, whatever its OS: macOS's Homebrew formulae and vendors' disk
/// images and packages (installed as an administrator `elevation`'s way), Windows' winget packages
/// and elevated installers, or Linux's root script for the user `user` (joined to the groups a
/// tool's devices need), its root steps run `elevation`'s way with this process's proxy
/// ([`linux::proxy_assignments`]). The one call a caller plans an
/// install with: which OS's plan applies is the host's, never the OS the crate is built for.
///
/// # Errors
///
/// [`Refusal`]: why it can't be installed there ([`Refusal::NotHere`] first, before the package
/// manager is looked at).
///
/// What it asks of its user ([`interactions`]) is the plan's last step's, the one that installs
/// the tool (one before it only prepares: a Homebrew tap trusted).
pub fn plan(dep: Dependency, host: &crate::host::Host, user: Option<&str>, elevation: Elevation) -> Result<Vec<Step>, Refusal> {
    let mut steps = os_plan(dep, host, user, elevation)?;
    if let Some(last) = steps.last_mut() {
        last.interactions = interactions(dep, host, elevation, user);
    }
    Ok(steps)
}

/// [`plan`]'s steps, as the host's OS makes them.
fn os_plan(dep: Dependency, host: &crate::host::Host, user: Option<&str>, elevation: Elevation) -> Result<Vec<Step>, Refusal> {
    dep.runs_here(host.os)?;
    match host.os {
        HostOs::Macos => macos::install(dep, host.packages, host.arch, elevation),
        HostOs::Windows => windows::install(dep, host.arch),
        HostOs::Linux => {
            let root = linux::Root::with_this_proxy(elevation);
            linux::install(dep, host.packages, host.arch, user, &root)
        }
    }
}

/// The removal of what `added` lists of `dep` on `host` ([`Installed::added`], as on record),
/// and of nothing else: on Linux those of its packages ([`added::packages`]), through the package
/// manager that installed them, its root steps run `elevation`'s way with this process's proxy;
/// elsewhere, and for the AWS CLI's folder, the tool itself when the record says the install
/// added it ([`Item::Tool`]). On macOS, VirtualBox's uninstaller runs from its installer image
/// (`virtualbox`).
///
/// # Errors
///
/// [`Refusal::NothingAdded`] when `added` lists nothing of `dep`'s, or why it can't be removed
/// there.
pub fn removal(dep: Dependency, host: &crate::host::Host, added: &[Item], elevation: Elevation, virtualbox: Option<&str>) -> Result<Vec<Step>, Refusal> {
    dep.runs_here(host.os)?;
    match host.os {
        HostOs::Linux => {
            let root = linux::Root::with_this_proxy(elevation);
            linux::uninstall(dep, host.packages, added, &root)
        }
        _ if !added.contains(&Item::Tool(dep)) => Err(Refusal::NothingAdded { dependency: dep }),
        HostOs::Macos => macos::uninstall(dep, host.packages, virtualbox),
        HostOs::Windows => windows::uninstall(dep),
    }
}

/// Whether `dep` is installed on the context's host; `None` when that can't be told (WSL, Hyper-V).
/// The tool itself (`tool_found`); a hypervisor with the programs its VMs need beside it
/// ([`crate::providers::helpers()`]), as its provider's detection reads it: one without them is
/// installed again, which brings them.
pub async fn present(cx: &Context, dep: Dependency) -> Option<bool> {
    let found = tool_found(cx, dep).await?;
    match dep.hypervisor() {
        Some(provider) if found => Some(crate::providers::helper::missing(cx, provider).await.is_none()),
        _ => Some(found),
    }
}

/// Whether `dep` itself is on the context's host, its helpers aside; `None` when that can't be
/// told (WSL, Hyper-V). Its macOS app bundle, once whole (no copy under way, its signature
/// verifying: one that isn't is installed again), else its version probe ([`ToolRow::probe`]; a
/// hypervisor's, its provider's); VMware's utility, a service, as
/// [`crate::providers::vmware_utility`] finds it.
pub(crate) async fn tool_found(cx: &Context, dep: Dependency) -> Option<bool> {
    if dep == Dependency::VmwareUtility {
        return Some(crate::providers::vmware_utility(&cx.host).await != crate::providers::UtilityState::Missing);
    }
    let row = dep.row();
    let mac_app = row.mac_app.filter(|_| cx.host.os == HostOs::Macos);
    if let Some(app) = mac_app
        .and_then(|a| std::path::Path::new(a).file_name())
        .map(|a| cx.host.devices.applications.join(a))
        && app.exists()
    {
        return Some(mac_image::complete(cx, &app).await);
    }
    let probe = dep
        .hypervisor()
        .map_or(row.probe, |provider| crate::providers::hypervisor_probe(provider, cx.host.arch));
    match probe {
        Some((program, args)) => Some(cx.read_ok(program, args).await.is_ok()),
        None if mac_app.is_some() => Some(false),
        None => None,
    }
}

#[cfg(test)]
mod tests;