main
John Lauer Publish 0.1.3 446c8b3
#!/bin/bash
# hydrogen-host-setup.sh: everything a Linux computer needs for Adom Hydrogen and its dock apps
# (adom/hydrogen-linux-bootstrap; the inventory is in this package's README).
#
#   hydrogen-host-setup.sh check [--json]        what is missing (no root, changes nothing)
#   hydrogen-host-setup.sh apply-system [opts]   install what is missing (root: Hydrogen runs it
#                                                with ONE pkexec prompt; idempotent)
#   hydrogen-host-setup.sh apply-user            the per-user part (fonts, Flatpak exports, tray
#                                                extension, default browser), no root
#
# apply-system options: --user NAME (whose desktop), --desktop GNOME|X-Cinnamon|KDE,
#   --session wayland|x11, --with-chrome (Google Chrome for the nb bridge), --dry-run.
# Ubuntu 22.04/24.04, Debian 12/13 and Fedora 40+ (and their derivatives). Prints what it does.
set -u
HHS_VERSION=0.1.4
# 3b. WHAT earlyoom MAY STOP (DIR-151403-30275, Debian 13 on 6 GB: it stopped code-server's
#     extension host three times, which runs every AI chat; the host is named MainThread and has
#     the highest OOM score in the workspace). Never: code-server (MainThread), Hydrogen, the
#     desktop, the AI CLIs. First: compilers, linkers, cargo, ffmpeg. Written once; a changed line
#     restarts earlyoom.
EOOM_ARGS='-r 3600 -m 4 -s 10 --avoid (^|/)(init|systemd|sshd|MainThread|code-server|adom-hydrogen|hydrogen|gnome-shell|Xwayland|Xorg|cinnamon|plasmashell|kwin_wayland|claude|codex|kimi|agy|adom-bridge)$ --prefer (^|/)(cc1|cc1plus|cc1obj|rustc|ld|ld[.]lld|ld[.]gold|lld|mold|clang|clang[+][+]|gcc|g[+][+]|cargo|make|ninja|ffmpeg|esbuild|tsc|webpack|kicad-cli)$'

MODE=${1:-check}; shift || true
JSON=0; DRY=0; WITH_CHROME=0; USERNAME=${SUDO_USER:-${PKEXEC_UID:+$(getent passwd "$PKEXEC_UID" | cut -d: -f1)}}
DESKTOP=${XDG_CURRENT_DESKTOP:-}; SESSION=${XDG_SESSION_TYPE:-}
while [ $# -gt 0 ]; do case "$1" in
  --json) JSON=1;; --dry-run) DRY=1;; --with-chrome) WITH_CHROME=1;;
  --user) USERNAME=$2; shift;; --desktop) DESKTOP=$2; shift;; --session) SESSION=$2; shift;;
esac; shift; done
HERE=$(cd "$(dirname "$0")" && pwd)
SAMPLE="$HERE/h264-high-sample.mp4"

. /etc/os-release 2>/dev/null || true
case " ${ID:-} ${ID_LIKE:-} " in
  *" fedora "*|*" rhel "*|*" centos "*) FAMILY=fedora ;;
  *" debian "*|*" ubuntu "*) FAMILY=debian ;;
  *) FAMILY=other ;;
esac
DE=$(echo "${DESKTOP}" | tr '[:upper:]' '[:lower:]')
is_gnome() { case "$DE" in *gnome*|*ubuntu*) return 0;; esac; return 1; }
is_cinnamon() { case "$DE" in *cinnamon*) return 0;; esac; return 1; }
is_kde() { case "$DE" in *kde*|*plasma*) return 0;; esac; return 1; }
have() { command -v "$1" >/dev/null 2>&1; }
say() { [ "$JSON" = 1 ] || echo "$*"; }

