#!/bin/sh # Steward host agent: the packages the agent's helper uses, installed with # whichever package manager the host has (#5789). Served by Steward at # /plugins/host_agent/files/install-deps.sh and run, as root, by install.sh # and the host_agent playbooks: one copy of the list. # # smartmontools gives the helper smartctl, which reads each drive's health. # On pacman hosts, pacman-contrib gives the agent checkupdates, the one safe # way to see pending updates without root (#5803). # A package that can't be installed is reported, never fatal: the agent runs # without it and the host page says what is missing. # # Recommended / weak dependencies are skipped: on Debian, smartmontools # recommends a mail server. have() { command -v "$1" >/dev/null 2>&1; } install_with() { if have apt-get; then export DEBIAN_FRONTEND=noninteractive # A stale package list can't find the package: refresh once and retry. apt-get install -y --no-install-recommends "$@" \ || { apt-get update && apt-get install -y --no-install-recommends "$@"; } elif have dnf; then dnf -y install --setopt=install_weak_deps=False "$@" elif have yum; then yum -y install "$@" elif have zypper; then zypper --non-interactive install --no-recommends "$@" elif have pacman; then pacman -S --needed --noconfirm "$@" elif have apk; then apk add --no-cache "$@" else echo "no package manager this script knows (apt, dnf, yum, zypper, pacman, apk)" return 1 fi } missing="" have smartctl || missing="$missing smartmontools" if have pacman && ! have checkupdates; then missing="$missing pacman-contrib" fi [ -n "$missing" ] || { echo "dependencies present"; exit 0; } # shellcheck disable=SC2086 # one word per package if install_with $missing; then echo "installed:$missing" else echo "WARNING: could not install$missing; until it is, drive health reads \"smartctl not installed\" (smartmontools) and the update check reads \"checkupdates isn't installed\" (pacman-contrib)" fi exit 0