Skip to content

Commit 9f6d78d

Browse files
added --os option to bash script (#118)
#13: added --os version for overriding automatic OS detection for primary links
1 parent 6b605aa commit 9f6d78d

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

src/dotnet-install.sh

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ -t 1 ] && command -v tput > /dev/null; then
4040
fi
4141

4242
say_warning() {
43-
printf "%b\n" "${yellow:-}dotnet_install: Warning: $1${normal:-}"
43+
printf "%b\n" "${yellow:-}dotnet_install: Warning: $1${normal:-}" >&3
4444
}
4545

4646
say_err() {
@@ -344,6 +344,30 @@ get_normalized_architecture_from_architecture() {
344344
return 1
345345
}
346346

347+
# args:
348+
# user_defined_os - $1
349+
get_normalized_os() {
350+
eval $invocation
351+
352+
local osname="$(to_lowercase "$1")"
353+
if [ ! -z "$osname" ]; then
354+
case "$osname" in
355+
osx | freebsd | rhel.6 | linux-musl | linux)
356+
echo "$osname"
357+
return 0
358+
;;
359+
*)
360+
say_err "'$user_defined_os' is not a supported value for --os option, supported values are: osx, linux, linux-musl, freebsd, rhel.6. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues."
361+
return 1
362+
;;
363+
esac
364+
else
365+
osname="$(get_current_os_name)" || return 1
366+
fi
367+
echo "$osname"
368+
return 0
369+
}
370+
347371
# The version text returned from the feeds is a 1-line or 2-line string:
348372
# For the SDK and the dotnet runtime (2 lines):
349373
# Line 1: # commit_hash
@@ -488,6 +512,7 @@ get_specific_version_from_version() {
488512
# channel - $2
489513
# normalized_architecture - $3
490514
# specific_version - $4
515+
# normalized_os - $5
491516
construct_download_link() {
492517
eval $invocation
493518

@@ -496,10 +521,8 @@ construct_download_link() {
496521
local normalized_architecture="$3"
497522
local specific_version="${4//[$'\t\r\n']}"
498523
local specific_product_version="$(get_specific_product_version "$1" "$4")"
499-
500-
local osname
501-
osname="$(get_current_os_name)" || return 1
502-
524+
local osname="$5"
525+
503526
local download_link=null
504527
if [[ "$runtime" == "dotnet" ]]; then
505528
download_link="$azure_feed/Runtime/$specific_version/dotnet-runtime-$specific_product_version-$osname-$normalized_architecture.tar.gz"
@@ -797,6 +820,9 @@ calculate_vars() {
797820
normalized_architecture="$(get_normalized_architecture_from_architecture "$architecture")"
798821
say_verbose "normalized_architecture=$normalized_architecture"
799822
823+
normalized_os="$(get_normalized_os "$user_defined_os")"
824+
say_verbose "normalized_os=$normalized_os"
825+
800826
specific_version="$(get_specific_version_from_version "$azure_feed" "$channel" "$normalized_architecture" "$version" "$json_file")"
801827
specific_product_version="$(get_specific_product_version "$azure_feed" "$specific_version")"
802828
say_verbose "specific_version=$specific_version"
@@ -805,7 +831,7 @@ calculate_vars() {
805831
return 1
806832
fi
807833
808-
download_link="$(construct_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")"
834+
download_link="$(construct_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version" "$normalized_os")"
809835
say_verbose "Constructed primary named payload URL: $download_link"
810836
811837
legacy_download_link="$(construct_legacy_download_link "$azure_feed" "$channel" "$normalized_architecture" "$specific_version")" || valid_legacy_download_link=false
@@ -966,6 +992,7 @@ runtime=""
966992
runtime_id=""
967993
override_non_versioned_files=true
968994
non_dynamic_parameters=""
995+
user_defined_os=""
969996
970997
while [ $# -ne 0 ]
971998
do
@@ -987,6 +1014,10 @@ do
9871014
shift
9881015
architecture="$1"
9891016
;;
1017+
--os|-[Oo][SS])
1018+
shift
1019+
user_defined_os="$1"
1020+
;;
9901021
--shared-runtime|-[Ss]hared[Rr]untime)
9911022
say_warning "The --shared-runtime flag is obsolete and may be removed in a future version of this script. The recommended usage is to specify '--runtime dotnet'."
9921023
if [ -z "$runtime" ]; then
@@ -1038,6 +1069,7 @@ do
10381069
shift
10391070
runtime_id="$1"
10401071
non_dynamic_parameters+=" $name "\""$1"\"""
1072+
say_warning "Use of --runtime-id is obsolete and should be limited to the versions below 2.1. To override architecture, use --architecture option instead. To override OS, use --os option instead."
10411073
;;
10421074
--jsonfile|-[Jj][Ss]on[Ff]ile)
10431075
shift
@@ -1077,6 +1109,11 @@ do
10771109
echo " --architecture <ARCHITECTURE> Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`."
10781110
echo " --arch,-Architecture,-Arch"
10791111
echo " Possible values: x64, arm, and arm64"
1112+
echo " --os <system> Specifies operating system to be used when selecting the installer."
1113+
echo " Overrides the OS determination approach used by the script. Supported values: osx, linux, linux-musl, freebsd, rhel.6."
1114+
echo " In case any other value is provided, the platform will be determined by the script based on machine configuration."
1115+
echo " Not supported for legacy links. Use --runtime-id to specify platform for legacy links."
1116+
echo " Refer to: https://aka.ms/dotnet-os-lifecycle for more information."
10801117
echo " --runtime <RUNTIME> Installs a shared runtime only, without the SDK."
10811118
echo " -Runtime"
10821119
echo " Possible values:"
@@ -1093,14 +1130,15 @@ do
10931130
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
10941131
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
10951132
echo " Note: global.json must have a value for 'SDK:Version'"
1096-
echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)."
1097-
echo " -RuntimeId"
10981133
echo " -?,--?,-h,--help,-Help Shows this help message"
10991134
echo ""
11001135
echo "Obsolete parameters:"
11011136
echo " --shared-runtime The recommended alternative is '--runtime dotnet'."
11021137
echo " This parameter is obsolete and may be removed in a future version of this script."
11031138
echo " Installs just the shared runtime bits, not the entire SDK."
1139+
echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)."
1140+
echo " -RuntimeId" The parameter is obsolete and may be removed in a future version of this script. Should be used only for versions below 2.1.
1141+
echo " For primary links to override OS or/and architecture, use --os and --architecture option instead."
11041142
echo ""
11051143
echo "Install Location:"
11061144
echo " Location is chosen in following order:"
@@ -1137,7 +1175,7 @@ if [ "$dry_run" = true ]; then
11371175
if [ "$valid_legacy_download_link" = true ]; then
11381176
say "Legacy named payload URL: $legacy_download_link"
11391177
fi
1140-
repeatable_command="./$script_name --version "\""$specific_version"\"" --install-dir "\""$install_root"\"" --architecture "\""$normalized_architecture"\"""
1178+
repeatable_command="./$script_name --version "\""$specific_version"\"" --install-dir "\""$install_root"\"" --architecture "\""$normalized_architecture"\"" --os "\""$normalized_os"\"""
11411179
if [[ "$runtime" == "dotnet" ]]; then
11421180
repeatable_command+=" --runtime "\""dotnet"\"""
11431181
elif [[ "$runtime" == "aspnetcore" ]]; then

0 commit comments

Comments
 (0)