# ── checks: one function per inventory item; prints "id<TAB>ok|missing|n/a<TAB>detail" ──
R=()
rec() { R+=("$1	$2	$3"); }
c_h264() {
  if have gst-inspect-1.0 && gst-inspect-1.0 avdec_h264 >/dev/null 2>&1 && gst-inspect-1.0 avdec_aac >/dev/null 2>&1; then
    if [ -f "$SAMPLE" ] && have gst-launch-1.0; then
      if timeout 20 gst-launch-1.0 -q filesrc location="$SAMPLE" ! qtdemux ! h264parse ! avdec_h264 ! fakesink >/dev/null 2>&1; then rec h264 ok "avdec_h264 decodes the High-profile sample"; else rec h264 missing "avdec_h264 is there but the High-profile sample did not decode"; fi
    else rec h264 ok "avdec_h264 and avdec_aac present"; fi
  elif ! have gst-inspect-1.0; then rec h264 missing "no gst-inspect-1.0 (GStreamer tools) to confirm H.264 playback"
  else rec h264 missing "no avdec_h264 (GStreamer libav): H.264 videos do not play in Hydrogen"; fi
}
c_fuse() { if { ldconfig -p 2>/dev/null || /sbin/ldconfig -p 2>/dev/null || /usr/sbin/ldconfig -p 2>/dev/null; } | grep -q 'libfuse\.so\.2' || ls /usr/lib/*/libfuse.so.2* /lib/*/libfuse.so.2* /usr/lib64/libfuse.so.2* >/dev/null 2>&1; then rec fuse2 ok "libfuse.so.2 present (AppImages run)"; else rec fuse2 missing "no libfuse.so.2: AppImages (Grok Bot, Adom Bridge) cannot run directly"; fi; }
c_flatpak() {
  if ! have flatpak; then rec flatpak missing "no flatpak (KiCad installs from Flathub)"; return; fi
  if flatpak remotes --system 2>/dev/null | grep -qw flathub || flatpak remotes 2>/dev/null | grep -qw flathub; then rec flatpak ok "flatpak with Flathub"; else rec flatpak missing "flatpak without the Flathub remote"; fi
}
c_tray() {
  if ! is_gnome; then rec tray n/a "this desktop has its own tray"; return; fi
  if [ "${ID:-}" = ubuntu ]; then rec tray ok "Ubuntu's own AppIndicator extension"; return; fi
  if have gnome-extensions && gnome-extensions info [email protected] 2>/dev/null | grep -q "State: ACTIVE"; then rec tray ok "AppIndicator extension active"
  elif [ -d /usr/share/gnome-shell/extensions/[email protected] ]; then rec tray relogin "AppIndicator extension installed; enable it and log out and in once"
  else rec tray missing "no tray on this GNOME: a closed Hydrogen window would have no way back"; fi
}
c_abext() { user_item ab_windows && return;
  if ! is_gnome || [ "${SESSION:-}" != wayland ]; then rec ab_windows n/a "only GNOME on Wayland needs it"; return; fi
  if have gnome-extensions && gnome-extensions info [email protected] 2>/dev/null | grep -q "State: ACTIVE"; then rec ab_windows ok "Adom Bridge window list extension active"
  elif have gnome-extensions && gnome-extensions info [email protected] >/dev/null 2>&1; then rec ab_windows relogin "Adom Bridge window list extension installed; log out and in once"
  else rec ab_windows missing "Adom Bridge installs its window list extension on first use"; fi
}
c_portal() {
  local p=/usr/share/xdg-desktop-portal/portals want=""
  if is_gnome; then want=gnome; elif is_cinnamon; then want=xapp; elif is_kde; then want=kde; else want=gtk; fi
  if [ -f "$p/$want.portal" ]; then rec portal ok "xdg-desktop-portal ($want)"; else rec portal missing "no $want desktop portal (screenshots and screen capture)"; fi
}
c_audio() { if have pw-record || have parec; then rec audio ok "$(have pw-record && echo pw-record || echo parec) for Dictate"; else rec audio missing "no pw-record or parec: Dictate cannot record"; fi; }
c_clip() { if have wl-copy || have xclip; then rec clipboard ok "$(have wl-copy && echo wl-copy) $(have xclip && echo xclip)"; else rec clipboard missing "no wl-copy or xclip: an annotate picture leaves the clipboard when Hydrogen loses focus"; fi; }
c_notify() { if have notify-send; then rec notify ok "notify-send"; else rec notify missing "no notify-send (Adom Bridge notifications)"; fi; }
c_xdg() { if have xdg-open && have xdg-settings; then rec xdg ok "xdg-open, xdg-settings"; else rec xdg missing "no xdg-utils"; fi; }
c_oom() {
  if systemctl is-active -q systemd-oomd 2>/dev/null || systemctl is-active -q earlyoom 2>/dev/null; then rec oom ok "$(systemctl is-active -q systemd-oomd 2>/dev/null && echo systemd-oomd || echo earlyoom)"
  else rec oom missing "no out-of-memory guard (Debian): a full memory can freeze the desktop"; fi
}
c_fonts() { user_item fonts && return; if have fc-list && fc-list 2>/dev/null | grep -qi "familjen grotesk" && fc-list | grep -qi "satoshi" && fc-list | grep -qi "jetbrains mono"; then rec fonts ok "Familjen Grotesk, Satoshi, JetBrains Mono"; else rec fonts missing "Adom fonts not installed for this user"; fi; }
c_mesh() { user_item mesh && return;
  local f="${HOME}/.adom/config.json"
  [ -f "$f" ] || { rec mesh n/a "Adom Bridge not set up yet"; return; }
  if python3 -c "import json,sys;d=json.load(open('$f'));sys.exit(0 if d.get('mesh_enabled',True) and d.get('mesh_mode','relay')=='relay' else 1)" 2>/dev/null; then rec mesh ok "mesh on, relay mode"
  else rec mesh missing "Adom Bridge mesh off or not in relay mode: approvals do not mirror"; fi
}
c_firewall() {
  if have firewall-cmd && systemctl is-active -q firewalld 2>/dev/null; then
    local port; port=$(python3 -c "import json;d=json.load(open('${HOME}/.adom/config.json'));print(d.get('mesh_port') or '')" 2>/dev/null)
    [ -n "$port" ] || { rec firewall n/a "firewalld on; Adom Bridge uses the relay (no direct mesh port configured)"; return; }
    if firewall-cmd --query-port="$port/tcp" >/dev/null 2>&1; then rec firewall ok "firewalld allows $port/tcp"; else rec firewall missing "firewalld blocks the Adom Bridge mesh port $port/tcp"; fi
  else rec firewall n/a "no firewalld"; fi
}
c_keyring() { user_item keyring && return; if [ -f "${HOME}/.local/share/keyrings/login.keyring" ]; then rec keyring ok "login keyring exists"; else rec keyring warn "no login keyring: Chrome may ask for a new keyring password (nb/pup start Chrome with --password-store=basic)"; fi; }
c_chrome() { if have google-chrome || have google-chrome-stable; then rec chrome ok "$( (google-chrome --version || google-chrome-stable --version) 2>/dev/null | head -1)"; else rec chrome n/a "Google Chrome not installed (only the nb bridge needs it; Hydrogen offers it there)"; fi; }
c_workspace_tz() {
  local m=/var/lib/machines/Adom-Workspace host
  host=$(timedatectl show -p Timezone --value 2>/dev/null)
  if ! machinectl show Adom-Workspace >/dev/null 2>&1 && ! [ -d "$m" ]; then rec workspace_tz n/a "no workspace yet"; return; fi
  if [ "$(id -u)" != 0 ]; then rec workspace_tz ok "set to the computer's zone ($host) by the root step on every install"; return; fi
  if [ "$(cat "$m/etc/timezone" 2>/dev/null)" = "$host" ]; then rec workspace_tz ok "workspace follows $host"; else rec workspace_tz missing "workspace time zone is not the computer's ($host)"; fi
}
user_item() { [ "$(id -u)" = 0 ] && { rec "$1" user "checked by the user step"; return 0; }; return 1; }
run_checks() { R=(); c_h264; c_fuse; c_flatpak; c_tray; c_abext; c_portal; c_audio; c_clip; c_notify; c_xdg; c_oom; c_fonts; c_mesh; c_firewall; c_keyring; c_chrome; c_workspace_tz; }
print_checks() {
  if [ "$JSON" = 1 ]; then
    printf '{"version":"%s","distro":"%s","family":"%s","desktop":"%s","session":"%s","items":[' "$HHS_VERSION" "${PRETTY_NAME:-unknown}" "$FAMILY" "$DESKTOP" "$SESSION"
    local first=1 line id st de
    for line in "${R[@]}"; do IFS=$'\t' read -r id st de <<<"$line"; [ $first = 1 ] || printf ','; first=0
      printf '{"id":"%s","state":"%s","detail":"%s"}' "$id" "$st" "$(echo "$de" | sed 's/\\/\\\\/g; s/"/\\"/g')"; done
    printf ']}\n'
  else
    echo "Hydrogen host check $HHS_VERSION on ${PRETTY_NAME:-unknown} (${DESKTOP:-no desktop}, ${SESSION:-?})"
    local line; for line in "${R[@]}"; do IFS=$'\t' read -r id st de <<<"$line"; printf '  %-13s %-8s %s\n' "$id" "$st" "$de"; done
  fi
}
state_of() { local line; for line in "${R[@]}"; do case "$line" in "$1	"*) echo "$line" | cut -f2; return;; esac; done; }

