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 alpine)" -eq 1 ]; then
54 elif [ "$(cat /etc/*-release | grep -cim1 fedora)" -eq 1 ]; then
55 if [ "$(cat /etc/*-release | grep -cim1 23)" -eq 1 ]; then
59 if [ "$(cat /etc/*-release | grep -cim1 24)" -eq 1 ]; then
63 elif [ "$(cat /etc/*-release | grep -cim1 opensuse)" -eq 1 ]; then
64 if [ "$(cat /etc/*-release | grep -cim1 13.2)" -eq 1 ]; then
68 if [ "$(cat /etc/*-release | grep -cim1 42.1)" -eq 1 ]; then
74 # Cannot determine Linux distribution, assuming Ubuntu 14.04.
79 if [ -z "$__DOTNET_PKG" ]; then
84 __DOTNET_PKG=dotnet-dev-osx-x64
89 __DOTNET_PKG="dotnet-dev-$(get_current_linux_name)-x64"
94 echo "Unsupported OS '$OSName' detected. Downloading ubuntu-x64 tools."
96 __DOTNET_PKG=dotnet-dev-ubuntu-x64
101 __CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
102 echo ".NET CLI will be downloaded from $__CLIDownloadURL"
103 echo "Locating $__PROJECT_JSON_FILE to see if we already downloaded .NET CLI tools..."
105 if [ ! -e $__PROJECT_JSON_FILE ]; then
106 echo "$__PROJECT_JSON_FILE not found. Proceeding to download .NET CLI tools. "
107 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
109 if [ ! -e $__DOTNET_PATH ]; then
110 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
111 which curl > /dev/null 2> /dev/null
112 if [ $? -ne 0 ]; then
113 mkdir -p "$__DOTNET_PATH"
114 wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
115 echo "wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
117 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
118 echo "curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
121 tar -xf $__DOTNET_PATH/dotnet.tar
122 if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then
123 find $__DOTNET_PATH -name *.ni.* | xargs rm 2>/dev/null
124 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin
125 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin/dnx
126 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/runtime/coreclr
132 mkdir "$__PROJECT_JSON_PATH"
133 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
135 if [ ! -e $__BUILD_TOOLS_PATH ]; then
136 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE
139 # On ubuntu 14.04, /bin/sh (symbolic link) calls /bin/dash by default.
140 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR
142 cp $__TOOLRUNTIME_DIR/NuGet.Frameworks.dll $__TOOLRUNTIME_DIR/dotnetcli/sdk/$__DOTNET_TOOLS_VERSION
145 echo "$__PROJECT_JSON_FILE found. Skipping .NET CLI installation."