Skip to main content

Module install

Module install 

Source
Expand description

Install module for building package installation, removal, and update commands.

This module builds commands — it never executes them. Every builder returns a CommandSpec (program + argument vector) that callers can:

Functionality:

  • Command building — pacman install/remove/update, AUR helper install
  • Batch planning — split mixed target lists between pacman and an AUR helper
  • Detection — find the preferred AUR helper (paruyay) and privilege tool (doassudo) on PATH
  • Shell safety — strict package-name validation and POSIX quoting helpers

§Features

This module requires the install feature flag (which enables deps for the shared PackageRef/PackageSource types):

[dependencies]
arch-toolkit = { version = "0.3", features = ["install"] }

§Examples

§Build and Display an Install Command

use arch_toolkit::install::build_pacman_install;
use arch_toolkit::types::install::InstallOptions;

let spec = build_pacman_install(&["ripgrep", "fd"], &InstallOptions::default())?;
// Dry run: display instead of executing
println!("Would run: {}", spec.to_shell_string());

§Detect Tools and Plan a Mixed Batch

use arch_toolkit::install::{build_batch_install, detect_aur_helper, detect_privilege_tool};
use arch_toolkit::types::install::InstallOptions;
use arch_toolkit::{PackageRef, PackageSource};

let targets = vec![
    PackageRef::official("ripgrep", "14.0.0", "extra", "x86_64"),
    PackageRef::aur("yay-bin", "12.0.0"),
];
let plan = build_batch_install(
    &targets,
    detect_aur_helper(),
    detect_privilege_tool(),
    &InstallOptions::default(),
    None::<&std::collections::HashSet<String>>,
)?;
for command in &plan.commands {
    println!("{command}");
}

§Remove Packages with Cascade Control

use arch_toolkit::install::{build_remove_command, with_privilege};
use arch_toolkit::types::install::{CascadeMode, PrivilegeTool};

let spec = with_privilege(
    PrivilegeTool::Sudo,
    build_remove_command(&["old-package"], CascadeMode::CascadeWithConfigs, true)?,
);
assert_eq!(spec.to_shell_string(), "sudo pacman -Rns --noconfirm -- old-package");

§Execute a Built Command (caller’s decision)

use arch_toolkit::install::build_update_command;

let spec = build_update_command(None, true);
let status = spec.to_command().status()?;
println!("Update exited with: {status}");

Re-exports§

pub use crate::types::install::AurHelper;
pub use crate::types::install::CascadeMode;
pub use crate::types::install::CommandSpec;
pub use crate::types::install::InstallOptions;
pub use crate::types::install::PrivilegeTool;

Structs§

InstallPlan
What: The result of planning a batch installation.

Constants§

NO_AUR_HELPER_MESSAGE
Message printed by shell-fallback bodies when no AUR helper is installed.

Functions§

aur_install_shell_fallback
What: Build a shell body that installs AUR packages with runtime helper fallback.
aur_update_shell_fallback
What: Build a shell body that updates AUR packages with runtime helper fallback.
build_aur_install
What: Build an AUR helper install command for AUR packages.
build_aur_update_command
What: Build an AUR-only update command (-Sua).
build_batch_install
What: Plan a batch installation by splitting targets between pacman and an AUR helper.
build_force_sync_update_command
What: Build a full-system update command that force-refreshes sync databases.
build_pacman_install
What: Build a pacman install command for official repository packages.
build_remove_command
What: Build a pacman remove command with the requested cascade level.
build_update_command
What: Build a full-system update command.
command_on_path
What: Determine whether a command is available on the Unix PATH.
detect_aur_helper
What: Detect the preferred AUR helper available on PATH.
detect_privilege_tool
What: Detect the preferred privilege escalation tool available on PATH.
is_aur_helper_available
What: Check whether a specific AUR helper is available on PATH.
is_privilege_tool_available
What: Check whether a specific privilege tool is available on PATH.
is_safe_package_name
What: Check whether a package name matches the strict allowlist used for install commands.
resolve_command_on_path
What: Resolve an executable on PATH or by explicit path.
shell_single_quote
What: Safely single-quote an arbitrary string for POSIX shells.
validate_package_names
What: Validate a list of package names against the strict install-command allowlist.
with_privilege
What: Wrap a command with a privilege escalation tool prefix.