dotnet-install.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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" | awk '{print tolower($0)}')"
  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.
  49. cpuname=$(uname -p)
  50. # Some Linux platforms report unknown for platform, but the arch for machine.
  51. if [[ "$cpuname" == "unknown" ]]; then
  52. cpuname=$(uname -m)
  53. fi
  54. case $cpuname in
  55. aarch64)
  56. buildarch=arm64
  57. ;;
  58. amd64|x86_64)
  59. buildarch=x64
  60. ;;
  61. armv7l)
  62. buildarch=arm
  63. ;;
  64. i686)
  65. buildarch=x86
  66. ;;
  67. *)
  68. echo "Unknown CPU $cpuname detected, treating it as x64"
  69. buildarch=x64
  70. ;;
  71. esac
  72. dotnetRoot="$repo_root/.dotnet"
  73. if [[ $architecture != "" ]] && [[ $architecture != $buildarch ]]; then
  74. dotnetRoot="$dotnetRoot/$architecture"
  75. fi
  76. InstallDotNet $dotnetRoot $version "$architecture" $runtime true $runtimeSourceFeed $runtimeSourceFeedKey || {
  77. local exit_code=$?
  78. Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "dotnet-install.sh failed (exit code '$exit_code')." >&2
  79. ExitWithExitCode $exit_code
  80. }
  81. ExitWithExitCode 0