#!/usr/bin/env bash # Source from install.sh. Package commands use the supported distribution's signed feeds. ensure_dependencies() { local distribution=$1 version=$2 runtime=$3 persistence=$4 case "$distribution:$version" in ubuntu:24.04|debian:12|debian:13) ;; *) fail 'Automatic provisioning supports Ubuntu 24.04 and Debian 12/13.';; esac step='install base dependencies' if ! command -v curl >/dev/null || ! command -v update-ca-certificates >/dev/null; then apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl fi if [[ ! -x "$runtime" ]] || ! "$runtime" --list-runtimes | grep -q 'Microsoft.AspNetCore.App 10\.'; then step='install .NET 10 ASP.NET Core runtime' apt-get update if [[ "$distribution" == debian ]]; then local package_dir package_dir=$(mktemp -d) curl --fail --silent --show-error "https://packages.microsoft.com/config/debian/$version/packages-microsoft-prod.deb" -o "$package_dir/microsoft.deb" dpkg -i "$package_dir/microsoft.deb" rm -f -- "$package_dir/microsoft.deb" rmdir -- "$package_dir" apt-get update fi DEBIAN_FRONTEND=noninteractive apt-get install -y aspnetcore-runtime-10.0 fi [[ -x "$runtime" ]] && "$runtime" --list-runtimes | grep -q 'Microsoft.AspNetCore.App 10\.' || fail 'The .NET 10 ASP.NET Core runtime could not be provisioned.' if [[ "$persistence" == true ]]; then step='provision PostgreSQL server' if ! command -v pg_isready >/dev/null || ! pg_isready -q -h localhost -p 5432; then DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql systemctl enable --now postgresql fi local ready=false attempt for attempt in {1..30}; do if pg_isready -q -h localhost -p 5432; then ready=true; break; fi sleep 1 done [[ "$ready" == true ]] || fail 'PostgreSQL did not become available on localhost:5432.' fi }