5 if [ "$1" == "Linux" ]; then
7 if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
8 export __DistroName=ubuntu
9 elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
10 export __DistroName=centos
11 elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
12 export __DistroName=rhel
13 elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
14 export __DistroName=debian
16 export __DistroName=""
21 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
23 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
24 # This is needed by CLI to function.
25 if [ -z "$HOME" ]; then
26 if [ ! -d "$__scriptpath/temp_home" ]; then
29 export HOME=$__scriptpath/temp_home
30 echo "HOME not defined; setting it to $HOME"
33 __PACKAGES_DIR=$__scriptpath/packages
34 __TOOLRUNTIME_DIR=$__scriptpath/Tools
35 __DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
36 __DOTNET_CMD=$__DOTNET_PATH/bin/dotnet
37 if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://www.myget.org/F/dotnet-buildtools/; fi
38 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
39 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
40 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
41 __PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
42 __PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
43 __PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"dnxcore50\": { } } }"
50 __DOTNET_PKG=dotnet-osx-x64
55 __DOTNET_PKG=dotnet-ubuntu-x64
59 echo "Unsupported OS $OSName detected. Downloading ubuntu-x64 tools"
61 __DOTNET_PKG=dotnet-ubuntu-x64
65 # Initialize Linux Distribution name and .NET CLI package name.
68 if [ "$__DistroName" == "centos" ]; then
69 __DOTNET_PKG=dotnet-centos-x64
72 __CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/dev/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
73 echo ".NET CLI will be downloaded from $__CLIDownloadURL"
75 if [ ! -e $__PROJECT_JSON_FILE ]; then
76 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
78 if [ ! -e $__DOTNET_PATH ]; then
79 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
80 which curl > /dev/null 2> /dev/null
82 mkdir -p "$__DOTNET_PATH"
83 wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
85 curl -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
88 tar -xf $__DOTNET_PATH/dotnet.tar
89 if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then
90 find $__DOTNET_PATH -name *.ni.* | xargs rm 2>/dev/null
91 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin
92 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin/dnx
93 cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/runtime/coreclr
99 mkdir "$__PROJECT_JSON_PATH"
100 echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
102 if [ ! -e $__BUILD_TOOLS_PATH ]; then
103 $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE
106 sh $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR
107 chmod a+x $__TOOLRUNTIME_DIR/corerun