dotnet-install.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env bash
  2. source="${BASH_SOURCE[0]}"
  3. # resolve $source until the file is no longer a symlink
  4. while [[ -h "$source" ]]; do
  5. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  6. source="$(readlink "$source")"
  7. # if $source was a relative symlink, we need to resolve it relative to the path where the
  8. # symlink file was located
  9. [[ $source != /* ]] && source="$scriptroot/$source"
  10. done
  11. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  12. . "$scriptroot/tools.sh"
  13. version='Latest'
  14. architecture=''
  15. runtime='dotnet'
  16. runtimeSourceFeed=''
  17. runtimeSourceFeedKey=''
  18. while [[ $# > 0 ]]; do
  19. opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
  20. case "$opt" in
  21. -version|-v)
  22. shift
  23. version="$1"
  24. ;;
  25. -architecture|-a)
  26. shift
  27. architecture="$1"
  28. ;;
  29. -runtime|-r)
  30. shift
  31. runtime="$1"
  32. ;;
  33. -runtimesourcefeed)
  34. shift
  35. runtimeSourceFeed="$1"
  36. ;;
  37. -runtimesourcefeedkey)
  38. shift
  39. runtimeSourceFeedKey="$1"
  40. ;;
  41. *)
  42. Write-PipelineTelemetryError -Category 'Build' -Message "Invalid argument: $1"
  43. exit 1
  44. ;;
  45. esac
  46. shift
  47. done
  48. # Use uname to determine what the CPU is, see https://en.wikipedia.org/wiki/Uname#Examples
  49. cpuname=$(uname -m)
  50. case $cpuname in
  51. arm64|aarch64)
  52. buildarch=arm64
  53. ;;
  54. loongarch64)
  55. buildarch=loongarch64
  56. ;;
  57. amd64|x86_64)
  58. buildarch=x64
  59. ;;
  60. armv*l)
  61. buildarch=arm
  62. ;;
  63. i[3-6]86)
  64. buildarch=x86
  65. ;;
  66. *)
  67. echo "Unknown CPU $cpuname detected, treating it as x64"
  68. buildarch=x64
  69. ;;
  70. esac
  71. dotnetRoot="${repo_root}.dotnet"
  72. if [[ $architecture != "" ]] && [[ $architecture != $buildarch ]]; then
  73. dotnetRoot="$dotnetRoot/$architecture"
  74. fi
  75. InstallDotNet $dotnetRoot $version "$architecture" $runtime true $runtimeSourceFeed $runtimeSourceFeedKey || {
  76. local exit_code=$?
  77. Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "dotnet-install.sh failed (exit code '$exit_code')." >&2
  78. ExitWithExitCode $exit_code
  79. }
  80. ExitWithExitCode 0