57 lines
3.5 KiB
Bash
57 lines
3.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Source from install.sh. Package commands use the supported distribution's signed feeds.
|
|
package_available() {
|
|
local policy
|
|
policy=$(LC_ALL=C apt-cache policy "$1") || return 1
|
|
[[ "$policy" =~ Candidate:[[:space:]]+([^[:space:]]+) && "${BASH_REMATCH[1]}" != '(none)' ]]
|
|
}
|
|
|
|
ensure_dependencies() {
|
|
local distribution=$1 version=$2 runtime=$3 persistence=$4 ancestry=${5:-}
|
|
case " $distribution $ancestry " in
|
|
*" debian "*|*" ubuntu "*) ;;
|
|
*) fail 'Automatic Linux provisioning requires a Debian/Ubuntu-based distribution (ID or ID_LIKE).';;
|
|
esac
|
|
command -v apt-get >/dev/null && command -v apt-cache >/dev/null || fail 'Debian/Ubuntu provisioning requires apt-get and apt-cache.'
|
|
step='refresh dependency package availability'
|
|
apt-get update || fail 'Could not refresh package feeds; check network access and configured repositories.'
|
|
step='install base dependencies'
|
|
if ! command -v curl >/dev/null || ! command -v update-ca-certificates >/dev/null; then
|
|
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'
|
|
if ! package_available aspnetcore-runtime-10.0 && [[ "$distribution" == debian ]]; then
|
|
[[ "$version" =~ ^[0-9]+$ ]] || fail 'Cannot identify a compatible Microsoft Debian package repository from VERSION_ID.'
|
|
local package_dir
|
|
package_dir=$(mktemp -d)
|
|
if ! curl --fail --silent --show-error --location "https://packages.microsoft.com/config/debian/$version/packages-microsoft-prod.deb" -o "$package_dir/microsoft.deb"; then
|
|
rm -f -- "$package_dir/microsoft.deb"
|
|
rmdir -- "$package_dir"
|
|
fail "No accessible Microsoft Debian $version repository; aspnetcore-runtime-10.0 is unavailable in configured feeds."
|
|
fi
|
|
dpkg -i "$package_dir/microsoft.deb"
|
|
rm -f -- "$package_dir/microsoft.deb"
|
|
rmdir -- "$package_dir"
|
|
apt-get update
|
|
fi
|
|
package_available aspnetcore-runtime-10.0 || fail "Required package aspnetcore-runtime-10.0 is unavailable for $distribution $version in configured feeds; no compatible runtime repository could be identified automatically."
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y aspnetcore-runtime-10.0 || fail 'Failed to install aspnetcore-runtime-10.0 from configured feeds.'
|
|
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
|
|
package_available postgresql || fail "Required package postgresql is unavailable for $distribution $version in configured feeds."
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql || fail 'Failed to install PostgreSQL from configured feeds.'
|
|
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
|
|
}
|