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/os-release | grep -cim1 ubuntu)" -eq 1 ]; then
22 if [ "$(cat /etc/os-release | grep -cim1 16.04)" -eq 1 ]; then
26 if [ "$(cat /etc/os-release | grep -cim1 16.10)" -eq 1 ]; then
33 elif [ "$(cat /etc/os-release | grep -cim1 centos)" -eq 1 ]; then
36 elif [ "$(cat /etc/os-release | grep -cim1 rhel)" -eq 1 ]; then
39 elif [ "$(cat /etc/os-release | grep -cim1 debian)" -eq 1 ]; then
42 elif [ "$(cat /etc/os-release | grep -cim1 alpine)" -eq 1 ]; then
45 elif [ "$(cat /etc/os-release | grep -cim1 fedora)" -eq 1 ]; then
46 if [ "$(cat /etc/os-release | grep -cim1 24)" -eq 1 ]; then
50 if [ "$(cat /etc/os-release | grep -cim1 25)" -eq 1 ]; then
54 elif [ "$(cat /etc/os-release | grep -cim1 opensuse)" -eq 1 ]; then
55 if [ "$(cat /etc/os-release | grep -cim1 42.1)" -eq 1 ]; then
61 # Cannot determine Linux distribution, assuming Ubuntu 14.04.
66 if [ -z "$__DOTNET_PKG" ]; then
71 __DOTNET_PKG=dotnet-dev-osx-x64
76 __DOTNET_PKG="dotnet-dev-$(get_current_linux_name)-x64"
81 echo "Unsupported OS '$OSName' detected. Downloading ubuntu-x64 tools."
83 __DOTNET_PKG=dotnet-dev-ubuntu-x64
88 if [ ! -e $__INIT_TOOLS_DONE_MARKER ]; then
89 __PATCH_CLI_NUGET_FRAMEWORKS=0
91 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
92 echo "Running: $__scriptpath/init-tools.sh" > $__init_tools_log
94 if [ ! -e $__DOTNET_PATH ]; then
96 mkdir -p "$__DOTNET_PATH"
98 if [ -n "$DOTNET_TOOLSET_DIR" ] && [ -d "$DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION" ]; then
99 echo "Copying $DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION to $__DOTNET_PATH" >> $__init_tools_log
100 cp -r $DOTNET_TOOLSET_DIR/$__DOTNET_TOOLS_VERSION/* $__DOTNET_PATH
101 elif [ -n "$DOTNET_TOOL_DIR" ] && [ -d "$DOTNET_TOOL_DIR" ]; then
102 echo "Copying $DOTNET_TOOL_DIR to $__DOTNET_PATH" >> $__init_tools_log
103 cp -r $DOTNET_TOOL_DIR/* $__DOTNET_PATH
105 echo "Installing dotnet cli..."
106 __DOTNET_LOCATION="https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz"
107 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
108 echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'" >> $__init_tools_log
109 if command -v curl > /dev/null; then
110 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
112 wget -q -O $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
115 tar -xf $__DOTNET_PATH/dotnet.tar
119 __PATCH_CLI_NUGET_FRAMEWORKS=1
124 if [ -n "$BUILD_TOOLS_TOOLSET_DIR" ] && [ -d "$BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION" ]; then
125 echo "Copying $BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION to $__TOOLRUNTIME_DIR" >> $__init_tools_log
126 cp -r $BUILD_TOOLS_TOOLSET_DIR/$__BUILD_TOOLS_PACKAGE_VERSION/* $__TOOLRUNTIME_DIR
127 elif [ -n "$BUILD_TOOLS_TOOL_DIR" ] && [ -d "$BUILD_TOOLS_TOOL_DIR" ]; then
128 echo "Copying $BUILD_TOOLS_TOOL_DIR to $__TOOLRUNTIME_DIR" >> $__init_tools_log
129 cp -r $BUILD_TOOLS_TOOL_DIR/* $__TOOLRUNTIME_DIR
131 if [ ! -d "$__PROJECT_JSON_PATH" ]; then mkdir "$__PROJECT_JSON_PATH"; fi
132 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
134 if [ ! -e $__BUILD_TOOLS_PATH ]; then
135 echo "Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION..."
136 echo "Running: $__DOTNET_CMD restore \"$__PROJECT_JSON_FILE\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE" >> $__init_tools_log
137 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE >> $__init_tools_log
138 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
141 echo "Initializing BuildTools..."
142 echo "Running: $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR" >> $__init_tools_log
143 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR >> $__init_tools_log
144 if [ "$?" != "0" ]; then
145 echo "ERROR: An error occured when trying to initialize the tools. Please check '$__init_tools_log' for more details."1>&2
150 if [ $__PATCH_CLI_NUGET_FRAMEWORKS -eq 1 ]; then
151 echo "Updating CLI NuGet Frameworks map..."
152 cp $__TOOLRUNTIME_DIR/NuGet.Frameworks.dll $__TOOLRUNTIME_DIR/dotnetcli/sdk/$__DOTNET_TOOLS_VERSION >> $__init_tools_log
153 if [ "$?" != "0" ]; then
154 echo "ERROR: An error occured when updating Nuget for CLI . Please check '$__init_tools_log' for more details."1>&2
159 touch $__INIT_TOOLS_DONE_MARKER
161 echo "Done initializing tools."
163 echo "Tools are already initialized"