#!/usr/bin/env bash # Distribution package adapters; normal installation uses signed native package feeds. has_runtime() { [[ -x "$dotnet" ]] && "$dotnet" --list-runtimes | rg_runtime; } rg_runtime() { grep -q 'Microsoft.AspNetCore.App 10\.'; } ensure_dependencies() { local family='' source "${HEALTHAPP_OS_RELEASE:-/etc/os-release}" case " $ID ${ID_LIKE:-} " in *' debian '*|*' ubuntu '*) family=apt;; *' fedora '*|*' rhel '*) family=dnf;; *' arch '*|*' manjaro '*) family=pacman;; *) fail 'No supported dependency adapter for this systemd distribution.';; esac stage='distribution dependencies' case "$family" in apt) apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl if ! has_runtime; then if ! apt-cache policy aspnetcore-runtime-10.0 | grep -Eq 'Candidate: [0-9]'; then if [[ "$ID" == debian && "$VERSION_ID" =~ ^(12|13)$ ]]; then local feed; feed=$(mktemp -d) curl --fail --silent --show-error --location "https://packages.microsoft.com/config/debian/$VERSION_ID/packages-microsoft-prod.deb" -o "$feed/feed.deb" dpkg -i "$feed/feed.deb"; apt-get update elif [[ "$ID" == ubuntu && "$VERSION_ID" == 24.04 ]]; then DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common add-apt-repository -y ppa:dotnet/backports; apt-get update else fail 'No identified .NET 10 feed; derivative versions are not mapped to an unrelated upstream.'; fi fi DEBIAN_FRONTEND=noninteractive apt-get install -y aspnetcore-runtime-10.0 fi if [[ "$mode" == local ]]; then DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql; systemctl enable --now postgresql; fi ;; dnf) dnf install -y ca-certificates curl has_runtime || dnf install -y aspnetcore-runtime-10.0 if [[ "$mode" == local ]]; then dnf install -y postgresql-server postgresql [[ -f /var/lib/pgsql/data/PG_VERSION ]] || postgresql-setup --initdb systemctl enable --now postgresql fi ;; pacman) # Avoid partial rolling-distribution upgrades when installing dependencies. pacman -Syu --noconfirm --needed ca-certificates curl has_runtime || pacman -S --noconfirm --needed aspnet-runtime if [[ "$mode" == local ]]; then pacman -S --noconfirm --needed postgresql if [[ ! -f /var/lib/postgres/data/PG_VERSION ]]; then install -d -o postgres -g postgres -m 700 /var/lib/postgres/data runuser -u postgres -- initdb -D /var/lib/postgres/data --auth-local=peer --auth-host=scram-sha-256 fi systemctl enable --now postgresql fi ;; esac has_runtime || fail '.NET 10 ASP.NET Core runtime is unavailable after dependency provisioning.' if [[ "$mode" == local ]]; then stage='local PostgreSQL readiness' local ready=false attempt for attempt in {1..30}; do if pg_isready -q -h 127.0.0.1 -p 5432; then ready=true; break; fi; sleep 1; done [[ "$ready" == true ]] || fail 'Local PostgreSQL is not ready on port 5432.' fi }