5 if [ "$1" == "Linux" ]; then
6 if [ ! -e /etc/os-release ]; then
7 echo "WARNING: Can not determine runtime id for current distro."
10 source /etc/os-release
11 export __DistroRid="$ID.$VERSION_ID-x64"
16 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
18 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
19 # This is needed by CLI to function.
20 if [ -z "$HOME" ]; then
21 if [ ! -d "$__scriptpath/temp_home" ]; then
24 export HOME=$__scriptpath/temp_home
25 echo "HOME not defined; setting it to $HOME"
28 __PACKAGES_DIR=$__scriptpath/packages
29 __TOOLRUNTIME_DIR=$__scriptpath/Tools
30 __DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
31 __DOTNET_CMD=$__DOTNET_PATH/dotnet
32 if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://www.myget.org/F/dotnet-buildtools/; fi
33 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
34 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
35 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
36 __PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
37 __PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
38 __PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"dnxcore50\": { } } }"
45 __DOTNET_PKG=dotnet-dev-osx-x64
51 if [ ! -e /etc/os-release ]; then
52 echo "Cannot determine Linux distribution, asuming Ubuntu 14.04."
53 __DOTNET_PKG=dotnet-dev-ubuntu.14.04-x64
55 source /etc/os-release
56 __DOTNET_PKG="dotnet-dev-$ID.$VERSION_ID-x64"
61 echo "Unsupported OS $OSName detected. Downloading ubuntu-x64 tools"
63 __DOTNET_PKG=dotnet-dev-ubuntu.14.04-x64
67 # Initialize Linux Distribution name and .NET CLI package name.
71 # Work around mac build issue
72 if [ "$OS"=="OSX" ]; then
73 echo Raising file open limit - otherwise Mac build may fail
78 __CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
79 echo ".NET CLI will be downloaded from $__CLIDownloadURL"
80 echo "Locating $__PROJECT_JSON_FILE to see if we already downloaded .NET CLI tools..."
82 if [ ! -e $__PROJECT_JSON_FILE ]; then
83 echo "$__PROJECT_JSON_FILE not found. Proceeding to download .NET CLI tools. "
84 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
86 if [ ! -e $__DOTNET_PATH ]; then
87 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
88 which curl > /dev/null 2> /dev/null
90 mkdir -p "$__DOTNET_PATH"
91 wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
92 echo "wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
94 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
95 echo "curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL"
98 tar -xf $__DOTNET_PATH/dotnet.tar
99 if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then
100 find $__DOTNET_PATH -name *.ni.* | xargs rm 2>/dev/null
101 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin
102 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin/dnx
103 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/runtime/coreclr
109 mkdir "$__PROJECT_JSON_PATH"
110 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
112 if [ ! -e $__BUILD_TOOLS_PATH ]; then
113 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE
116 # On ubuntu 14.04, /bin/sh (symbolic link) calls /bin/dash by default.
117 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR
119 chmod a+x $__TOOLRUNTIME_DIR/corerun
121 echo "$__PROJECT_JSON_FILE found. Skipping .NET CLI installation."