# ── apply-system (root) ──
pkg_avail_deb() { apt-cache show "$1" >/dev/null 2>&1; }
run() { echo "  + $*"; [ "$DRY" = 1 ] || "$@"; }
apply_system() {
  [ "$(id -u)" = 0 ] || { echo "apply-system needs root (Hydrogen runs it with pkexec)"; exit 2; }
  run_checks
  local pk=() changed=0
  echo "Adom Hydrogen: setting up this computer (${PRETTY_NAME:-unknown}, ${DESKTOP:-no desktop})"
  if [ "$FAMILY" = debian ]; then
    export DEBIAN_FRONTEND=noninteractive
    run apt-get update -qq
    # gstreamer1.0-tools: gst-inspect-1.0, which the check needs (Debian 13 does not install it).
    [ "$(state_of h264)" = ok ] || pk+=(gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-vaapi gstreamer1.0-tools)
    if [ "$(state_of fuse2)" != ok ]; then if pkg_avail_deb libfuse2t64; then pk+=(libfuse2t64); else pk+=(libfuse2); fi; fi
    have flatpak || pk+=(flatpak)
    if is_gnome && [ "${ID:-}" != ubuntu ] && [ "$(state_of tray)" = missing ]; then pk+=(gnome-shell-extension-appindicator); fi
    if [ "$(state_of portal)" != ok ]; then
      pk+=(xdg-desktop-portal)
      if is_gnome; then pk+=(xdg-desktop-portal-gnome); elif is_cinnamon; then pk+=(xdg-desktop-portal-xapp xdg-desktop-portal-gtk); elif is_kde; then pk+=(xdg-desktop-portal-kde); else pk+=(xdg-desktop-portal-gtk); fi
    fi
    [ "$(state_of audio)" = ok ] || pk+=(pulseaudio-utils)
    have wl-copy || pk+=(wl-clipboard); have xclip || pk+=(xclip)
    have notify-send || pk+=(libnotify-bin)
    { have xdg-open && have xdg-settings; } || pk+=(xdg-utils)
    [ "$(state_of oom)" = ok ] || pk+=(earlyoom)
    if [ ${#pk[@]} -gt 0 ]; then run apt-get install -y -q --no-install-recommends "${pk[@]}" && changed=1; fi
    [ "$(state_of oom)" = ok ] || run systemctl enable --now earlyoom
    if [ -f /etc/default/earlyoom ] && ! grep -qF -- "$EOOM_ARGS" /etc/default/earlyoom; then
      printf '# Adom Hydrogen (hydrogen-host-setup): what earlyoom may stop, and what first.\nEARLYOOM_ARGS="%s"\n' "$(printf '%s' "$EOOM_ARGS")" > /etc/default/earlyoom && systemctl restart earlyoom && changed=1
    fi
  elif [ "$FAMILY" = fedora ]; then
    have gst-inspect-1.0 || pk+=(gstreamer1)
    if [ "$(state_of h264)" != ok ]; then
      if ! rpm -q rpmfusion-free-release >/dev/null 2>&1; then
        echo "  H.264 (the codec Adom's videos use) is not in Fedora itself. Adding the RPM Fusion free"
        echo "  repository (rpmfusion.org), the standard source for it on Fedora."
        run dnf install -y -q "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm"
      fi
      rpm -q ffmpeg-free >/dev/null 2>&1 && run dnf swap -y -q ffmpeg-free ffmpeg --allowerasing
      pk+=(gstreamer1-plugin-libav gstreamer1-plugins-bad-free gstreamer1-plugins-good gstreamer1-vaapi)
    fi
    [ "$(state_of fuse2)" = ok ] || pk+=(fuse-libs)
    have flatpak || pk+=(flatpak)
    if is_gnome && [ "$(state_of tray)" = missing ]; then pk+=(gnome-shell-extension-appindicator); fi
    if [ "$(state_of portal)" != ok ]; then pk+=(xdg-desktop-portal); if is_gnome; then pk+=(xdg-desktop-portal-gnome); elif is_kde; then pk+=(xdg-desktop-portal-kde); else pk+=(xdg-desktop-portal-gtk); fi; fi
    [ "$(state_of audio)" = ok ] || pk+=(pipewire-utils)
    have wl-copy || pk+=(wl-clipboard); have xclip || pk+=(xclip)
    have notify-send || pk+=(libnotify)
    { have xdg-open && have xdg-settings; } || pk+=(xdg-utils)
    if [ ${#pk[@]} -gt 0 ]; then run dnf install -y -q "${pk[@]}" && changed=1; fi
  else
    echo "  ${PRETTY_NAME:-This distribution} is not one the bootstrap knows (Ubuntu, Debian, Fedora); nothing installed."
  fi
  # GStreamer caches what each plugin can do per user; swapping libavcodec underneath (Fedora:
  # ffmpeg-free -> ffmpeg) does not touch the plugin file, so the cache keeps saying "no H.264".
  if [ "$(state_of h264)" != ok ] && [ -n "$USERNAME" ]; then
    local uh; uh=$(getent passwd "$USERNAME" | cut -d: -f6)
    [ -n "$uh" ] && [ -d "$uh/.cache/gstreamer-1.0" ] && { echo "  + GStreamer plugin cache of $USERNAME cleared (it still described the old codecs)"; [ "$DRY" = 1 ] || rm -rf "$uh/.cache/gstreamer-1.0"; }
    rm -rf /root/.cache/gstreamer-1.0 2>/dev/null
  fi
  if have flatpak && ! flatpak remotes --system 2>/dev/null | grep -qw flathub; then run flatpak remote-add --system --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo; fi
  if [ "$WITH_CHROME" = 1 ] && ! have google-chrome && ! have google-chrome-stable; then
    echo "  Google Chrome for the native browser bridge (your default browser is kept)."
    if [ "$FAMILY" = debian ]; then run curl -fsSLo /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && run apt-get install -y -q /tmp/google-chrome.deb
    elif [ "$FAMILY" = fedora ]; then run dnf install -y -q https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm; fi
  fi
  # The workspace keeps the computer's time zone (systemd-nspawn does not follow a change).
  local m=/var/lib/machines/Adom-Workspace tz; tz=$(timedatectl show -p Timezone --value 2>/dev/null)
  if [ -d "$m/etc" ] && [ -n "$tz" ] && [ -e "$m/usr/share/zoneinfo/$tz" ] && [ "$(cat "$m/etc/timezone" 2>/dev/null)" != "$tz" ]; then
    echo "  + workspace time zone -> $tz"; [ "$DRY" = 1 ] || { echo "$tz" > "$m/etc/timezone"; ln -sfn "/usr/share/zoneinfo/$tz" "$m/etc/localtime"; }
  fi
  if have firewall-cmd && systemctl is-active -q firewalld 2>/dev/null && [ -n "$USERNAME" ]; then
    local home port; home=$(getent passwd "$USERNAME" | cut -d: -f6)
    port=$(python3 -c "import json;print(json.load(open('$home/.adom/config.json')).get('mesh_port') or '')" 2>/dev/null)
    if [ -n "$port" ] && ! firewall-cmd --query-port="$port/tcp" >/dev/null 2>&1; then run firewall-cmd --permanent --add-port="$port/tcp"; run firewall-cmd --reload; fi
  fi
  echo "Done."
  JSON=0; R=(); run_checks; print_checks
}

# ── apply-user (no root) ──
apply_user() {
  [ "$(id -u)" != 0 ] || { echo "apply-user runs as the desktop user, not root"; exit 2; }
  local st="$HOME/.local/share/adom-hydrogen"; mkdir -p "$st"
  # Default browser: remember it once, and put it back if a Chrome install took it.
  local cur; cur=$(xdg-settings get default-web-browser 2>/dev/null)
  if [ -n "$cur" ] && [ ! -f "$st/default-browser" ]; then echo "$cur" > "$st/default-browser"; fi
  local was; was=$(cat "$st/default-browser" 2>/dev/null)
  if [ -n "$was" ] && [ -n "$cur" ] && [ "$cur" != "$was" ] && case "$cur" in google-chrome*) true;; *) false;; esac && [ -f "$st/chrome-installed-by-hydrogen" ]; then
    echo "  + default browser back to $was (a Chrome install had taken it)"; xdg-settings set default-web-browser "$was" 2>/dev/null
  fi
  # H.264 installed but still "missing": a stale GStreamer plugin cache; clear it and look again.
  if ! gst-inspect-1.0 avdec_h264 >/dev/null 2>&1 && [ -d "$HOME/.cache/gstreamer-1.0" ]; then
    rm -rf "$HOME/.cache/gstreamer-1.0"; gst-inspect-1.0 avdec_h264 >/dev/null 2>&1 && echo "  + GStreamer plugin cache rebuilt: H.264 found"
  fi
  # Adom fonts.
  if ! (fc-list 2>/dev/null | grep -qi "familjen grotesk" && fc-list | grep -qi satoshi && fc-list | grep -qi "jetbrains mono"); then
    local fd="$HOME/.local/share/fonts/adom" tmp; mkdir -p "$fd"; tmp=$(mktemp -d)
    echo "  + Adom fonts -> $fd"
    curl -fsSL -o "$fd/FamiljenGrotesk[wght].ttf" "https://github.com/google/fonts/raw/main/ofl/familjengrotesk/FamiljenGrotesk%5Bwght%5D.ttf"
    curl -fsSL -o "$fd/JetBrainsMono[wght].ttf" "https://github.com/google/fonts/raw/main/ofl/jetbrainsmono/JetBrainsMono%5Bwght%5D.ttf"
    if curl -fsSL -o "$tmp/satoshi.zip" "https://api.fontshare.com/v2/fonts/download/satoshi"; then
      python3 - "$tmp/satoshi.zip" "$fd" <<'PY'
import sys, zipfile, os
z = zipfile.ZipFile(sys.argv[1])
for n in z.namelist():
    b = os.path.basename(n)
    if b.lower().endswith(('.ttf', '.otf')) and 'variable' in n.lower() and b:
        open(os.path.join(sys.argv[2], b), 'wb').write(z.read(n))
PY
    fi
    rm -rf "$tmp"; fc-cache -f "$fd" >/dev/null 2>&1
  fi
  # Flatpak apps (KiCad) visible in menus and icons now, not only after the next login.
  local ex
  for ex in /var/lib/flatpak/exports/share "$HOME/.local/share/flatpak/exports/share"; do
    [ -d "$ex/applications" ] || continue
    mkdir -p "$HOME/.local/share/applications"
    for f in "$ex"/applications/*.desktop; do [ -e "$f" ] && ln -sf "$f" "$HOME/.local/share/applications/$(basename "$f")"; done
    if [ -d "$ex/icons" ]; then (cd "$ex/icons" && find . \( -type f -o -type l \) | while read -r i; do mkdir -p "$HOME/.local/share/icons/$(dirname "$i")"; ln -sf "$ex/icons/$i" "$HOME/.local/share/icons/$i"; done); fi
  done
  mkdir -p "$HOME/.config/environment.d"
  [ -f "$HOME/.config/environment.d/60-flatpak.conf" ] || printf 'XDG_DATA_DIRS=%s/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}\n' "$HOME" > "$HOME/.config/environment.d/60-flatpak.conf"
  have update-desktop-database && update-desktop-database "$HOME/.local/share/applications" >/dev/null 2>&1
  have gtk-update-icon-cache && [ -d "$HOME/.local/share/icons/hicolor" ] && gtk-update-icon-cache -q -t "$HOME/.local/share/icons/hicolor" 2>/dev/null
  # Tray on GNOME (Debian, Fedora): enable the AppIndicator extension; it loads at the next login.
  if is_gnome && [ "${ID:-}" != ubuntu ] && have gnome-extensions && [ -d /usr/share/gnome-shell/extensions/[email protected] ]; then
    gnome-extensions enable [email protected] 2>/dev/null && echo "  + tray extension enabled (active after you log out and in once)"
  fi
  run_checks; print_checks
}

case "$MODE" in
  check) run_checks; print_checks ;;
  apply-system) apply_system ;;
  apply-user) apply_user ;;
  version) echo "$HHS_VERSION" ;;
  *) echo "usage: $0 check [--json] | apply-system [--user U --desktop D --session S --with-chrome --dry-run] | apply-user"; exit 2 ;;
esac