#!/bin/sh # HIPS Provider: the one-line installer for Linux and macOS. # # curl -fsSL https://hips.com/install.sh | bash # # The script is POSIX sh, so `| sh` works as well. It installs the HIPS # Provider app from the public releases at # https://github.com/hips-ai/hips-provider-releases, on Linux on an x86_64 # or arm64 (aarch64) machine that uses apt (Debian, Ubuntu) or dnf (Fedora, # RHEL, Rocky Linux, AlmaLinux, Amazon Linux 2023), and on macOS 13 or later # on a Mac with Apple silicon: # # 1. Checks the computer: the system and the processor, and on Linux the # package manager and the GNU C library (glibc). # 2. Downloads the release's SHA256SUMS, its signature SHA256SUMS.sig and # the package for this computer into a private temporary folder, which # is removed when it ends. # 3. Checks that HIPS's release key signed SHA256SUMS (with sqv or gpgv, # which every apt system has) and the package's SHA-256 against it, # and installs nothing if either fails. On Fedora, RHEL and the other # rpm systems it gives rpm HIPS's package key, so rpm installs the # package only with its own HIPS signature. # 4. Installs the package and nothing else: on Linux with dpkg or rpm on # its own, which sets up no other package of the system and reads no # repository, after getting with apt-get or dnf only a dependency the # system lacks; on a Mac with the macOS installer. Whether it worked # is read from the package system's record of HIPS Provider alone, # never from a tool's exit code, so a system whose other packages # are broken still gets HIPS Provider; what is broken there is listed # for its owner to fix, and never stops the install. A package system # another program holds (automatic updates) is waited for, up to 15 # minutes. A HIPS Provider its owner holds at its version (apt-mark # hold, dnf versionlock) stays as it is, and a masked service is # unmasked by its owner only. Only this step and the next two run as # root, through sudo unless the script already runs as root, which is # asked for its password once. # 5. Makes sure the HIPS Provider service is running (in a container # where systemd does not run, under the app's own supervision, the # container declared a data-center server), and on Linux installs # what the GPU needs from the distribution: on an AMD GPU # the Vulkan loader and Mesa's Vulkan drivers where they are missing, # and on Strix Halo (gfx1151) a kernel with the fixes ROCm needs, # which one restart of the computer finishes (it never restarts the # computer itself). # 6. Sets how this computer works for HIPS. On Linux it asks: Always, # whenever the computer is on (the default, for a server or a # dedicated machine), or Auto, only while nobody is using it; without # a terminal to ask in, Always. On a Mac, Auto. A computer linked # already keeps the mode it has unless HIPS_MODE says otherwise. With # HIPS_DATA_CENTER=1 a Linux server is declared a data-center server # before it is linked, works Always, and nothing is asked. # 7. Hands over to `hips-provider setup`, which finds the GPUs, links # this computer to your HIPS account (a code and a QR code to approve # at https://console.hips.com/device) and says what runs next. On a # Mac it also starts the menu bar app. With HIPS_ENROLLMENT_CODE a # Linux server is linked with that code instead, with nobody # approving it. # # Read it before you run it: # # curl -fsSL https://hips.com/install.sh -o install.sh # less install.sh # bash install.sh # # It is the install.sh of the newest release, listed in its SHA256SUMS. # # Settings, as environment variables after the pipe # (curl -fsSL https://hips.com/install.sh | HIPS_NO_LINK=1 bash): # # HIPS_VERSION=x.y.z Install that release instead of the newest. # HIPS_MODE=always How this computer works for HIPS, without the # HIPS_MODE=auto question: always, whenever it is on; auto, only # while nobody is using it. # HIPS_NO_LINK=1 Install without linking (machine images, CI). # Link later with: sudo hips-provider setup # HIPS_DATA_CENTER=1 Declare this Linux server a data-center server # before it is linked, as hips-provider config set # data_center true does: it works whenever it is on # and healthy, and nothing is asked. A computer # linked already keeps what it has. # HIPS_ENROLLMENT_CODE Link this Linux server with an enrollment code HIPS # gave you, with nobody approving it. The installer # takes it out of its environment at once, so no # program it starts sees it, and hands it to # hips-provider on standard input, never as an # argument. Read it from a file only root can read, # so it is not typed where it is kept: # HIPS_ENROLLMENT_CODE="$(cat /root/hips-enrollment-code)" # or link afterwards from that file: # sudo hips-provider connect --enrollment-code-file /root/hips-enrollment-code # A code typed on the command line stays in the # shell's history, and while it is linking the code # is in the memory of the programs that use it. # HIPS_RELEASES_BASE For testing only: another address laid out as the # releases are, /latest/download/ and # /download/v/. # # Exit codes: # # 0 Installed and running, and linked, linked already, or not linked # because HIPS_NO_LINK=1 asked so. # 1 This computer is not supported. # 2 A setting or an argument is not valid. # 3 A download failed. # 4 A download does not match SHA256SUMS, or cannot be checked. # 5 The package could not be installed. # 6 Installed, but the service is not running (or, with a release # before 0.1.7, systemd does not run here). # 7 Installed and running, but this computer is not linked yet. # 8 Installed, but this computer has no GPU HIPS supports, so it # cannot work for HIPS. # 9 Installed and running, but HIPS refused the enrollment code (used # up, expired, revoked, unknown, or its account no longer enrolling # Certified pool devices), so this computer is not linked. # # To remove HIPS Provider: sudo hips-provider remove set -u RELEASES=https://github.com/hips-ai/hips-provider-releases/releases DOWNLOAD_PAGE=https://hips.com/download APPROVAL_PAGE=https://console.hips.com/device # The oldest glibc each Linux architecture's packages run on, and the # oldest macOS the Mac package installs on. GLIBC_FLOOR_X86_64=2.34 GLIBC_FLOOR_AARCH64=2.34 MACOS_FLOOR=13.0 MAC_APP="/Applications/HIPS Provider.app" MAC_DAEMON=com.hips.provider MAC_RECEIPT=com.hips.provider LINUX_SERVICE=hips-provider.service # HIPS's release keys: their fingerprints and certificates, written into # each released installer by the release build from the keys the release # was signed with. An installer without them, a copy from the source # repository, checks SHA256SUMS by its SHA-256s alone, as before releases # were signed. RELEASE_KEY_FINGERPRINTS="6775B6C0C0E1B9A1FBCFBD168ABDB676D4A546F4" RELEASE_KEY_CERTIFICATES='-----BEGIN PGP PUBLIC KEY BLOCK----- mQINBGruJJIBEACVIuYs2Co1qLLJ3/TMIgbfRLKX9j9pcBmKdbYjcDF2C48EQ8fn g/007mR39rRsxLHTsG7PHfuuDyR1rVDQ9Ewql9ErCIqH0l7rbRX9UfBNL3pSohA4 WUDXnkqe5r8LTE52OSuge2ajKt1l0S2Y3xxSeUMwR7dt1cD5AOPEwec9t8LNQ2Pn dXd93tc+urV4eotBuK1Tcy8dttkyKDbmXRbG7tFs/H3Ta7qpxbAgqTB/Et38IfMO JVLVuzynMo7Jkhb7ufu9AZw/VV+Vyvhs0aG/5nUnz9nsiurOCawyVJC5PGAA+w+y eXfJZ+uBzf2Z/ftrROGfqm8hcftozbOBdhb+KitSyg8Q0ju/53JceSE+1VfwKNjt sf89KUqNmHnVPJ1IYzKwtn/Mak0S1VQ5D4tt5wk0Qzi8mA2WDxKhSSzJlLvQCSQL K9AZYhulPKruqOEdnYjiXBfI96MgLEHDTGdIwcqeM67DVdrBvSayRkV0g4795hc/ O6sBNXHaUUsmbVDBM0++CwVKE9R/mBMSlTdsrDVPZvnhGG00LN087W2eK4WSSwtC 9n9FKnPitdLY1ulDD++IIIWjEYLslv0O4RSbkT6Q4ft40s0z0YV2LGfgHrjQa757 uI8A8X6sJvJv3ynTK04bBhwCbKA1RlNYO7Ak4bEsLLIFRcbfr2F++Q/7zwARAQAB tC1ISVBTIFByb3ZpZGVyIHJlbGVhc2VzIDxlbmdpbmVlcmluZ0BoaXBzLmNvbT6J AjkEEwEIACMWIQRndbbAwOG5ofvPvRaKvbZ21KVG9AUCau4kkgIbAwIVCAAKCRCK vbZ21KVG9A2UD/9k2LLcEJ2H7hG7cCk2S94d1zWVEy3IwJc6izC6s7S4fHOUZ6Sh 1hbC5PTwibY7YKifarVvpXpsI7iX1CzpWAcnBbgdVclv928UbGFBZthMB95zq5bM nT0QdcG6ISBYWxEasEX+1WoktjObrfK0lqHIlKebraw2MBVFujO0IcJdjU+G1PH5 bcNgd80vLZ8rqBAxPTbXjr+gmV5th2M6Vz93PRUdOAh1Yr+mT0RrJenxqncuHnht DBezfDXujWFaCPJGRsGJlGx8+m6kI0NMg2vtmLCKek5m+Mg20kMs+D1N2lnhqktZ AmpMwiiDzNWm1q6PoQ1pDBu8/IyfEBlYhKKdTA6Fg6ym7ntW1tjI3X+JeV69ggWE /HPfZ1tAnRUIgfNPUBZVQa+rqOkXXqgbWbp1EXw1hVUm5TKLU2/YNea6P6jNz+LL 4HLbCGOE2uC8crUYTKT7RE47Lc/UJvvAtCg1lNfY/FdaYRpVBJGMCzoLBQFKxsbd 4A5PzaL8dJKvmz6nsej6VLl519fHgMgK8FDaDL/abirBgmI0lnRVTeynCxASOKsF ysNZW8zSWvZl9ub3Q5O1DitRTDxJkLU/Z5UMO21yXSO2Tp/L8JRF8NSxxys0Jmoo /MWXDEsTpCM1NYjEAJ34sWmzupTgGCGOAFRQlC2VMg+gl440icXSCCDoIQ== =JbpT -----END PGP PUBLIC KEY BLOCK-----' # The administrators group the package makes, whose members, with root, # use the daemon's socket on a machine with no desktop session. ADMIN_GROUP=hips-provider-admin # The package tools run with no question to ask (debconf, needrestart, # apt-listchanges, apt-listbugs, ucf) and in English, which this script # reads. PM_ENV="DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=l NEEDRESTART_SUSPEND=1 APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none UCF_FORCE_CONFFOLD=1 LC_ALL=C" # How long a package system another program holds (automatic updates, # PackageKit) is waited for, in seconds. LOCK_WAIT_S=900 # The space a download needs, and the space the install needs beyond the # package's own size, in KiB. DOWNLOAD_ROOM_KB=65536 INSTALL_ROOM_KB=51200 say() { printf '%s\n' "$*"; } step() { printf '\n%s\n' "$*"; } fail() { fail_code="$1" shift # Once HIPS Provider is installed, the system's notes come first. [ "${installed_here:-0}" = 1 ] && show_notes printf '\nhips-provider install: %s\n' "$*" >&2 exit "$fail_code" } usage() { say "HIPS Provider: the one-line installer for Linux and macOS." say "" say " curl -fsSL https://hips.com/install.sh | bash" say "" say "Settings, as environment variables after the pipe:" say " HIPS_VERSION=x.y.z install that release instead of the newest" say " HIPS_NO_LINK=1 install without linking; link later with: sudo hips-provider connect" say " HIPS_DATA_CENTER=1 declare this Linux server a data-center server before it is linked" say " HIPS_ENROLLMENT_CODE link this Linux server with an enrollment code, with nobody approving it" say " HIPS_RELEASES_BASE for testing only: another releases address" say "" say "Remove HIPS Provider with: sudo hips-provider remove" } # make_tmp: a private temporary folder, in the first of TMPDIR, /tmp, # /var/tmp and the home folder that can be written and has room. make_tmp() { for tmp_root in "${TMPDIR:-}" /tmp /var/tmp "${HOME:-}"; do [ -n "$tmp_root" ] && [ -d "$tmp_root" ] || continue tmp_free="$(df -Pk "$tmp_root" 2>/dev/null | awk 'NR == 2 { print $4 }')" case "$tmp_free" in '' | *[!0-9]*) continue ;; esac [ "$tmp_free" -ge "$DOWNLOAD_ROOM_KB" ] || continue tmp_try="$(umask 077 && mktemp -d "$tmp_root/hips-provider-install.XXXXXX" 2>/dev/null)" || continue if (: >"$tmp_try/write-test") 2>/dev/null; then rm -f "$tmp_try/write-test" tmp="$tmp_try" return 0 fi rmdir "$tmp_try" 2>/dev/null done return 1 } # Run by the EXIT trap. # shellcheck disable=SC2329 cleanup() { if [ -n "${sudo_keeper:-}" ]; then kill "$sudo_keeper" 2>/dev/null fi if [ -n "${tmp:-}" ] && [ -d "$tmp" ]; then rm -rf "$tmp" fi } have() { command -v "$1" >/dev/null 2>&1; } # as_root COMMAND...: the command as root, through sudo unless this already # is root. as_root() { if [ "$uid" = 0 ]; then "$@" else sudo "$@" fi } # version_at_least A B: whether the version A is B or newer. version_at_least() { awk -v a="$1" -v b="$2" 'BEGIN { na = split(a, x, "."); nb = split(b, y, ".") n = na > nb ? na : nb for (i = 1; i <= n; i++) { if (x[i] + 0 > y[i] + 0) exit 0 if (x[i] + 0 < y[i] + 0) exit 1 } exit 0 }' } is_version() { printf '%s\n' "$1" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' } glibc_version() { glibc="$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{ print $2 }')" if [ -z "$glibc" ]; then glibc="$(ldd --version 2>&1 | head -n 1 | awk '{ print $NF }')" fi case "$glibc" in [0-9]*.[0-9]*) printf '%s' "$glibc" ;; *) return 1 ;; esac } # fetch URL FILE: downloads URL to FILE, failing on an HTTP error. fetch() { rm -f "$2" if [ "$downloader" = curl ]; then # A transfer that stalls (under 1 KB/s for 30 seconds) is a failed try. curl -fsSL --proto "$protocols" --proto-redir "$protocols" --retry 3 --connect-timeout 20 \ --speed-limit 1024 --speed-time 30 -o "$2" "$1" else wget -q --tries=3 --timeout=30 -O "$2" "$1" fi fetched=$? if [ "$fetched" -ne 0 ] || [ ! -s "$2" ]; then rm -f "$2" return 1 fi return 0 } # fetch_failure URL: the last download's failure, from curl's or wget's # exit code, with what to check. fetch_failure() { case "$downloader:$fetched" in *:0) why="it came back empty" ;; curl:5 | curl:6) why="the name of its server could not be resolved; check this computer's DNS, and its proxy if it uses one" ;; curl:7) why="its server could not be reached; check this computer's network, and its proxy if it uses one" ;; curl:28) why="it stalled or timed out; check this computer's network" ;; curl:35 | curl:51 | curl:53 | curl:54 | curl:58 | curl:59 | curl:60 | curl:77 | curl:80 | curl:82 | curl:83 | curl:90 | curl:91 | wget:5) why="its server's TLS certificate could not be checked; check this computer's date and time, and that its CA certificates are installed (the ca-certificates package)" ;; curl:22 | wget:8) why="the server answered with an error" ;; wget:4) why="a network failure (the server not reached, its name not resolved, or the download stalled); check this computer's network, and its proxy if it uses one" ;; *) why="$downloader's error $fetched" ;; esac say "could not download $1: $why" } sha256_of() { if have sha256sum; then sha256sum "$1" | awk '{ print $1 }' else shasum -a 256 "$1" | awk '{ print $1 }' fi } # sums_valid: the downloaded SHA256SUMS is a list of SHA-256 sums, not a # page a captive portal or a proxy answered with. sums_valid() { grep -q -E '^[0-9a-f]{64} [ *]?[^ ]+$' "$tmp/SHA256SUMS" \ || fail 4 "what came back as $sums_url is not a list of SHA-256 sums (a proxy or a network sign-in page may have answered instead of GitHub), so nothing was installed. Check this computer's network, then run it again." } # signed_release: whether this installer carries HIPS's release keys. signed_release() { [ -n "$RELEASE_KEY_FINGERPRINTS" ]; } # write_release_keys: each of this installer's certificates into a file of # its own in the temporary folder (release-key-.asc, for rpm), and all # of them as one binary keyring (release-keys.gpg, for gpgv and sqv). write_release_keys() { [ -s "$tmp/release-keys.gpg" ] && return 0 printf '%s\n' "$RELEASE_KEY_CERTIFICATES" | awk -v dir="$tmp" ' /^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ { n++; f = dir "/release-key-" n ".asc" } f != "" { print > f } /^-----END PGP PUBLIC KEY BLOCK-----$/ { close(f); f = "" }' : >"$tmp/release-keys.gpg" for cert in "$tmp"/release-key-*.asc; do [ -s "$cert" ] || return 1 sed -e '/^-----/d' -e '/^=/d' -e '/^[[:space:]]*$/d' "$cert" | base64 -d >>"$tmp/release-keys.gpg" 2>/dev/null || return 1 done [ -s "$tmp/release-keys.gpg" ] } # sums_signed: with release keys in this installer, the release's # SHA256SUMS.sig, checked where the system has a verifier: sqv or gpgv, # one of which every apt system has (apt checks its own repositories with # it). Where neither is (an rpm system without GnuPG, a Mac), rpm checks # the package's own HIPS signature (rpm_trust_key), and a Mac's package is # checked by its SHA-256 alone until the Mac package is signed. sums_signed() { signed_release || return 0 sig_url="$base/download/v$version/SHA256SUMS.sig" fetch "$sig_url" "$tmp/SHA256SUMS.sig" \ || fail 4 "$(fetch_failure "$sig_url"), so HIPS's signature on SHA256SUMS could not be checked and nothing was installed. This installer installs only releases HIPS signed; see $DOWNLOAD_PAGE for the others." write_release_keys \ || fail 4 "this installer's HIPS release key could not be read, so nothing was installed. Download the installer again from $DOWNLOAD_PAGE." signer="" if have sqv; then verifier=sqv signer="$(sqv --keyring "$tmp/release-keys.gpg" "$tmp/SHA256SUMS.sig" "$tmp/SHA256SUMS" 2>"$tmp/sqv.log" | head -n 1)" elif have gpgv; then verifier=gpgv mkdir -m 700 "$tmp/gnupg" 2>/dev/null gpgv --homedir "$tmp/gnupg" --keyring "$tmp/release-keys.gpg" --status-fd 1 "$tmp/SHA256SUMS.sig" "$tmp/SHA256SUMS" >"$tmp/gpgv.status" 2>"$tmp/gpgv.log" signer="$(sed -n 's/^\[GNUPG:\] VALIDSIG \([0-9A-F]*\) .*/\1/p' "$tmp/gpgv.status" | head -n 1)" elif [ "$family" = deb ]; then fail 4 "this system has neither sqv nor gpgv, which apt itself uses to check its repositories, so HIPS's signature on SHA256SUMS cannot be checked and nothing was installed. Install one (${SUDO-sudo }apt-get install gpgv), then run the installer again." elif [ "$family" = rpm ]; then say " SHA256SUMS.sig: no sqv or gpgv here, so rpm checks the package's own HIPS signature instead." return 0 else say " SHA256SUMS.sig: this Mac has no OpenPGP verifier, so the package is checked by its SHA-256 alone." return 0 fi for fingerprint in $RELEASE_KEY_FINGERPRINTS; do if [ -n "$signer" ] && [ "$signer" = "$fingerprint" ]; then say " SHA256SUMS is signed by HIPS (key $signer, checked with $verifier)." return 0 fi done fail 4 "SHA256SUMS is not signed by HIPS's release key ($verifier did not accept SHA256SUMS.sig), so nothing was installed. Run it again; if it fails the same way, download the package from $DOWNLOAD_PAGE." } # sum_of NAME: NAME's SHA-256 in the downloaded SHA256SUMS. sum_of() { awk -v n="$1" '$2 == n || $2 == "*" n { print $1; exit }' "$tmp/SHA256SUMS" } # package_name [VERSION]: the release's file for this computer, unversioned # as releases/latest/download names it, or of VERSION. package_name() { case "$family:${1:-}" in deb:) say "hips-provider_$deb_arch.deb" ;; deb:*) say "hips-provider_${1}_$deb_arch.deb" ;; rpm:) say "hips-provider.$rpm_arch.rpm" ;; rpm:*) say "hips-provider-$1.$rpm_arch.rpm" ;; pkg:) say "HIPS-Provider-mac-arm64.pkg" ;; pkg:*) say "HIPS-Provider-$1-mac-arm64.pkg" ;; esac } # version_of NAME: the version in a versioned file name, or nothing. version_of() { case "$family" in deb) candidate="${1#hips-provider_}" && candidate="${candidate%_"$deb_arch".deb}" ;; rpm) candidate="${1#hips-provider-}" && candidate="${candidate%."$rpm_arch".rpm}" ;; *) candidate="${1#HIPS-Provider-}" && candidate="${candidate%-mac-arm64.pkg}" ;; esac if is_version "$candidate"; then say "$candidate"; fi } installed_version() { case "$family" in deb) # shellcheck disable=SC2016 dpkg-query -W -f='${Status} ${Version}\n' hips-provider 2>/dev/null \ | awk '$3 == "installed" || $3 == "triggers-awaited" || $3 == "triggers-pending" { print $4; exit }' ;; rpm) rpm -q --qf '%{VERSION}\n' hips-provider 2>/dev/null | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 ;; *) pkgutil --pkg-info "$MAC_RECEIPT" 2>/dev/null | sed -n 's/^version: //p' | head -n 1 ;; esac } # package_state: HIPS Provider's package, at the version being installed, # as the package system records it, which alone says whether the install # worked, whatever the tools' exit codes: set-up (installed and its setup # run; on dpkg also when it only waits for another package's trigger), # unpacked (its files there, its setup not run or failed), or absent. package_state() { if [ "$family" = deb ]; then # shellcheck disable=SC2016 dpkg-query -W -f='${Status} ${Version}\n' hips-provider 2>/dev/null | awk -v v="$version" ' $4 != v { print "absent"; exit } $3 == "installed" || $3 == "triggers-awaited" || $3 == "triggers-pending" { print "set-up"; exit } $3 == "unpacked" || $3 == "half-configured" || $3 == "half-installed" { print "unpacked"; exit } { print "absent"; exit } ' elif [ "$(rpm -q --qf '%{VERSION}' hips-provider 2>/dev/null)" = "$version" ]; then say set-up else say absent fi } # as_pm COMMAND...: a package tool as root, with PM_ENV and the proxy # settings of the person running this, which sudo would drop (run through # run_logged). # shellcheck disable=SC2329 as_pm() { # shellcheck disable=SC2086 as_root env $PM_ENV \ ${http_proxy:+"http_proxy=$http_proxy"} ${https_proxy:+"https_proxy=$https_proxy"} \ ${no_proxy:+"no_proxy=$no_proxy"} ${HTTP_PROXY:+"HTTP_PROXY=$HTTP_PROXY"} \ ${HTTPS_PROXY:+"HTTPS_PROXY=$HTTPS_PROXY"} ${NO_PROXY:+"NO_PROXY=$NO_PROXY"} "$@" } # run_logged LOG COMMAND...: the command's output shown as it comes and # kept in LOG, its input empty; returns its exit code. run_logged() { run_log="$1" shift { "$@" &1; printf '%s\n' "$?" >"$run_log.rc"; } | tee "$run_log" run_rc="$(cat "$run_log.rc" 2>/dev/null)" return "${run_rc:-1}" } # note TEXT: something on this system for its owner to fix, which is not # HIPS Provider's and does not stop it; listed once the install is done. note() { notes="${notes:-} - $* " } # A tool's message that another program holds the package system: dpkg's, # apt's, rpm's and dnf's locks. PM_LOCKED="locked by another process|Could not get lock|Unable to lock|Unable to acquire the dpkg frontend lock|is held by process|can't create transaction lock|can't create keyring lock|Another transaction is in progress|Failed to obtain rpm transaction lock" # pm_held LOG: whether a package tool's messages in LOG say another # program holds the package system. rpm says "can't create transaction # lock" also where its database cannot be written at all (a read-only # system), which no wait cures. pm_held() { grep -E "$PM_LOCKED" "$1" 2>/dev/null | grep -q -v -E 'Read-only file system|Permission denied' } # find_holder LOG: the program that holds the package system, into # holder (its name and pid) and holder_pid: from a tool's message, or # where it names none (rpm), the package tool that runs. find_holder() { holder_pid="$(sed -n 's/.*process with pid \([0-9][0-9]*\).*/\1/p; s/.*held by process \([0-9][0-9]*\).*/\1/p' "$1" | head -n 1)" if [ -z "$holder_pid" ]; then running="$(for holder_comm in /proc/[0-9]*/comm; do holder_id="${holder_comm#/proc/}" printf '%s %s\n' "$(cat "$holder_comm" 2>/dev/null)" "${holder_id%/comm}" done)" for holder_name in rpm dnf dnf5 dnf-automatic yum microdnf dpkg apt-get apt unattended-upgr packagekitd; do holder_pid="$(printf '%s\n' "$running" | awk -v n="$holder_name" '$1 == n { print $2; exit }')" [ -n "$holder_pid" ] && break done fi if [ -n "$holder_pid" ] && [ -r "/proc/$holder_pid/comm" ]; then holder="$(cat "/proc/$holder_pid/comm") (pid $holder_pid)" elif [ -n "$holder_pid" ]; then holder="pid $holder_pid" else holder="another program" fi } # wait_lock LOG: one more wait for a package system another program holds, # said once: until that program ends, or 30 seconds at most (10 when it # is not known) before the tool is tried again, bounded by LOCK_WAIT_S in # all. wait_lock() { find_holder "$1" if [ "$lock_waited" = 0 ]; then say " The package system is busy: $holder holds it. Waiting for it, up to $((LOCK_WAIT_S / 60)) minutes." fi lock_round=0 while :; do if [ "$lock_waited" -ge "$LOCK_WAIT_S" ]; then fail 5 "the package system stayed busy for $((LOCK_WAIT_S / 60)) minutes: $holder holds it, so nothing was installed. Run the installer again once it is done; automatic updates usually finish within minutes." fi sleep 5 lock_waited=$((lock_waited + 5)) lock_round=$((lock_round + 5)) if [ -n "$holder_pid" ] && [ -d "/proc/$holder_pid" ]; then [ "$lock_round" -lt 30 ] && continue elif [ -z "$holder_pid" ]; then [ "$lock_round" -lt 10 ] && continue fi break done } # pm_run LOG COMMAND...: a package tool through run_logged, run again # while another program holds the package system, up to LOCK_WAIT_S in # all; returns its exit code. pm_run() { pm_log="$1" shift while :; do run_logged "$pm_log" "$@" && return 0 pm_rc=$? pm_held "$pm_log" || return "$pm_rc" wait_lock "$pm_log" done } # pm_retry LOG COMMAND...: pm_run, run again where the package manager's # messages say the network failed a download (NET_FLAKY), after 5, 15 and # 45 seconds; any other failure, or the last, returned as it is. pm_retry() { retry_log="$1" shift for retry_wait in 5 15 45 ""; do pm_run "$retry_log" "$@" && return 0 retry_rc=$? if [ -z "$retry_wait" ] || ! grep -q -E "$NET_FLAKY" "$retry_log" 2>/dev/null; then return "$retry_rc" fi say " The download failed on the network; trying again in $retry_wait seconds." sleep "$retry_wait" done } # rpm_check: rpm's check of the package (rpm -U --test), its messages kept # in rpm-test.log for what it lacks and not shown, waited for as pm_run # waits. rpm_check() { while :; do # shellcheck disable=SC2086 as_pm rpm $rpm_options ${rpm_verify:+--define "$rpm_verify"} --test "$tmp/$file" "$tmp/rpm-test.log" 2>&1 && return 0 pm_held "$tmp/rpm-test.log" || return 1 wait_lock "$tmp/rpm-test.log" done } # listing NAMES: the names as a list ("a", "a and b", "a, b and c"). listing() { case "$#" in 1) say "$1" ;; 2) say "$1 and $2" ;; *) listed="$1" shift while [ "$#" -gt 1 ]; do listed="$listed, $1" shift done say "$listed and $1" ;; esac } # A package tool's messages that a fresh read of the package lists can # cure: a package apt does not know, or a file the mirror no longer has. STALE_LISTS='Unable to locate package|has no installation candidate|is not available|Unable to fetch some archives|Failed to fetch|Hash Sum mismatch|unauthenticated packages' # A repository that could not be reached. UNREACHED='Failed to fetch|Unable to fetch|Could not connect|Could not resolve|Temporary failure resolving|Unable to connect|Connection failed|Curl error|Cannot download|Failed to download metadata|Errors during downloading metadata' # A download the network failed, which the same run may get a moment # later: a name not resolved, a connection refused, cut or timed out, a # mirror's 502, 503 or 504; never a package a repository does not have. NET_FLAKY='Temporary failure resolving|Could not resolve|Could not connect|Connection timed out|Connection failed|Connection reset|Unable to connect|Operation too slow|50[234] +(Bad Gateway|Service Unavailable|Gateway Time)|Curl error \((6|7|28|35|52|56)\)|Cannot download repomd|Failed to download metadata|Errors during downloading metadata' # dep_met NAME OP VERSION: whether this system has NAME set up, at a # version that meets OP VERSION ("-" for any), or provided by an installed # package where no version is asked. dep_met() { # shellcheck disable=SC2016 dep_version="$(dpkg-query -W -f='${Status}|${Version}\n' "$1" 2>/dev/null \ | awk -F'|' '{ split($1, s, " ") } s[3] == "installed" || s[3] == "triggers-awaited" || s[3] == "triggers-pending" { print $2; exit }')" if [ -z "$dep_version" ]; then [ "$2" = - ] || return 1 # shellcheck disable=SC2016 dpkg-query -W -f='${Status}|${Provides}\n' 2>/dev/null | awk -F'|' -v n="$1" ' { split($1, s, " ") } s[3] != "installed" { next } { k = split($2, p, ","); for (i = 1; i <= k; i++) { q = p[i]; gsub(/^[ \t]+/, "", q); sub(/[ \t(].*/, "", q); if (q == n) { found = 1 } } } END { exit found ? 0 : 1 }' return fi [ "$2" = - ] && return 0 dpkg --compare-versions "$dep_version" "$2" "$3" } # deb_unmet FILE: the package's dependencies this system does not meet, # one a line: the first choice's name, a tab, the dependency as written. deb_unmet() { dpkg-deb -f "$1" Depends 2>/dev/null | tr ',' '\n' | while IFS= read -r clause; do clause="$(printf '%s' "$clause" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')" [ -n "$clause" ] || continue first="" met=1 printf '%s\n' "$clause" | tr '|' '\n' | awk '{ s = $0; name = s; op = "-"; ver = "-" i = index(s, "(") if (i) { name = substr(s, 1, i - 1); r = substr(s, i + 1); sub(/\).*/, "", r) gsub(/^[ \t]+|[ \t]+$/, "", r) m = match(r, /[0-9A-Za-z~]/) if (m) { op = substr(r, 1, m - 1); ver = substr(r, m); gsub(/[ \t]/, "", op); gsub(/[ \t]/, "", ver) } } gsub(/[ \t]/, "", name); sub(/:.*/, "", name) print name, op, ver }' >"$tmp/choices" while read -r dep_name dep_op dep_ver; do [ -n "$first" ] || first="$dep_name" if dep_met "$dep_name" "$dep_op" "$dep_ver"; then met=0 break fi done <"$tmp/choices" [ "$met" = 0 ] || printf '%s\t%s\n' "$first" "$clause" done } # deb_explain NAMES: why apt-get did not get HIPS Provider's dependencies, # from its messages and this system, with what to run. deb_explain() { needs="$(listing "$@")" for dep_name in "$@"; do if apt-mark showhold 2>/dev/null | grep -qx "$dep_name"; then say "HIPS Provider needs $dep_name, which is held on this system (apt-mark showhold), so apt-get will not install or change it. Release it with: ${SUDO-sudo }apt-mark unhold $dep_name, then run the installer again." return fi # shellcheck disable=SC2016 case "$(dpkg-query -W -f='${Status}' "$dep_name" 2>/dev/null)" in *half-configured | *unpacked | *half-installed) say "HIPS Provider needs $dep_name, which is on this system but not set up. Finish it with: ${SUDO-sudo }dpkg --configure -a (its messages say what fails), then run the installer again." return ;; esac done if grep -q 'dpkg was interrupted' "$tmp/apt.log" 2>/dev/null; then say "HIPS Provider needs $needs, and apt-get installs nothing while an earlier dpkg run on this system is unfinished. Finish it with: ${SUDO-sudo }dpkg --configure -a, then run the installer again." elif grep -q -E 'Unmet dependencies|--fix-broken' "$tmp/apt.log" 2>/dev/null; then say "HIPS Provider needs $needs, and apt-get installs nothing while other packages of this system have unmet dependencies (above). Fix them with: ${SUDO-sudo }apt --fix-broken install, then run the installer again." elif grep -q -E 'held packages|Held packages' "$tmp/apt.log" 2>/dev/null; then say "HIPS Provider needs $needs, and getting it would change packages held on this system (apt-mark showhold). Release the holds apt-get names above with ${SUDO-sudo }apt-mark unhold, then run the installer again." elif grep -q -E 'Unable to fetch some archives|Failed to fetch' "$tmp/apt.log" 2>/dev/null; then say "HIPS Provider needs $needs, and apt-get could not download it from this system's repositories (above). Check that this computer reaches them, and its proxy if it uses one, then run the installer again." elif grep -q -E "$UNREACHED" "$tmp/update.log" 2>/dev/null; then say "HIPS Provider needs $needs, and no repository apt-get could read offers it: apt-get update could not read some of them (above). Check that this computer reaches them, and its proxy if it uses one, or turn on the distribution's own repositories, then run the installer again." elif grep -q -E 'Unable to locate package|has no installation candidate|is not available' "$tmp/apt.log" 2>/dev/null; then say "HIPS Provider needs $needs, and no repository this system reads offers it (above). Turn on the distribution's own repositories, then run the installer again." else say "HIPS Provider needs $needs, which apt-get could not install (its messages are above). Fix what it names, then run the installer again." fi } # deb_get_deps NAMES: HIPS Provider's missing dependencies, and nothing # else, from the repositories with apt-get; the lists are read again only # when apt-get's messages say they are missing or out of date. deb_get_deps() { apt_options="-y -q --no-install-recommends -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold" # shellcheck disable=SC2086 pm_retry "$tmp/apt.log" as_pm apt-get install $apt_options "$@" && return 0 if grep -q 'dpkg was interrupted' "$tmp/apt.log"; then # An interrupted dpkg run leaves its journal, which apt-get refuses to # run past and any dpkg run takes up first, as dpkg -i of HIPS # Provider would. An empty --set-selections is such a run, and changes # nothing else. say " An earlier dpkg run on this system stopped before it finished; dpkg takes up its record first, as its next run would." pm_run "$tmp/journal.log" as_pm dpkg --set-selections || true # shellcheck disable=SC2086 pm_retry "$tmp/apt.log" as_pm apt-get install $apt_options "$@" && return 0 fi if grep -q -E "$STALE_LISTS" "$tmp/apt.log"; then say " Reading the package lists (apt-get update)." # apt-get update ends well when some repositories could not be read, # with a warning; either way they are named for the owner. update_rc=0 pm_run "$tmp/update.log" as_pm apt-get update -q || update_rc=$? if [ "$update_rc" != 0 ] || grep -q -E "$UNREACHED|Some index files failed" "$tmp/update.log"; then note "apt-get update could not read every repository this system lists (above). HIPS Provider did not need them; fix or remove the ones it names in /etc/apt/sources.list.d." fi # shellcheck disable=SC2086 pm_retry "$tmp/apt.log" as_pm apt-get install $apt_options "$@" fi } # deb_install: HIPS Provider's .deb, by dpkg and on its own, which sets up # no other package and reads no repository; apt-get only for a dependency # this system lacks. Judged by the package's own state alone. deb_install() { deb_unmet "$tmp/$file" >"$tmp/unmet" if [ -s "$tmp/unmet" ]; then set -- while IFS="$(printf '\t')" read -r dep_name _; do set -- "$@" "$dep_name" done <"$tmp/unmet" if [ -z "$manager" ]; then fail 5 "HIPS Provider needs $(listing "$@"), which this system does not have set up, and this system has no apt-get to get it. Install it, then run the installer again." fi if [ "$#" = 1 ]; then say " HIPS Provider needs $1, which this system does not have set up yet; getting it with apt-get." else say " HIPS Provider needs $(listing "$@"), which this system does not have set up yet; getting them with apt-get." fi deb_get_deps "$@" deb_unmet "$tmp/$file" >"$tmp/unmet" [ -s "$tmp/unmet" ] && fail 5 "$(deb_explain "$@")" fi pm_run "$tmp/dpkg.log" as_pm dpkg --force-confdef --force-confold -i "$tmp/$file" case "$(package_state)" in set-up) ;; unpacked) if grep -q -E 'No space left on device' "$tmp/dpkg.log"; then fail 5 "dpkg could not set up $file: the disk is full (above). Free some space, then run the installer again." fi fail 5 "dpkg unpacked $file, but its setup failed (its messages are above), so HIPS Provider is not installed. Run the installer again; if it fails the same way, send the messages above to HIPS support." ;; *) if grep -q -E 'No space left on device' "$tmp/dpkg.log"; then fail 5 "dpkg could not install $file: the disk is full (above). Free some space, then run the installer again." fi if grep -q -E 'Read-only file system' "$tmp/dpkg.log"; then fail 5 "dpkg could not write to this system: part of it is read-only (above), so nothing was installed. HIPS Provider needs /opt, /usr and /var writable; on an image-based or read-only system, see $DOWNLOAD_PAGE." fi owner="$(sed -n "s/.*trying to overwrite '\([^']*\)', which is also in package \([^ ]*\).*/\2 \1/p" "$tmp/dpkg.log" | head -n 1)" if [ -n "$owner" ]; then fail 5 "$file installs ${owner#* }, which belongs to another package of this system, ${owner%% *} (above), so nothing was installed. Remove that package if you no longer need it (${SUDO-sudo }apt remove ${owner%% *}), then run the installer again." fi fail 5 "dpkg could not install $file (its messages are above), so HIPS Provider is not installed." ;; esac } # rpm_explain NAMES: why dnf did not get HIPS Provider's dependencies. rpm_explain() { needs="$(listing "$@")" if grep -q -E 'There are no enabled repositories|No repositories available' "$tmp/dnf.log" 2>/dev/null; then say "HIPS Provider needs $needs, and this system has no repository to get it from. On RHEL, register it (${SUDO-sudo }subscription-manager register) or turn on a repository that provides it, then run the installer again." elif grep -q -i -E "$UNREACHED" "$tmp/dnf.log" 2>/dev/null; then say "HIPS Provider needs $needs, and $manager could not read this system's repositories to get it (above). Check that this computer reaches them, and its proxy if it uses one, then run the installer again." elif grep -q -E 'No match for argument|Unable to find a match|No package .* available|nothing provides' "$tmp/dnf.log" 2>/dev/null; then if grep -q 'This system is not registered' "$tmp/dnf.log" 2>/dev/null; then say "HIPS Provider needs $needs, and no repository this system reads provides it: this RHEL system is not registered, so Red Hat's repositories are off. Register it (${SUDO-sudo }subscription-manager register), or turn on a repository that provides it, then run the installer again." else say "HIPS Provider needs $needs, and no repository this system reads provides it (above). Turn on the distribution's own repositories, then run the installer again." fi else say "HIPS Provider needs $needs, which $manager could not install (its messages are above). Fix what it names, then run the installer again." fi } # rpm_trust_key: with release keys in this installer, rpm is given them # (rpmkeys --import), so a system that installs only signed packages # (Fedora 45's %_pkgverify_level) installs HIPS Provider and its later # updates, and rpm is asked to require the package's signature here # whatever this system's setting is. rpm_trust_key() { signed_release || return 0 write_release_keys \ || fail 4 "this installer's HIPS release key could not be read, so nothing was installed. Download the installer again from $DOWNLOAD_PAGE." for cert in "$tmp"/release-key-*.asc; do # rpm's keyring is locked while another installation runs (rpm 6): # waited for as every package system's lock is. while :; do as_pm rpmkeys --import "$cert" "$tmp/rpmkeys.log" 2>&1 && break pm_held "$tmp/rpmkeys.log" \ || fail 5 "rpm did not take HIPS's package key ($(tail -n 1 "$tmp/rpmkeys.log")), so nothing was installed." wait_lock "$tmp/rpmkeys.log" done done rpm_verify="_pkgverify_level all" say " rpm now trusts HIPS's package key ($RELEASE_KEY_FINGERPRINTS) and installs HIPS Provider only with its signature." } # rpm_install: HIPS Provider's .rpm, by rpm and on its own, which reads no # repository and asks no question; dnf only for a dependency this system # lacks. Judged by the package's own state alone. rpm_install() { rpm_options="-U --replacepkgs --oldpackage" rpm_verify="" rpm_trust_key # A tool that waits for a lock by itself (dnf) is bounded where timeout # exists; one that fails on it (rpm) is run again by pm_run. bound="" have timeout && bound="timeout $LOCK_WAIT_S" # What it lacks, from rpm's check. rpm_check awk '/ is needed by / { sub(/^[ \t]+/, ""); sub(/ is needed by .*/, ""); print }' "$tmp/rpm-test.log" >"$tmp/unmet" if [ -s "$tmp/unmet" ]; then set -- while IFS= read -r capability; do set -- "$@" "$capability" done <"$tmp/unmet" if [ -z "$manager" ]; then fail 5 "HIPS Provider needs $(listing "$@"), which this system does not have, and this system has no dnf or yum to get it. Install it, then run the installer again." fi if [ "$#" = 1 ]; then say " HIPS Provider needs $1, which this system does not have; getting it with $manager." else say " HIPS Provider needs $(listing "$@"), which this system does not have; getting them with $manager." fi # shellcheck disable=SC2086 pm_retry "$tmp/dnf.log" as_pm $bound "$manager" install -y --setopt=skip_if_unavailable=True --setopt=install_weak_deps=False "$@" || true if grep -q -i -E 'Failed to download metadata|Cannot download repomd|Curl error|Errors during downloading metadata' "$tmp/dnf.log"; then note "$manager could not read every repository this system lists (above). HIPS Provider did not need them; fix or turn off the ones it names in /etc/yum.repos.d." fi rpm_check grep -q ' is needed by ' "$tmp/rpm-test.log" && fail 5 "$(rpm_explain "$@")" fi # shellcheck disable=SC2086 pm_run "$tmp/rpm.log" as_pm $bound rpm $rpm_options ${rpm_verify:+--define "$rpm_verify"} "$tmp/$file" rpm_rc=$? [ "$(package_state)" = set-up ] && return 0 if [ "$rpm_rc" = 124 ]; then fail 5 "the package system stayed busy for $((LOCK_WAIT_S / 60)) minutes (rpm waited for its transaction lock), so nothing was installed. Run the installer again once the other installation is done." elif signed_release && grep -q -i -E 'does not verify|not signed|NOKEY|signature|digest' "$tmp/rpm.log"; then fail 5 "rpm refused $file: it does not carry a valid HIPS signature (above), so nothing was installed. Run it again; if it fails the same way, download the package from $DOWNLOAD_PAGE." elif grep -q -i -E 'does not verify|not signed|NOKEY|signature' "$tmp/rpm.log"; then fail 5 "this system installs only signed packages (rpm's %_pkgverify_level), and HIPS Provider's packages are not signed yet, so nothing was installed." elif grep -q -E 'conflicts with file from package' "$tmp/rpm.log"; then owner="$(sed -n 's/.*file \([^ ]*\) from install of .* conflicts with file from package \([^ ]*\).*/\2 \1/p' "$tmp/rpm.log" | head -n 1)" owner_name="$(rpm -q --qf '%{NAME}' "${owner%% *}" 2>/dev/null)" fail 5 "$file installs ${owner#* }, which belongs to another package of this system, ${owner_name:-${owner%% *}} (above), so nothing was installed. Remove that package if you no longer need it (${SUDO-sudo }$manager remove ${owner_name:-${owner%% *}}), then run the installer again." elif grep -q -E 'conflicts with' "$tmp/rpm.log"; then fail 5 "$file conflicts with a package on this system (above), so nothing was installed. Remove that package, then run the installer again." elif grep -q -E 'Read-only file system' "$tmp/rpm.log"; then fail 5 "rpm could not write to this system: part of it is read-only (above), so nothing was installed. HIPS Provider needs /opt, /usr and /var writable; on an image-based or read-only system, see $DOWNLOAD_PAGE." elif grep -q -E 'needs .* on the .* filesystem|No space left' "$tmp/rpm.log"; then fail 5 "rpm could not install $file: the disk is full (above). Free some space, then run the installer again." fi fail 5 "rpm could not install $file (its messages are above), so HIPS Provider is not installed." } # read_only_dirs: the folders the install writes (the package system's # records, /usr, /etc, /var, and /opt or / where /opt is missing) that # cannot be written, as root, listed; checked before anything is written, # since the package tools say it unclearly or not at all (Fedora's rpm says # "can't create transaction lock ... (Success)" on a read-only system, # which reads as a lock another program holds). read_only_dirs() { case "$family" in deb) package_db=/var/lib/dpkg ;; rpm) package_db="$(rpm -E '%{_dbpath}' 2>/dev/null)" case "$package_db" in /*) ;; *) package_db=/var/lib/rpm ;; esac ;; *) return 0 ;; esac install_root=/opt [ -d /opt ] || install_root=/ read_only="" for dir in "$package_db" /usr /etc /var "$install_root"; do [ -d "$dir" ] || continue as_root test -w "$dir" /dev/null || read_only="${read_only:+$read_only, }$dir" done say "$read_only" } # room_for_install: the space the package needs where it installs, said # before anything is written. room_for_install() { case "$family" in deb) need_kb="$(dpkg-deb -f "$tmp/$file" Installed-Size 2>/dev/null)" ;; rpm) need_kb="$(($(rpm -qp --qf '%{SIZE}' "$tmp/$file" 2>/dev/null || echo 0) / 1024))" ;; *) return 0 ;; esac case "$need_kb" in '' | *[!0-9]*) return 0 ;; esac room_dir=/opt [ -d /opt ] || room_dir=/ free_kb="$(df -Pk "$room_dir" 2>/dev/null | awk 'NR == 2 { print $4 }')" case "$free_kb" in '' | *[!0-9]*) return 0 ;; esac if [ "$free_kb" -lt $((need_kb + INSTALL_ROOM_KB)) ]; then fail 5 "HIPS Provider needs about $(((need_kb + INSTALL_ROOM_KB) / 1024)) MB in $room_dir, which has $((free_kb / 1024)) MB free, so nothing was installed. Free some space there, then run the installer again." fi } # show_notes: the notes for the owner, once: what this system has that is # not HIPS Provider's and needs its owner, read as the installer leaves it, # after the GPU's prerequisites, which can finish a kernel's setup another # package had stopped (AMD's amdgpu-dkms, decided 2026-10-29), so a note # never names a package that is set up by then. finish() and a failure # once HIPS Provider is installed show them where the run ends before. show_notes() { [ "${notes_shown:-0}" = 1 ] && return 0 notes_shown=1 system_notes if [ -n "${notes:-}" ]; then say "" say " For you to fix on this system. It is not HIPS Provider, which does not need it:" printf '%s' "$notes" fi } # system_notes: what this system has that is not HIPS Provider's and # needs its owner, read once HIPS Provider is installed. system_notes() { [ "$family" = deb ] || return 0 # shellcheck disable=SC2016 unfinished="$(dpkg-query -W -f='${db:Status-Abbrev}|${binary:Package}\n' 2>/dev/null \ | awk -F'|' 'substr($1, 2, 1) ~ /[UFHWt]/ && $2 !~ /^hips-provider(:|$)/ { print $2 }' \ | head -n 12 | tr '\n' ' ' | sed 's/ *$//')" if [ -n "$unfinished" ]; then note "Packages not fully set up: $unfinished. Fix them before this computer restarts, since a kernel or driver package left like this can keep it from starting; ${SUDO-sudo }dpkg --configure -a shows what fails." fi for journal in /var/lib/dpkg/updates/[0-9]*; do if [ -e "$journal" ]; then note "An earlier dpkg run was interrupted. Finish it with: ${SUDO-sudo }dpkg --configure -a" break fi done have apt-get || return 0 env LC_ALL=C apt-get -q check "$tmp/check.log" 2>&1 || true if grep -q 'Unmet dependencies' "$tmp/check.log"; then broken="$(awk '/ : / { print $1 }' "$tmp/check.log" | sort -u | head -n 12 | tr '\n' ' ' | sed 's/ *$//')" note "Packages with unmet dependencies${broken:+: $broken}. Fix them with: ${SUDO-sudo }apt --fix-broken install" fi } # held: whether this system's owner holds HIPS Provider at the version it # has (apt-mark hold, dnf versionlock), which the installer leaves as it is. # shellcheck disable=SC2016 held() { case "$family" in deb) dpkg-query -W -f='${Status}' hips-provider 2>/dev/null | grep -q '^hold ' ;; rpm) cat /etc/dnf/plugins/versionlock.list /etc/yum/pluginconf.d/versionlock.list /etc/dnf/versionlock.toml 2>/dev/null \ | grep -q -E '^!?hips-provider-[0-9]|^ *name *= *"hips-provider"' ;; *) return 1 ;; esac } # admit_account: the account that ran this installer through sudo (or # doas) joins hips-provider-admin, where it is a person's login account # and never root. On a computer with no desktop session the daemon admits # root and the members of that group alone, so without it the commands # printed at the end, which name no sudo for a member, would be refused # for the very account that installed the app. It is an administrator # of this computer already, so the membership gives it nothing it lacked, # and the daemon reads the group's members at each call, so it holds at # once, with no new login. Sets admitted to its name, and MEMBER_SUDO to # nothing, where it is a member. admit_account() { admitted="" if [ "$uid" != 0 ]; then account="$(id -un 2>/dev/null)" else account="${SUDO_USER:-${DOAS_USER:-}}" fi [ -n "$account" ] && login_account "$account" || return 0 if ! in_admin_group "$account"; then if [ "$family" = pkg ]; then as_root dseditgroup -o edit -a "$account" -t user "$ADMIN_GROUP" /dev/null 2>&1 else as_root usermod --append --groups "$ADMIN_GROUP" "$account" /dev/null 2>&1 fi in_admin_group "$account" || return 0 fi admitted="$account" MEMBER_SUDO="" } # login_account NAME: whether NAME is a person's login account: an id at # or above the system's first for people (login.defs' UID_MIN, 1000 where # it names none; 501 on a Mac), never root or the app's service account, # with a shell that admits logins. login_account() { case "$1" in root | hips-provider | _hipsprovider) return 1 ;; esac if [ "$family" = pkg ]; then account_uid="$(id -u "$1" 2>/dev/null)" account_shell="$(dscacheutil -q user -a name "$1" 2>/dev/null | awk '$1 == "shell:" { print $2; exit }')" first_uid=501 else account_entry="$(getent passwd "$1" 2>/dev/null | head -n 1)" account_uid="$(printf '%s\n' "$account_entry" | cut -d: -f3)" account_shell="$(printf '%s\n' "$account_entry" | cut -d: -f7)" first_uid="$(awk '$1 == "UID_MIN" { print $2; exit }' /etc/login.defs 2>/dev/null)" case "$first_uid" in '' | *[!0-9]*) first_uid=1000 ;; esac fi case "$account_uid" in '' | *[!0-9]*) return 1 ;; esac [ "$account_uid" -ne 0 ] && [ "$account_uid" -ge "$first_uid" ] || return 1 case "$account_shell" in */nologin | */false) return 1 ;; esac return 0 } # in_admin_group NAME: whether NAME is a member of hips-provider-admin as # the daemon reads it: listed among its members, or its primary group. in_admin_group() { if [ "$family" = pkg ]; then dseditgroup -o checkmember -m "$1" "$ADMIN_GROUP" >/dev/null 2>&1 return fi group_entry="$(getent group "$ADMIN_GROUP" 2>/dev/null | head -n 1)" [ -n "$group_entry" ] || return 1 case ",$(printf '%s\n' "$group_entry" | cut -d: -f4)," in *",$1,"*) return 0 ;; esac [ "$(id -g "$1" 2>/dev/null)" = "$(printf '%s\n' "$group_entry" | cut -d: -f3)" ] } # masked: whether the owner has masked the service (systemctl mask), which # keeps it from starting and the package from setting it up. masked() { [ "$family" != pkg ] && [ -d /run/systemd/system ] || return 1 case "$(systemctl is-enabled "$LINUX_SERVICE" 2>/dev/null)" in masked*) return 0 ;; esac return 1 } # keep_sudo PID: sudo's timestamp kept fresh while PID runs, so a long wait # for the package system never asks for the password again, or lets # sudo's prompt time out with nobody there. keep_sudo() { while kill -0 "$1" 2>/dev/null; do sudo -n -v 2>/dev/null || return 0 sleep 10 done } service_active() { if [ "$family" = pkg ]; then as_root launchctl print "system/$MAC_DAEMON" /dev/null | grep -q 'state = running' elif [ "${supervised:-0}" = 1 ]; then as_root "$CLI" service status /dev/null 2>&1 else systemctl is-active --quiet "$LINUX_SERVICE" 2>/dev/null fi } wait_active() { waited=0 while [ "$waited" -lt "$1" ]; do service_active && return 0 sleep 1 waited=$((waited + 1)) done service_active } # link_state: linked, not-linked, or unknown while the daemon does not # answer, from the Account line of `hips-provider status`. link_state() { # The status as JSON where the app has it, the Account line otherwise. status_text="$(as_root "$CLI" status --json /dev/null)" && case "$status_text" in *'"linked":true'*) say linked return 0 ;; *'"linked":false'*) say not-linked return 0 ;; esac status_text="$(as_root "$CLI" status /dev/null)" || { say unknown return 0 } account="$(printf '%s\n' "$status_text" | sed -n 's/^ *Account: //p' | head -n 1)" case "$account" in "") say unknown ;; "connected as "* | *", under "*) say linked ;; *) say not-linked ;; esac } wait_daemon() { waited=0 state="$(link_state)" while [ "$state" = unknown ] && [ "$waited" -lt 30 ]; do sleep 1 waited=$((waited + 1)) state="$(link_state)" done } # The menu bar app, for the person at this Mac's screen: started quietly, # as its login item starts it, where the package has not started it (a # package before 0.1.6 does not on an install from the command line); # opening it again changes nothing. start_menu_bar_app() { if [ "$family" != pkg ] || [ ! -d "$MAC_APP" ]; then return 0 fi if [ "$uid" != 0 ] && [ "$(stat -f %Su /dev/console 2>/dev/null)" = "$(id -un)" ] \ && open -g -a "$MAC_APP" --args --background /dev/null 2>&1; then say " The HIPS Provider menu bar app is open." else say " The HIPS Provider menu bar app starts at the next sign-in, or open it from Applications." fi } # Whether a person can be asked: a terminal this script can open. Piped # from curl, the script's own input is the script, so the answer is read # from the terminal itself. Tried in a subshell: a POSIX shell exits when a # redirection of one of its special builtins fails. can_ask() { (exec /dev/null } # choose_mode: how this computer works for HIPS, into `mode` (always or # auto): HIPS_MODE; on a Mac, auto; on Linux, the person's answer, or # always when nobody can be asked or on Enter. choose_mode() { if [ -n "${HIPS_MODE:-}" ]; then mode="$HIPS_MODE" say " Mode: $mode (HIPS_MODE)." return 0 fi if [ "$family" = pkg ]; then mode=auto say " Mode: auto, only while nobody is using this Mac." return 0 fi mode=always if [ "${data_center:-0}" = 1 ]; then say " Mode: always (a data-center server, HIPS_DATA_CENTER=1)." return 0 fi if ! can_ask; then say " Mode: always (no terminal to ask in; HIPS_MODE=auto chooses the other)." return 0 fi # The question and its answer on the terminal, whatever this script's # output is sent to. { say "" say " How should this machine work for HIPS?" say " 1) Always (recommended for a server or dedicated machine)" say " 2) Auto (only when nobody is using it)" } >/dev/tty asked=0 while [ "$asked" -lt 3 ]; do asked=$((asked + 1)) printf ' Choose 1 or 2 [1]: ' >/dev/tty answer="" read -r answer /dev/tty ;; esac done say " Mode: $mode." } # apply_mode: the mode as the app's availability_mode (always, or auto as # scheduled, whose default schedule is every hour with the idle rule), # set through the service, so it reaches the account with the link. apply_mode() { case "$mode" in always) setting=always ;; *) setting=scheduled ;; esac if ! as_root "$CLI" config set availability_mode "$setting" "$tmp/mode.txt" 2>&1; then cat "$tmp/mode.txt" >&2 say " The mode could not be set (above). Set it later with: ${MEMBER_SUDO-sudo }hips-provider config set availability_mode $setting" fi } # data_center_now: the app's data_center setting, true or false, or # nothing where it cannot be read. data_center_now() { as_root "$CLI" config get data_center /dev/null | sed -n 's/^data_center = \([a-z]*\).*/\1/p' | head -n 1 } # declare_data_center: HIPS_DATA_CENTER=1 as `hips-provider config set # data_center true`, through the service, before the link, so the device # is linked as a data-center server; the configuration file's own flag is # read as before. A computer linked already keeps what it has, since only # HIPS changes the flag of a linked device. Never a question, with or # without a terminal; where the declaration fails, the computer is not # linked. declare_data_center() { if [ "$state" = linked ]; then say " This computer is linked already, so HIPS_DATA_CENTER=1 changes nothing here: once a device is linked, an operator changes its data-center flag in the HIPS Console. Ask HIPS support." return 0 fi if [ "$(data_center_now)" = true ]; then say " Declared a data-center server already." return 0 fi if ! as_root "$CLI" config set data_center true "$tmp/data-center.txt" 2>&1 \ || [ "$(data_center_now)" != true ]; then cat "$tmp/data-center.txt" >&2 fail 7 "HIPS Provider $installed is installed and running, but it could not be declared a data-center server (above), so this computer was not linked. Declare it with: ${MEMBER_SUDO-sudo }hips-provider config set data_center true, then link it with: $(link_command)" fi say " Declared a data-center server (HIPS_DATA_CENTER=1): it works whenever it is on and healthy, and nobody's use of it is waited for." } # link_with_code: the link by the enrollment code, handed to setup on its # standard input by printf, a builtin of the shell, so it is never in a # program's arguments; nothing is asked. HIPS refusing it is exit 9, the # code not taken as one exit 2. link_with_code() { if ! "$CLI" setup --help 2>/dev/null | grep -q -- '--enrollment-code-stdin'; then enrollment_code="" say " HIPS Provider $installed takes no enrollment code: a newer release does." say " Link this computer with a code to approve: $(link_command)" finish 7 fi set -- setup --enrollment-code-stdin if [ -n "${mode:-}" ]; then set -- "$@" --mode "$mode" fi printf '%s\n' "$enrollment_code" | as_root "$CLI" "$@" linked_by=$? enrollment_code="" case "$linked_by" in 0) ;; 4) say "" say "HIPS Provider $installed is installed and running, but HIPS refused the enrollment code (it says why, above), so this computer is not linked." say "Ask HIPS for a new code, then link it with: ${SUDO-sudo }hips-provider connect --enrollment-code-file " exit 9 ;; 2) say "" say "HIPS Provider $installed is installed and running, but HIPS_ENROLLMENT_CODE is not an enrollment code (above), so this computer is not linked." exit 2 ;; 3) say "" say "HIPS Provider $installed is installed, but this computer has no GPU HIPS supports, so it cannot work for HIPS (setup says why, above)." say "Remove it with: ${SUDO-sudo }hips-provider remove" exit 8 ;; esac state="$(link_state)" if [ "$state" = linked ]; then step "HIPS Provider $installed is installed, running and linked with the enrollment code." finish 0 fi say "" say "HIPS Provider $installed is installed and running, but this computer is not linked yet (setup says why, above)." say "See it with: ${MEMBER_SUDO-sudo }hips-provider status, or link it with: ${SUDO-sudo }hips-provider connect --enrollment-code-file " finish 7 } # The command that links this computer later: setup, or connect in a # release without it. link_command() { if "$CLI" setup --help >/dev/null 2>&1; then say "${SUDO-sudo }hips-provider setup" else say "${SUDO-sudo }hips-provider connect" fi } # use_line COMMAND WHAT: one line of "Use it", the command first. use_line() { printf ' %-28s %s\n' "$1" "$2"; } finish() { show_notes if [ "${supervised:-0}" = 1 ]; then step "When this container restarts" say " Nothing starts HIPS Provider again when this container restarts: systemd does not run here." # The device's state on the container's own volume at /workspace # (decided 2026-10-29): a restart that clears the container's disk # brings it back as the same device, linked, once the app is installed # again, which the start command does. case "$(readlink /var/lib/hips-provider 2>/dev/null)" in /workspace/.hips-provider/*) say " This device's state is kept on the container's volume, /workspace/.hips-provider, so after a restart it comes back as the same device, linked, with no new code." say " Put this first in the container's start command (on RunPod, the pod's container start command or its start script); it installs HIPS Provider again where the restart cleared the container's disk:" say "" say " (/usr/bin/hips-provider service start || curl -fsSL https://hips.com/install.sh | bash) >/workspace/.hips-provider/start.log 2>&1 &" say "" say " For example: bash -c '(/usr/bin/hips-provider service start || curl -fsSL https://hips.com/install.sh | bash) >/workspace/.hips-provider/start.log 2>&1 & exec /start.sh'" ;; *) say " Put this first in the container's start command (on RunPod, the pod's container start command or its start script):" say "" say " /usr/bin/hips-provider service start" say "" say " For example: bash -c '/usr/bin/hips-provider service start; exec /start.sh'" if [ -n "${RUNPOD_POD_ID:-}" ]; then say " RunPod clears a pod's container disk at every stop and restart and keeps only /workspace. This pod has no volume at /workspace, so after a restart HIPS Provider is gone with its link: give the pod a volume at /workspace and HIPS Provider keeps this device there." fi ;; esac fi if [ "${restart_to_finish:-0}" = 1 ]; then step "Restart to finish" say " Restart this computer once: it starts the kernel with the fixes ROCm needs on this GPU, and HIPS Provider uses ROCm after it." fi # Each command as the person reading it runs it (admit_account). step "Use it" use_line "${MEMBER_SUDO-sudo }hips-provider status" "the status, once" use_line "${MEMBER_SUDO-sudo }hips-provider" "the live view and every setting" use_line "${SUDO-sudo }hips-provider setup" "find the GPUs and link this computer to your HIPS account" use_line "${SUDO-sudo }hips-provider remove" "remove HIPS Provider from this computer" if [ -n "${admitted:-}" ]; then say " $admitted runs the first two without sudo: the account is in the $ADMIN_GROUP group, whose members use the hips-provider command." fi exit "$1" } # A Linux system: its processor, package manager and glibc. check_linux() { machine="$(uname -m 2>/dev/null)" case "$machine" in x86_64 | amd64) deb_arch=amd64 rpm_arch=x86_64 glibc_floor="$GLIBC_FLOOR_X86_64" ;; aarch64 | arm64) deb_arch=arm64 rpm_arch=aarch64 glibc_floor="$GLIBC_FLOOR_AARCH64" ;; *) fail 1 "HIPS Provider runs on x86_64 and arm64 (aarch64) processors; this machine's is $machine." ;; esac if [ -e /run/ostree-booted ]; then fail 1 "this is an image-based system (OSTree: Fedora Silverblue or Kinoite, Fedora CoreOS, RHEL for Edge), whose system folders a package installer cannot write, and HIPS Provider has no package for it yet." fi # The system's own package tool: dpkg where apt-get is, or where rpm is # not (a minimal image without apt), else rpm; apt-get or dnf only gets # a missing dependency. if have dpkg && { have apt-get || ! have rpm; }; then family=deb manager=apt-get have apt-get || manager="" packages_arch="$(dpkg --print-architecture 2>/dev/null)" [ "$packages_arch" = "$deb_arch" ] \ || fail 1 "this system installs $packages_arch packages, and HIPS Provider has $deb_arch packages for this $machine processor. Install a 64-bit system." elif have rpm; then family=rpm if have dnf; then manager=dnf elif have yum; then manager=yum else manager="" fi else fail 1 "this installer installs .deb packages (Debian, Ubuntu) and .rpm packages (Fedora, RHEL, Rocky Linux, AlmaLinux, Amazon Linux 2023), and this system has neither dpkg nor rpm. See $DOWNLOAD_PAGE for the packages." fi glibc="$(glibc_version)" \ || fail 1 "HIPS Provider needs the GNU C library (glibc) $glibc_floor or newer, and this system's could not be read." version_at_least "$glibc" "$glibc_floor" \ || fail 1 "HIPS Provider needs glibc $glibc_floor or newer (Ubuntu 22.04, Debian 12, Fedora 35, RHEL 9 or newer), and this system has glibc $glibc." CLI=/usr/bin/hips-provider PROGRAM=/opt/hips-provider/current/hips-provider os="$(sed -n 's/^PRETTY_NAME=//p' /etc/os-release 2>/dev/null | tr -d '"' | head -n 1)" about="${os:-Linux}, $machine, glibc $glibc" } # A Mac: Apple silicon (also under Rosetta, where uname says x86_64) and # the macOS the package installs on. check_mac() { [ "$(sysctl -n hw.optional.arm64 2>/dev/null)" = 1 ] \ || fail 1 "HIPS Provider runs on Macs with Apple silicon (M1 and newer). This Mac has an Intel processor, so nothing was installed." macos="$(sw_vers -productVersion 2>/dev/null)" if [ -z "$macos" ] || ! version_at_least "$macos" "$MACOS_FLOOR"; then fail 1 "HIPS Provider needs macOS $MACOS_FLOOR or later, and this Mac has macOS ${macos:-of a version that could not be read}." fi family=pkg manager=installer CLI=/usr/local/bin/hips-provider PROGRAM="$CLI" about="macOS $macos, Apple silicon" } main() { for argument in "$@"; do case "$argument" in -h | --help) usage exit 0 ;; *) fail 2 "unknown argument '$argument'. Settings are environment variables; run it with --help to see them." ;; esac done say "HIPS Provider" # Root's programs on the PATH: `su` without `-` keeps the user's PATH, # without the sbin folders dpkg and the packages' scripts need. for sbin in /usr/local/sbin /usr/sbin /sbin; do case ":$PATH:" in *":$sbin:"*) ;; *) PATH="$PATH:$sbin" ;; esac done export PATH # 1. The settings and the computer. case "${HIPS_NO_LINK:-0}" in "" | 0) link=1 ;; 1) link=0 ;; *) fail 2 "HIPS_NO_LINK is '$HIPS_NO_LINK'; set it to 1 to install without linking." ;; esac case "${HIPS_MODE:-}" in "" | always | auto) ;; *) fail 2 "HIPS_MODE is '$HIPS_MODE'; set it to always or auto, or leave it out to be asked." ;; esac case "${HIPS_DATA_CENTER:-}" in "" | 0) data_center=0 ;; 1) data_center=1 ;; *) fail 2 "HIPS_DATA_CENTER is '$HIPS_DATA_CENTER'; set it to 1 to declare this server a data-center server, or leave it out." ;; esac # The enrollment code, out of the environment at once, so no program # started from here on (the package manager, sudo, the app's own) sees # it; whether it is a code at all, hips-provider decides. enrollment_code="${HIPS_ENROLLMENT_CODE:-}" unset HIPS_ENROLLMENT_CODE if [ -n "$enrollment_code" ]; then [ "$(uname -s 2>/dev/null)" = Linux ] \ || fail 2 "HIPS_ENROLLMENT_CODE links a Linux server; this computer is not one, so nothing was installed. Leave it out, and link this computer with a code to approve." [ "$link" = 1 ] \ || fail 2 "HIPS_ENROLLMENT_CODE links this computer, and HIPS_NO_LINK=1 asks not to link it. Leave one of them out." fi if [ "$data_center" = 1 ]; then [ "$(uname -s 2>/dev/null)" = Linux ] \ || fail 2 "HIPS_DATA_CENTER=1 declares a Linux server a data-center server; this computer is not one, so nothing was installed. Leave it out." [ "${HIPS_MODE:-always}" = always ] \ || fail 2 "HIPS_DATA_CENTER=1 declares a server that works whenever it is on, so HIPS_MODE=$HIPS_MODE does not go with it. Leave HIPS_MODE out, or set it to always." fi version="${HIPS_VERSION:-}" version="${version#v}" if [ -n "$version" ] && ! is_version "$version"; then fail 2 "HIPS_VERSION is '$HIPS_VERSION'; set it to a release's version, such as 0.1.5, or leave it out for the newest." fi base="${HIPS_RELEASES_BASE:-$RELEASES}" base="${base%/}" case "$base" in https://*) protocols='=https' ;; http://*) protocols='=http,https' ;; *) fail 2 "HIPS_RELEASES_BASE is '$base'; it must be an http or https address, and it is for testing only." ;; esac case "$(uname -s 2>/dev/null)" in Linux) check_linux ;; Darwin) check_mac ;; *) fail 1 "this installer is for Linux and macOS. For Windows, download HIPS Provider at $DOWNLOAD_PAGE." ;; esac if have curl; then downloader=curl elif have wget; then downloader=wget else fail 1 "this installer needs curl or wget to download the package. Install one of them, then run it again." fi have sha256sum || have shasum \ || fail 4 "this installer needs sha256sum or shasum to check the download. Install coreutils, then run it again." uid="$(id -u)" # How a printed command is given: as it is to root itself (logged in as # root, with no sudo above it, where sudo may not even be installed, as # in a container), through sudo to anyone else; the commands that only # read or set the daemon also as they are to a member of # hips-provider-admin (MEMBER_SUDO, admit_account). SUDO="sudo " if [ "$uid" = 0 ] && [ -z "${SUDO_USER:-}${DOAS_USER:-}" ]; then SUDO="" fi MEMBER_SUDO="$SUDO" if [ "$uid" != 0 ] && ! have sudo; then fail 5 "installing needs root. Run it as root, or install sudo, then run it again." fi say " Computer: $about" if [ -n "${HIPS_RELEASES_BASE:-}" ]; then say " Releases: $base (HIPS_RELEASES_BASE, for testing only)" fi make_tmp \ || fail 3 "there is no folder to download into: ${TMPDIR:+$TMPDIR, }/tmp, /var/tmp and ${HOME:-the home folder} are read-only, missing, or have less than $((DOWNLOAD_ROOM_KB / 1024)) MB free. Free some space, or set TMPDIR to a folder with room, then run it again." trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM trap 'exit 129' HUP unversioned="$(package_name)" # 2. The release's SHA256SUMS, then the package. The newest release's # SHA256SUMS names its version, and the package is then that version's # own file, so a release published meanwhile cannot mix its files with # another's. step "Downloading" say " Into $tmp" if [ -n "$version" ]; then sums_url="$base/download/v$version/SHA256SUMS" fetch "$sums_url" "$tmp/SHA256SUMS" \ || fail 3 "$(fetch_failure "$sums_url"). Check that $version is a release at $RELEASES and that this computer reaches github.com, then run it again." sums_valid else sums_url="$base/latest/download/SHA256SUMS" fetch "$sums_url" "$tmp/SHA256SUMS" \ || fail 3 "$(fetch_failure "$sums_url"). Check that this computer reaches github.com, then run it again." sums_valid newest="$(sum_of "$unversioned")" [ -n "$newest" ] \ || fail 1 "the newest release has no package for this computer ($unversioned is not in its SHA256SUMS). See $DOWNLOAD_PAGE for what is available." awk -v h="$newest" -v n="$unversioned" '$1 == h && $2 != n { sub(/^\*/, "", $2); print $2 }' "$tmp/SHA256SUMS" >"$tmp/names" while read -r name; do version="$(version_of "$name")" [ -n "$version" ] && break done <"$tmp/names" [ -n "$version" ] \ || fail 4 "the newest release's SHA256SUMS names no version for $unversioned, so it was not installed. Run it again later, or download the package from $DOWNLOAD_PAGE." fi sums_signed file="$(package_name "$version")" expected="$(sum_of "$file")" if [ -z "$expected" ]; then fail 1 "release $version has no package for this computer ($file is not in its SHA256SUMS). See $DOWNLOAD_PAGE for what is available." fi printf '%s\n' "$expected" | grep -Eq '^[0-9a-f]{64}$' \ || fail 4 "the SHA-256 of $file in SHA256SUMS is not a SHA-256, so it was not installed." say " HIPS Provider $version: $file" package_url="$base/download/v$version/$file" fetch "$package_url" "$tmp/$file" \ || fail 3 "$(fetch_failure "$package_url"). Check that this computer reaches github.com, then run it again." # 3. The check. actual="$(sha256_of "$tmp/$file")" [ "$actual" = "$expected" ] \ || fail 4 "$file does not match its SHA-256 in SHA256SUMS (expected $expected, downloaded $actual), so nothing was installed. Run it again; if it fails the same way, download the package from $DOWNLOAD_PAGE and check it as that page shows." say " SHA-256 matches SHA256SUMS: $actual" # 4. The install, as root. step "Installing" if [ "$uid" != 0 ]; then if sudo -n true /dev/null; then say " With sudo." elif can_ask; then say " With sudo, which may ask for your password." sudo true /dev/null 2>&1 & sudo_keeper=$! fi lock_waited=0 installed="$(installed_version)" # What the package manager is asked: install (also an update), none, a # downgrade a pinned version asks for, or the same version again when the # package is recorded as installed but its programs are gone (as # `hips-provider remove` leaves the package record on Linux). if [ -z "$installed" ]; then action=install elif [ ! -x "$PROGRAM" ] || ! "$PROGRAM" --version >/dev/null 2>&1; then action=reinstall say " HIPS Provider $installed is recorded as installed, but its programs are missing; installing $version again." elif [ "$installed" = "$version" ]; then action=none say " HIPS Provider $version is installed already." elif held; then action=none if [ "$family" = deb ]; then say " HIPS Provider $installed is held on this system (apt-mark hold), so it stays at $installed. For $version, release it with: ${SUDO-sudo }apt-mark unhold hips-provider, then run the installer again." else say " HIPS Provider $installed is locked at its version on this system (dnf versionlock), so it stays at $installed. For $version, release it with: ${SUDO-sudo }dnf versionlock delete hips-provider, then run the installer again." fi elif version_at_least "$installed" "$version"; then if [ -n "${HIPS_VERSION:-}" ]; then action=downgrade say " HIPS Provider $installed is installed; going back to $version, as HIPS_VERSION asks." else action=none say " HIPS Provider $installed is installed, newer than this release's $version; it stays." fi else action=install say " Updating HIPS Provider $installed to $version." fi if [ "$action" != none ]; then if masked; then fail 5 "the $LINUX_SERVICE service is masked on this system (systemctl mask), so HIPS Provider cannot be set up, and nothing was installed. Unmask it with: ${SUDO-sudo }systemctl unmask $LINUX_SERVICE, then run the installer again." fi read_only="$(read_only_dirs)" if [ -n "$read_only" ]; then fail 5 "this system cannot be written where HIPS Provider installs: part of it is read-only ($read_only), so nothing was installed. HIPS Provider needs /opt, /usr, /etc and /var writable; on an image-based or read-only system, see $DOWNLOAD_PAGE." fi room_for_install case "$family" in deb) deb_install ;; rpm) rpm_install ;; *) # The package installs over any version, an earlier one included. as_root installer -pkg "$tmp/$file" -target / /dev/null 2>&1; then fail 5 "the package system records HIPS Provider, but its program $PROGRAM does not run, so it is not installed whole. Run the installer again; if it fails the same way, install the package from $DOWNLOAD_PAGE." fi # The hips-provider command is HIPS Provider's link, unless something # else was there first, which the package leaves as it is; this script # then runs the program itself. if [ "$CLI" != "$PROGRAM" ]; then case "$(readlink -f "$CLI" 2>/dev/null)" in /opt/hips-provider/*) ;; *) if [ -e "$CLI" ] || [ -L "$CLI" ]; then if [ "$family" = deb ]; then shadow="$(dpkg -S "$CLI" 2>/dev/null | sed -n 's/: .*//p' | head -n 1)" else shadow="$(rpm -qf --qf '%{NAME}\n' "$CLI" 2>/dev/null)" || shadow="" shadow="$(printf '%s\n' "$shadow" | head -n 1)" fi note "$CLI is not HIPS Provider's${shadow:+ (it belongs to the package $shadow)}, so the hips-provider command runs it instead. Move it away and link HIPS Provider's: ${SUDO-sudo }mv $CLI $CLI.old && ${SUDO-sudo }ln -s $PROGRAM $CLI" else note "the hips-provider command ($CLI) is missing. Link it with: ${SUDO-sudo }ln -s $PROGRAM $CLI" fi CLI="$PROGRAM" ;; esac fi say " Installed: HIPS Provider $installed" admit_account installed_here=1 # 5. The service. Where systemd does not run (a container), the app # supervises its own service from 0.1.7 on (decided 2026-10-28). step "Starting" supervised=0 if [ "$family" != pkg ] && [ ! -d /run/systemd/system ]; then if ! "$CLI" service status --help >/dev/null 2>&1; then if grep -q -i microsoft /proc/version 2>/dev/null; then say " systemd is not running in this WSL, so the hips-provider service was not started." say " Turn it on with [boot] systemd=true in /etc/wsl.conf, run wsl --shutdown in Windows, then: ${SUDO-sudo }hips-provider service install" else say " systemd is not running here (a container?), so the hips-provider service was not started." fi say " HIPS Provider runs without systemd from 0.1.7 on; install the newest release." if [ "$link" = 0 ]; then finish 0 fi fail 6 "HIPS Provider $installed is installed, but its service cannot run without systemd, so this device was not linked. Install the newest release, without HIPS_VERSION." fi supervised=1 say " systemd is not running here (a container), so HIPS Provider runs its service under its own supervision." fi if masked; then fail 6 "HIPS Provider is installed, but its $LINUX_SERVICE service is masked on this system (systemctl mask), so it does not run. Unmask it with: ${SUDO-sudo }systemctl unmask $LINUX_SERVICE, then run the installer again." fi if ! wait_active 15; then if [ "$supervised" = 1 ]; then as_root "$CLI" service install /dev/null)" = enabled ]; then as_root systemctl start "$LINUX_SERVICE" /dev/null 2>&1; then step "What the GPU needs" { as_root "$CLI" service prerequisites &1; echo "$?" >"$tmp/prerequisites.rc"; } | sed 's/^/ /' case "$(cat "$tmp/prerequisites.rc" 2>/dev/null)" in 3) restart_to_finish=1 ;; esac fi show_notes # 6. The mode. A computer linked already keeps its own, which its owner # may have changed since, unless HIPS_MODE asks. step "How this computer works for HIPS" wait_daemon if [ "$data_center" = 1 ]; then declare_data_center fi if [ "$state" = linked ] && [ -z "${HIPS_MODE:-}" ]; then say " This computer is linked already and keeps its mode (see it with: ${MEMBER_SUDO-sudo }hips-provider config get availability_mode)." else choose_mode apply_mode fi # 7. The link, by setup where the release has it. if [ "$link" = 0 ]; then step "Linking skipped (HIPS_NO_LINK=1)" say " Link this computer to your HIPS account later with: $(link_command)" finish 0 fi step "Linking this computer to your HIPS account" start_menu_bar_app if [ "$state" = linked ]; then say " This computer is linked to a HIPS account already." [ -z "$enrollment_code" ] || say " The enrollment code was not used." finish 0 fi if [ -n "$enrollment_code" ]; then link_with_code fi # setup draws its own sheets: what it found, the code to approve, what # runs next. A release without it has connect. if "$CLI" setup --help >/dev/null 2>&1; then set -- setup if [ -n "${mode:-}" ] && "$CLI" setup --help 2>/dev/null | grep -q -- '--mode'; then set -- setup --mode "$mode" fi else set -- connect say " Approve the code at $APPROVAL_PAGE, signed in to your HIPS account, from this or any other device." say "" fi # Ctrl+C stops the wait in hips-provider, which withdraws the code and # says so; the installer then goes on to say what is next. trap ':' INT as_root "$CLI" "$@"