3 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
4 __init_tools_log=$__scriptpath/init-tools.log
5 __PACKAGES_DIR=$__scriptpath/packages
6 __TOOLRUNTIME_DIR=$__scriptpath/Tools
7 __DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
8 __DOTNET_CMD=$__DOTNET_PATH/dotnet
9 if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json; fi
10 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
11 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
12 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
13 __PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
14 __PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
15 __PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"netcoreapp1.0\": { } } }"
16 __INIT_TOOLS_DONE_MARKER=$__PROJECT_JSON_PATH/done
18 # Extended version of platform detection logic from dotnet/cli/scripts/obtain/dotnet-install.sh 16692fc
19 get_current_linux_name() {
21 if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
22 if [ "$(cat /etc/*-release | grep -cim1 16.04)" -eq 1 ]; then
26 if [ "$(cat /etc/*-release | grep -cim1 16.10)" -eq 1 ]; then
33 elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
36 elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
39 elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
42 elif [ "$(cat /etc/*-release | grep -cim1 alpine)" -eq 1 ]; then
45 elif [ "$(cat /etc/*-release | grep -cim1 fedora)" -eq 1 ]; then
46 if [ "$(cat /etc/*-release | grep -cim1 23)" -eq 1 ]; then
50 if [ "$(cat /etc/*-release | grep -cim1 24)" -eq 1 ]; then
54 elif [ "$(cat /etc/*-release | grep -cim1 opensuse)" -eq 1 ]; then
55 if [ "$(cat /etc/*-release | grep -cim1 13.2)" -eq 1 ]; then
59 if [ "$(cat /etc/*-release | grep -cim1 42.1)" -eq 1 ]; then
65 # Cannot determine Linux distribution, assuming Ubuntu 14.04.
70 if [ -z "$__DOTNET_PKG" ]; then
75 __DOTNET_PKG=dotnet-dev-osx-x64
80 __DOTNET_PKG="dotnet-dev-$(get_current_linux_name)-x64"
85 echo "Unsupported OS '$OSName' detected. Downloading ubuntu-x64 tools."
87 __DOTNET_PKG=dotnet-dev-ubuntu-x64
92 if [ ! -e $__INIT_TOOLS_DONE_MARKER ]; then
93 __PATCH_CLI_NUGET_FRAMEWORKS=0
95 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
96 echo "Running: $__scriptpath/init-tools.sh" > $__init_tools_log
98 if [ ! -e $__DOTNET_PATH ]; then
100 mkdir -p "$__DOTNET_PATH"
102 if [ -n "$DOTNET_TOOLSET_DIR" ] && [ -d "$DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION" ]; then
103 echo "Copying $DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION to $__DOTNET_PATH" >> $__init_tools_log
104 cp -r $DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION/* $__DOTNET_PATH
105 elif [ -n "$DOTNET_TOOL_DIR" ] && [ -d "$DOTNET_TOOL_DIR" ]; then
106 echo "Copying $DOTNET_TOOL_DIR to $__DOTNET_PATH" >> $__init_tools_log
107 cp -r $DOTNET_TOOL_DIR/* $__DOTNET_PATH
109 echo "Installing dotnet cli..."
110 __DOTNET_LOCATION="https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz"
111 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
112 echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'" >> $__init_tools_log
113 if command -v curl > /dev/null; then
114 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
116 wget -q -O $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
119 tar -xf $__DOTNET_PATH/dotnet.tar
123 __PATCH_CLI_NUGET_FRAMEWORKS=1
128 if [ -n "$BUILD_TOOLS_TOOLSET_DIR" ] && [ -d "$BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION" ]; then
129 echo "Copying $BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION to $__TOOLRUNTIME_DIR" >> $__init_tools_log
130 cp -r $BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION/* $__TOOLRUNTIME_DIR
131 elif [ -n "$BUILD_TOOLS_TOOL_DIR" ] && [ -d "$BUILD_TOOLS_TOOL_DIR" ]; then
132 echo "Copying $BUILD_TOOLS_TOOL_DIR to $__TOOLRUNTIME_DIR" >> $__init_tools_log
133 cp -r $BUILD_TOOLS_TOOL_DIR/* $__TOOLRUNTIME_DIR
135 if [ ! -d "$__PROJECT_JSON_PATH" ]; then mkdir "$__PROJECT_JSON_PATH"; fi
136 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
138 if [ ! -e $__BUILD_TOOLS_PATH ]; then
139 echo "Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION..."
140 echo "Running: $__DOTNET_CMD restore \"$__PROJECT_JSON_FILE\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE" >> $__init_tools_log
141 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE >> $__init_tools_log
142 if [ ! -e "$__BUILD_TOOLS_PATH/init-tools.sh" ]; then echo "ERROR: Could not restore build tools correctly. See '$__init_tools_log' for more details."1>&2; fi
145 echo "Initializing BuildTools..."
146 echo "Running: $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR" >> $__init_tools_log
147 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR >> $__init_tools_log
148 if [ "$?" != "0" ]; then
149 echo "ERROR: An error occured when trying to initialize the tools. Please check '$__init_tools_log' for more details."1>&2
154 if [ $__PATCH_CLI_NUGET_FRAMEWORKS -eq 1 ]; then
155 echo "Updating CLI NuGet Frameworks map..."
156 cp $__TOOLRUNTIME_DIR/NuGet.Frameworks.dll $__TOOLRUNTIME_DIR/dotnetcli/sdk/$__DOTNET_TOOLS_VERSION >> $__init_tools_log
157 if [ "$?" != "0" ]; then
158 echo "ERROR: An error occured when updating Nuget for CLI . Please check '$__init_tools_log' for more details."1>&2
163 touch $__INIT_TOOLS_DONE_MARKER
165 echo "Done initializing tools."
167 echo "Tools are already initialized"