dotnet-install.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if [ "$(getconf LONG_BIT)" -lt 64 ]; then
  54. # This is 32-bit OS running on 64-bit CPU (for example Raspberry Pi OS)
  55. buildarch=arm
  56. fi
  57. ;;
  58. loongarch64)
  59. buildarch=loongarch64
  60. ;;
  61. amd64|x86_64)
  62. buildarch=x64
  63. ;;
  64. armv*l)
  65. buildarch=arm
  66. ;;
  67. i[3-6]86)
  68. buildarch=x86
  69. ;;
  70. riscv64)
  71. buildarch=riscv64
  72. ;;
  73. *)
  74. echo "Unknown CPU $cpuname detected, treating it as x64"
  75. buildarch=x64
  76. ;;
  77. esac
  78. dotnetRoot="${repo_root}.dotnet"
  79. if [[ $architecture != "" ]] && [[ $architecture != $buildarch ]]; then
  80. dotnetRoot="$dotnetRoot/$architecture"
  81. fi
  82. InstallDotNet "$dotnetRoot" $version "$architecture" $runtime true $runtimeSourceFeed $runtimeSourceFeedKey || {
  83. local exit_code=$?
  84. Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "dotnet-install.sh failed (exit code '$exit_code')." >&2
  85. ExitWithExitCode $exit_code
  86. }
  87. ExitWithExitCode 0