[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx ...
[mono-project.git] / eng / common / darc-init.sh
blob82b2b576776db94eb0afdf6304fd2d7c30036d81
1 #!/usr/bin/env bash
3 source="${BASH_SOURCE[0]}"
4 darcVersion=''
5 versionEndpoint="https://maestro-prod.westus2.cloudapp.azure.com/api/assets/darc-version?api-version=2019-01-16"
6 verbosity=m
8 while [[ $# > 0 ]]; do
9 opt="$(echo "$1" | awk '{print tolower($0)}')"
10 case "$opt" in
11 --darcversion)
12 darcVersion=$2
13 shift
15 --versionendpoint)
16 versionEndpoint=$2
17 shift
19 --verbosity)
20 verbosity=$2
21 shift
23 --toolpath)
24 toolpath=$2
25 shift
28 echo "Invalid argument: $1"
29 usage
30 exit 1
32 esac
34 shift
35 done
37 # resolve $source until the file is no longer a symlink
38 while [[ -h "$source" ]]; do
39 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
40 source="$(readlink "$source")"
41 # if $source was a relative symlink, we need to resolve it relative to the path where the
42 # symlink file was located
43 [[ $source != /* ]] && source="$scriptroot/$source"
44 done
45 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
47 . "$scriptroot/tools.sh"
49 if [ -z "$darcVersion" ]; then
50 darcVersion=$(curl -X GET "$versionEndpoint" -H "accept: text/plain")
53 function InstallDarcCli {
54 local darc_cli_package_name="microsoft.dotnet.darc"
56 InitializeDotNetCli
57 local dotnet_root=$_InitializeDotNetCli
59 if [ -z "$toolpath" ]; then
60 local tool_list=$($dotnet_root/dotnet tool list -g)
61 if [[ $tool_list = *$darc_cli_package_name* ]]; then
62 echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name -g)
64 else
65 local tool_list=$($dotnet_root/dotnet tool list --tool-path "$toolpath")
66 if [[ $tool_list = *$darc_cli_package_name* ]]; then
67 echo $($dotnet_root/dotnet tool uninstall $darc_cli_package_name --tool-path "$toolpath")
71 local arcadeServicesSource="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json"
73 echo "Installing Darc CLI version $darcVersion..."
74 echo "You may need to restart your command shell if this is the first dotnet tool you have installed."
75 if [ -z "$toolpath" ]; then
76 echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity -g)
77 else
78 echo $($dotnet_root/dotnet tool install $darc_cli_package_name --version $darcVersion --add-source "$arcadeServicesSource" -v $verbosity --tool-path "$toolpath")
82 InstallDarcCli