@@ -26,6 +26,10 @@ DOTNET_CDN_FEED_URI="https://dotnetcli.azureedge.net"
2626# Ubuntu 22.04 and on do not ship with libssl1.1, which is required for versions of .NET < 6.0
2727DOTNET_VERSION_CODENAMES_REQUIRE_OLDER_LIBSSL_1=" buster bullseye bionic focal hirsute"
2828
29+ # Comma-separated list of dotnet versions to be installed
30+ # alongside DOTNET_VERSION, but not set as default.
31+ ADDITIONAL_VERSIONS=${ADDITIONAL_VERSIONS:- " " }
32+
2933# Exit on failure.
3034set -e
3135
@@ -235,6 +239,7 @@ install_using_apt() {
235239# DOTNET_DOWNLOAD_NAME
236240get_full_version_details () {
237241 local sdk_or_runtime=" $1 "
242+ local VERSION=" $2 "
238243 local architecture
239244 local dotnet_channel_version
240245 local dotnet_releases_url
@@ -249,12 +254,12 @@ get_full_version_details() {
249254 # Set architecture variable to current user's architecture (x64 or ARM64).
250255 architecture=" $( get_architecture_name_for_target_os) "
251256
252- # Set DOTNET_VERSION to empty string to ensure jq includes all .NET versions in reverse sort below
253- if [ " ${DOTNET_VERSION } " = " latest" ]; then
254- DOTNET_VERSION =" "
257+ # Set VERSION to empty string to ensure jq includes all .NET versions in reverse sort below
258+ if [ " ${VERSION } " = " latest" ]; then
259+ VERSION =" "
255260 fi
256261
257- dotnet_patchless_version=" $( echo " ${DOTNET_VERSION } " | cut -d " ." --field=1,2) "
262+ dotnet_patchless_version=" $( echo " ${VERSION } " | cut -d " ." --field=1,2) "
258263
259264 set +e
260265 dotnet_channel_version=" $( curl -s " ${DOTNET_CDN_FEED_URI} /dotnet/release-metadata/releases-index.json" | jq -r --arg channel_version " ${dotnet_patchless_version} " ' [."releases-index"[]] | sort_by(."channel-version") | reverse | map( select(."channel-version" | startswith($channel_version))) | first | ."channel-version"' ) "
@@ -274,29 +279,30 @@ get_full_version_details() {
274279 if [ -n " ${dotnet_releases_json} " ] && [[ ! " ${dotnet_releases_json} " = * " Error" * ]]; then
275280 dotnet_latest_version=" $( echo " ${dotnet_releases_json} " | jq -r --arg sdk_or_runtime " ${sdk_or_runtime} " ' ."latest-\($sdk_or_runtime)"' ) "
276281 # If user-specified version has 2 or more dots, use it as is. Otherwise use latest version.
277- if [ " $( echo " ${DOTNET_VERSION } " | grep -o " \." | wc -l) " -lt " 2" ]; then
278- DOTNET_VERSION =" ${dotnet_latest_version} "
282+ if [ " $( echo " ${VERSION } " | grep -o " \." | wc -l) " -lt " 2" ]; then
283+ VERSION =" ${dotnet_latest_version} "
279284 fi
280285
281- dotnet_download_details=" $( echo " ${dotnet_releases_json} " | jq -r --arg sdk_or_runtime " ${sdk_or_runtime} " --arg dotnet_version " ${DOTNET_VERSION } " --arg arch " ${architecture} " ' .releases[]."\($sdk_or_runtime)" | select(.version==$dotnet_version) | .files[] | select(.name=="dotnet-\($sdk_or_runtime)-linux-\($arch).tar.gz")' ) "
286+ dotnet_download_details=" $( echo " ${dotnet_releases_json} " | jq -r --arg sdk_or_runtime " ${sdk_or_runtime} " --arg dotnet_version " ${VERSION } " --arg arch " ${architecture} " ' .releases[]."\($sdk_or_runtime)" | select(.version==$dotnet_version) | .files[] | select(.name=="dotnet-\($sdk_or_runtime)-linux-\($arch).tar.gz")' ) "
282287 if [ -n " ${dotnet_download_details} " ]; then
283- echo " Found .NET binary version ${DOTNET_VERSION } "
288+ echo " Found .NET binary version ${VERSION } "
284289 DOTNET_DOWNLOAD_URL=" $( echo " ${dotnet_download_details} " | jq -r ' .url' ) "
285290 DOTNET_DOWNLOAD_HASH=" $( echo " ${dotnet_download_details} " | jq -r ' .hash' ) "
286291 DOTNET_DOWNLOAD_NAME=" $( echo " ${dotnet_download_details} " | jq -r ' .name' ) "
287292 else
288- err " Unable to find .NET binary for version ${DOTNET_VERSION } "
293+ err " Unable to find .NET binary for version ${VERSION } "
289294 exit 1
290295 fi
291296 else
292- err " Unable to find .NET release details for version ${DOTNET_VERSION } at ${dotnet_releases_url} "
297+ err " Unable to find .NET release details for version ${VERSION } at ${dotnet_releases_url} "
293298 exit 1
294299 fi
295300}
296301
297302# Install .NET CLI using the .NET releases url
298303install_using_dotnet_releases_url () {
299304 local sdk_or_runtime=" $1 "
305+ local VERSION=" $2 "
300306
301307 # Check listed package dependecies and install them if they are not already installed.
302308 # NOTE: icu-devtools is a small package with similar dependecies to .NET.
@@ -313,11 +319,11 @@ install_using_dotnet_releases_url() {
313319 check_packages libssl3.0
314320 fi
315321
316- get_full_version_details " ${sdk_or_runtime} "
322+ get_full_version_details " ${sdk_or_runtime} " " ${VERSION} "
317323
318- DOTNET_INSTALL_PATH=" ${TARGET_DOTNET_ROOT} /${DOTNET_VERSION } "
324+ DOTNET_INSTALL_PATH=" ${TARGET_DOTNET_ROOT} /${VERSION } "
319325 if [ -d " ${DOTNET_INSTALL_PATH} " ]; then
320- echo " (!) Dotnet version ${DOTNET_VERSION } already exists."
326+ echo " (!) Dotnet version ${VERSION } already exists."
321327 exit 1
322328 fi
323329 # exports DOTNET_DOWNLOAD_URL, DOTNET_DOWNLOAD_HASH, DOTNET_DOWNLOAD_NAME
@@ -402,6 +408,7 @@ echo "(*) Installing .NET CLI..."
402408. /etc/os-release
403409architecture=" $( dpkg --print-architecture) "
404410
411+ CHANGE_OWNERSHIP=" false"
405412if [[ " ${DOTNET_ARCHIVE_ARCHITECTURES} " = * " ${architecture} " * ]] && [[ " ${DOTNET_ARCHIVE_VERSION_CODENAMES} " = * " ${VERSION_CODENAME} " * ]] && [[ " ${INSTALL_USING_APT} " = " true" ]]; then
406413 echo " Detected ${VERSION_CODENAME} on ${architecture} . Attempting to install dotnet from apt"
407414 install_using_apt " ${DOTNET_SDK_OR_RUNTIME} "
@@ -411,17 +418,31 @@ else
411418 else
412419 echo " Could not install dotnet from apt. Attempting to install dotnet from releases url"
413420 fi
421+ install_using_dotnet_releases_url " ${DOTNET_SDK_OR_RUNTIME} " " ${DOTNET_VERSION} "
422+ CHANGE_OWNERSHIP=" true"
423+ fi
414424
425+ # Additional dotnet versions to be installed but not be set as default.
426+ if [ ! -z " ${ADDITIONAL_VERSIONS} " ]; then
427+ OLDIFS=$IFS
428+ IFS=" ,"
429+ read -a additional_versions <<< " $ADDITIONAL_VERSIONS"
430+ for version in " ${additional_versions[@]} " ; do
431+ OVERRIDE_DEFAULT_VERSION=" false"
432+ install_using_dotnet_releases_url " ${DOTNET_SDK_OR_RUNTIME} " " ${version} "
433+ done
434+ IFS=$OLDIFS
435+ fi
436+
437+ if [ " ${CHANGE_OWNERSHIP} " = " true" ]; then
415438 if ! cat /etc/group | grep -e " ^dotnet:" > /dev/null 2>&1 ; then
416439 groupadd -r dotnet
417440 fi
418441 usermod -a -G dotnet " ${USERNAME} "
419442
420- install_using_dotnet_releases_url " ${DOTNET_SDK_OR_RUNTIME} "
421-
422443 chown -R " ${USERNAME} :dotnet" " ${TARGET_DOTNET_ROOT} "
423444 chmod -R g+r+w " ${TARGET_DOTNET_ROOT} "
424445 find " ${TARGET_DOTNET_ROOT} " -type d | xargs -n 1 chmod g+s
425446fi
426447
427- echo " Done!"
448+ echo " Done!"
0 commit comments