#!/usr/bin/env bash # Installs the .NET SDK for a CI job, instead of actions/setup-dotnet (a JavaScript action, which needs Node). Like # that action it takes the newest SDK of the channel (default 10.0, like «10.0.x»), but it verifies it: the version # and the SHA-512 hash of the archive come from Microsoft's release metadata (read with json.awk and dotnet-sdk.awk, # POSIX awk), the archive from builds.dotnet.microsoft.com, and it is installed only if the hash matches. Never an # install script downloaded on the fly. # # .gitea/scripts/dotnet.sh [canale] # # Where: in the runner's tool cache (RUNNER_TOOL_CACHE, the act-toolcache volume that act_runner mounts in every job, # containers included), in febe-dotnet/; without it, in the job's temporary folder. A version already # installed and verified is not downloaded again; older versions in febe-dotnet are removed. Adds dotnet to the PATH # of the following steps (GITHUB_PATH) and writes DOTNET_ROOT (GITHUB_ENV); outside the CI it only prints the folder. # Needs curl, tar, sha512sum and awk. In the Debian container of the tests the SDK's system libraries (ICU, OpenSSL) # are installed by ambiente-prove.sh; on the runner image ICU is not guaranteed, and the jobs that run there # (installatore, windows, release) use DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true. set -euo pipefail canale="${1:-10.0}" [[ "$canale" =~ ^[0-9]+\.[0-9]+$ ]] || { echo "Canale .NET non valido: «$canale» (per esempio 10.0)." >&2; exit 2; } qui="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" case "$(uname -s)-$(uname -m)" in Linux-x86_64) rid=linux-x64 ;; Linux-aarch64) rid=linux-arm64 ;; *) echo "Piattaforma non prevista per l'SDK .NET della CI: $(uname -s)-$(uname -m)." >&2; exit 2 ;; esac radice="${RUNNER_TOOL_CACHE:-${RUNNER_TEMP:-/tmp}}/febe-dotnet" mkdir -p "$radice" temporanea="$(mktemp -d "$radice/.scarico-XXXXXX")" trap 'rm -rf "$temporanea"' EXIT echo "== SDK .NET $canale" curl -fsSL --retry 3 --retry-delay 5 --max-time 120 -o "$temporanea/releases.json" \ "https://builds.dotnet.microsoft.com/dotnet/release-metadata/$canale/releases.json" scelta=$(LC_ALL=C awk -v rid="$rid" -f "$qui/json.awk" -f "$qui/dotnet-sdk.awk" "$temporanea/releases.json") IFS=$'\t' read -r versione indirizzo sha512 <<< "$scelta" [[ "$versione" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || { echo "Versione dell'SDK non valida: «$versione»." >&2; exit 1; } [[ "$versione" == "$canale".* ]] || { echo "L'SDK $versione non è del canale $canale." >&2; exit 1; } cartella="$radice/$versione" if [[ -x "$cartella/dotnet" && -f "$cartella/.febe-sha512" && "$(cat "$cartella/.febe-sha512")" == "$sha512" ]]; then echo " $versione già installato in $cartella" else echo " $versione da $indirizzo" curl -fsSL --retry 3 --retry-delay 5 --max-time 900 -o "$temporanea/sdk.tar.gz" "$indirizzo" if ! echo "$sha512 $temporanea/sdk.tar.gz" | sha512sum -c --quiet -; then echo "L'impronta SHA-512 dell'SDK $versione non è quella dei metadati di Microsoft: non si installa." >&2 exit 1 fi mkdir "$temporanea/sdk" tar -xzf "$temporanea/sdk.tar.gz" -C "$temporanea/sdk" echo "$sha512" > "$temporanea/sdk/.febe-sha512" rm -rf "$cartella" mv "$temporanea/sdk" "$cartella" fi # The earlier versions, which no job will use any more (the CI runs one job at a time), and interrupted downloads. for vecchia in "$radice"/* "$radice"/.scarico-*; do [[ -d "$vecchia" && "$vecchia" != "$cartella" && "$vecchia" != "$temporanea" ]] || continue rm -rf "$vecchia" done "$cartella/dotnet" --version if [[ -n "${GITHUB_PATH:-}" ]]; then echo "$cartella" >> "$GITHUB_PATH" echo "DOTNET_ROOT=$cartella" >> "$GITHUB_ENV" else echo "$cartella" fi