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 export __BUILDTOOLS_USE_CSPROJ=true
11 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
12 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
13 __ILASM_VERSION=$(cat $__scriptpath/ILAsmVersion.txt)
14 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/microsoft.dotnet.buildtools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
15 __INIT_TOOLS_RESTORE_PROJECT=$__scriptpath/init-tools.msbuild
16 __BUILD_TOOLS_SEMAPHORE=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION/init-tools.complete
18 if [ -e $__BUILD_TOOLS_SEMAPHORE ]; then
19 echo "Tools are already initialized"
20 return #return instead of exit because this script is inlined in other scripts which we don't want to exit
23 if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
25 if [ -d "$DotNetBuildToolsDir" ]; then
26 echo "Using tools from '$DotNetBuildToolsDir'."
27 ln -s "$DotNetBuildToolsDir" "$__TOOLRUNTIME_DIR"
29 if [ ! -e "$__DOTNET_CMD" ]; then
30 echo "ERROR: Ensure that $DotNetBuildToolsDir contains the .NET Core SDK at $__DOTNET_PATH"
34 echo "Done initializing tools."
35 mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch $__BUILD_TOOLS_SEMAPHORE
36 return #return instead of exit because this script is inlined in other scripts which we don't want to exit
39 echo "Running: $__scriptpath/init-tools.sh" > $__init_tools_log
41 display_error_message()
43 echo "Please check the detailed log that follows." 1>&2
44 cat "$__init_tools_log" 1>&2
47 # Executes a command and retries if it fails.
48 execute_with_retry() {
50 local retries=${retries:-5}
51 local waitFactor=${waitFactor:-6}
54 count=$(( $count + 1 ))
55 if [ $count -lt $retries ]; then
56 local wait=$(( waitFactor ** (( count - 1 )) ))
57 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
60 say_err "Retry $count/$retries exited $exit, no more retries left."
68 if [ ! -e $__DOTNET_PATH ]; then
69 if [ -z "$__DOTNET_PKG" ]; then
70 if [ "$(uname -m | grep "i[3456]86")" = "i686" ]; then
71 echo "Warning: build not supported on 32 bit Unix"
82 # Format x.y.z as single integer with three digits for each part
83 VERSION=`sw_vers -productVersion| sed -e 's/\./ /g' | xargs printf "%03d%03d%03d"`
84 if [ "$VERSION" -lt 010012000 ]; then
85 echo error: macOS version `sw_vers -productVersion` is too old. 10.12 is needed as minimum.
94 if [ -e /etc/os-release ]; then
95 source /etc/os-release
96 if [[ $ID == "alpine" ]]; then
97 # remove the last version digit
98 VERSION_ID=${VERSION_ID%.*}
99 __PKG_RID=alpine.$VERSION_ID
101 elif [ -e /etc/redhat-release ]; then
102 redhatRelease=$(</etc/redhat-release)
103 if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
111 echo "Unsupported OS '$OSName' detected. Downloading linux-$__PKG_ARCH tools."
116 __DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION}-$__PKG_RID-$__PKG_ARCH
118 mkdir -p "$__DOTNET_PATH"
120 echo "Installing dotnet cli..."
121 __DOTNET_LOCATION="https://dotnetcli.azureedge.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.tar.gz"
123 install_dotnet_cli() {
124 echo "Installing '${__DOTNET_LOCATION}' to '$__DOTNET_PATH/dotnet.tar'" >> "$__init_tools_log"
125 rm -rf -- "$__DOTNET_PATH/*"
126 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
127 if command -v curl > /dev/null; then
128 curl --retry 10 -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
130 wget -q -O $__DOTNET_PATH/dotnet.tar ${__DOTNET_LOCATION}
133 tar -xf $__DOTNET_PATH/dotnet.tar
135 execute_with_retry install_dotnet_cli >> "$__init_tools_log" 2>&1
140 if [ ! -e $__BUILD_TOOLS_PATH ]; then
141 echo "Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION..."
142 echo "Running: $__DOTNET_CMD restore \"$__INIT_TOOLS_RESTORE_PROJECT\" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir=$__TOOLRUNTIME_DIR" >> $__init_tools_log
143 $__DOTNET_CMD restore "$__INIT_TOOLS_RESTORE_PROJECT" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION /p:ToolsDir=$__TOOLRUNTIME_DIR >> $__init_tools_log
144 if [ ! -e "$__BUILD_TOOLS_PATH/init-tools.sh" ]; then
145 echo "ERROR: Could not restore build tools correctly." 1>&2
146 display_error_message
150 if [ -z "$__ILASM_RID" ]; then
151 __ILASM_RID=$__PKG_RID-$__PKG_ARCH
154 echo "Using RID $__ILASM_RID for BuildTools native tools"
156 export ILASMCOMPILER_VERSION=$__ILASM_VERSION
157 export NATIVE_TOOLS_RID=$__ILASM_RID
159 echo "Initializing BuildTools..."
160 echo "Running: $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR" >> $__init_tools_log
162 # Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
163 chmod +x $__BUILD_TOOLS_PATH/init-tools.sh
164 $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR >> $__init_tools_log
165 if [ "$?" != "0" ]; then
166 echo "ERROR: An error occurred when trying to initialize the tools." 1>&2
167 display_error_message
171 echo "Making all .sh files executable under Tools."
172 # Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
173 ls $__scriptpath/Tools/*.sh | xargs chmod +x
174 ls $__scriptpath/Tools/scripts/docker/*.sh | xargs chmod +x
176 Tools/crossgen.sh $__scriptpath/Tools
178 mkdir -p "$(dirname "$__BUILD_TOOLS_SEMAPHORE")" && touch $__BUILD_TOOLS_SEMAPHORE
180 echo "Done initializing tools."