darc-init.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. source="${BASH_SOURCE[0]}"
  3. darcVersion=''
  4. versionEndpoint='https://maestro.dot.net/api/assets/darc-version?api-version=2020-02-20'
  5. verbosity='minimal'
  6. while [[ $# > 0 ]]; do
  7. opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")"
  8. case "$opt" in
  9. --darcversion)
  10. darcVersion=$2
  11. shift
  12. ;;
  13. --versionendpoint)
  14. versionEndpoint=$2
  15. shift
  16. ;;
  17. --verbosity)
  18. verbosity=$2
  19. shift
  20. ;;
  21. --toolpath)
  22. toolpath=$2
  23. shift
  24. ;;
  25. *)
  26. echo "Invalid argument: $1"
  27. usage
  28. exit 1
  29. ;;
  30. esac
  31. shift
  32. done
  33. # resolve $source until the file is no longer a symlink
  34. while [[ -h "$source" ]]; do
  35. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  36. source="$(readlink "$source")"
  37. # if $source was a relative symlink, we need to resolve it relative to the path where the
  38. # symlink file was located
  39. [[ $source != /* ]] && source="$scriptroot/$source"
  40. done
  41. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  42. . "$scriptroot/tools.sh"
  43. if [ -z "$darcVersion" ]; then
  44. darcVersion=$(curl -X GET "$versionEndpoint" -H "accept: text/plain")
  45. fi
  46. function InstallDarcCli {
  47. local darc_cli_package_name="microsoft.dotnet.darc"
  48. InitializeDotNetCli true
  49. local dotnet_root=$_InitializeDotNetCli
  50. if [ -z "$toolpath" ]; then
  51. local tool_list=$($dotnet_root/dotnet tool list -g)
  52. if [[ $tool_list = *$darc_cli_package_name* ]]; then
  53. echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name -g)
  54. fi
  55. else
  56. local tool_list=$($dotnet_root/dotnet tool list --tool-path "$toolpath")
  57. if [[ $tool_list = *$darc_cli_package_name* ]]; then
  58. echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name --tool-path "$toolpath")
  59. fi
  60. fi
  61. local arcadeServicesSource="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json"
  62. echo "Installing Darc CLI version $darcVersion..."
  63. echo "You may need to restart your command shell if this is the first dotnet tool you have installed."
  64. if [ -z "$toolpath" ]; then
  65. echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity -g)
  66. else
  67. echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity --tool-path "$toolpath")
  68. fi
  69. }
  70. InstallDarcCli