3 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
5 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
6 # This is needed by CLI to function.
7 if [ -z "$HOME" ]; then
8 if [ ! -d "$__scriptpath/temp_home" ]; then
11 export HOME=$__scriptpath/temp_home
12 echo "HOME not defined; setting it to $HOME"
15 __PACKAGES_DIR=$__scriptpath/packages
16 __TOOLRUNTIME_DIR=$__scriptpath/Tools
17 __DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
18 __DOTNET_CMD=$__DOTNET_PATH/dotnet
19 if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json; fi
20 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
21 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
22 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
23 __PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
24 __PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
25 __PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"dnxcore50\": { } } }"
27 # Extended version of platform detection logic from dotnet/cli/scripts/obtain/dotnet-install.sh 16692fc
28 get_current_linux_name() {
30 if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
31 if [ "$(cat /etc/*-release | grep -cim1 16.04)" -eq 1 ]; then
35 if [ "$(cat /etc/*-release | grep -cim1 16.10)" -eq 1 ]; then
42 elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
45 elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
48 elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
51 elif [ "$(cat /etc/*-release | grep -cim1 fedora)" -eq 1 ]; then
52 if [ "$(cat /etc/*-release | grep -cim1 23)" -eq 1 ]; then
56 if [ "$(cat /etc/*-release | grep -cim1 24)" -eq 1 ]; then
60 elif [ "$(cat /etc/*-release | grep -cim1 opensuse)" -eq 1 ]; then
61 if [ "$(cat /etc/*-release | grep -cim1 13.2)" -eq 1 ]; then
65 if [ "$(cat /etc/*-release | grep -cim1 42.1)" -eq 1 ]; then
71 # Cannot determine Linux distribution, assuming Ubuntu 14.04.
76 if [ -z "$__DOTNET_PKG" ]; then
81 __DOTNET_PKG=dotnet-dev-osx-x64
86 __DOTNET_PKG="dotnet-dev-$(get_current_linux_name)-x64"
91 echo "Unsupported OS '$OSName' detected. Downloading ubuntu-x64 tools."
93 __DOTNET_PKG=dotnet-dev-ubuntu-x64
98 __CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
99 echo ".NET CLI will be downloaded from $__CLIDownloadURL"
100 echo "Locating $__PROJECT_JSON_FILE to see if we already downloaded .NET CLI tools..."
102 if [ ! -e $__PROJECT_JSON_FILE ]; then
103 echo "$__PROJECT_JSON_FILE not found. Proceeding to download .NET CLI tools. "
104 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
106 if [ ! -e $__DOTNET_PATH ]; then
107 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
108 which curl > /dev/null 2> /dev/null
109 if [ $? -ne 0 ]; then
110 mkdir -p "$__DOTNET_PATH"
111 wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
112 echo "wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
114 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
115 echo "curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
118 tar -xf $__DOTNET_PATH/dotnet.tar
119 if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then
120 find $__DOTNET_PATH -name *.ni.* | xargs rm 2>/dev/null
121 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin
122 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin/dnx
123 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/runtime/coreclr
129 mkdir "$__PROJECT_JSON_PATH"
130 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
132 if [ ! -e $__BUILD_TOOLS_PATH ]; then
133 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE
136 # On ubuntu 14.04, /bin/sh (symbolic link) calls /bin/dash by default.
137 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR
140 echo "$__PROJECT_JSON_FILE found. Skipping .NET CLI installation."