11#! /usr/bin/env bash
22
33__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
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
1010export __BUILDTOOLS_USE_CSPROJ=true
11- __BUILD_TOOLS_PACKAGE_VERSION=$( cat $__scriptpath /BuildToolsVersion.txt | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
12- __DOTNET_TOOLS_VERSION=$( cat $__scriptpath /DotnetCLIVersion.txt | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
13- __ILASM_VERSION=$( cat $__scriptpath /tools-local/ILAsmVersion.txt | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
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
17-
18- if [ -e $__BUILD_TOOLS_SEMAPHORE ]; then
11+ __BUILD_TOOLS_PACKAGE_VERSION=$( cat " $__scriptpath /BuildToolsVersion.txt" | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
12+ __DOTNET_TOOLS_VERSION=$( cat " $__scriptpath /DotnetCLIVersion.txt" | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
13+ __ILASM_VERSION=$( cat " $__scriptpath /tools-local/ILAsmVersion.txt" | sed ' s/\r$//' ) # remove CR if mounted repo on Windows drive
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"
17+
18+ if [ -e " $__BUILD_TOOLS_SEMAPHORE " ]; then
1919 echo " Tools are already initialized"
2020 return # return instead of exit because this script is inlined in other scripts which we don't want to exit
2121fi
2222
23- if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR ; fi
23+ if [ -e " $__TOOLRUNTIME_DIR " ]; then rm -rf -- " $__TOOLRUNTIME_DIR " ; fi
2424
25- if [ -d " $DotNetBuildToolsDir " ]; then
25+ if [ -d " ${ DotNetBuildToolsDir:- } " ]; then
2626 echo " Using tools from '$DotNetBuildToolsDir '."
2727 ln -s " $DotNetBuildToolsDir " " $__TOOLRUNTIME_DIR "
2828
@@ -32,11 +32,11 @@ if [ -d "$DotNetBuildToolsDir" ]; then
3232 fi
3333
3434 echo " Done initializing tools."
35- mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch $__BUILD_TOOLS_SEMAPHORE
35+ mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch " $__BUILD_TOOLS_SEMAPHORE "
3636 return # return instead of exit because this script is inlined in other scripts which we don't want to exit
3737fi
3838
39- echo " Running: $__scriptpath /init-tools.sh" > $__init_tools_log
39+ echo " Running: $__scriptpath /init-tools.sh" > " $__init_tools_log "
4040
4141display_error_message ()
4242{
@@ -65,13 +65,13 @@ execute_with_retry() {
6565 return 0
6666}
6767
68- if [ ! -e $__DOTNET_PATH ]; then
69- if [ -z " $__DOTNET_PKG " ]; then
68+ if [ ! -e " $__DOTNET_PATH " ]; then
69+ if [ -z " ${ __DOTNET_PKG:- } " ]; then
7070 if [ " $( uname -m | grep " i[3456]86" ) " = " i686" ]; then
7171 echo " Warning: build not supported on 32 bit Unix"
7272 fi
7373
74- __PKG_ARCH=x64
74+ __PKG_ARCH=x64
7575
7676 OSName=$( uname -s)
7777 case $OSName in
@@ -88,7 +88,7 @@ if [ ! -e $__DOTNET_PATH ]; then
8888 ;;
8989
9090 Linux)
91- __PKG_RID=linux
91+ __PKG_RID=linux
9292 OS=Linux
9393
9494 if [ -e /etc/os-release ]; then
@@ -108,21 +108,21 @@ if [ ! -e $__DOTNET_PATH ]; then
108108 ;;
109109
110110 * )
111- echo " Unsupported OS '$OSName ' detected. Downloading linux-$__PKG_ARCH tools."
111+ echo " Unsupported OS '$OSName ' detected. Downloading linux-$__PKG_ARCH tools."
112112 OS=Linux
113113 __PKG_RID=linux
114114 ;;
115- esac
115+ esac
116116
117- __DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION} -$__PKG_RID -$__PKG_ARCH
117+ __DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION} -$__PKG_RID -$__PKG_ARCH
118118 fi
119119 mkdir -p " $__DOTNET_PATH "
120120
121121 echo " Installing dotnet cli..."
122122 __DOTNET_LOCATION=" https://dotnetcli.azureedge.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION} /${__DOTNET_PKG} .tar.gz"
123123
124124 install_dotnet_cli () {
125- if [[ " $ DotNetBootstrapCliTarPath" = " " ]]; then
125+ if [[ -z " ${ DotNetBootstrapCliTarPath-} " ]]; then
126126 echo " Installing '${__DOTNET_LOCATION} ' to '$__DOTNET_PATH /dotnet.tar'"
127127 rm -rf -- " $__DOTNET_PATH /*"
128128 # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
@@ -135,25 +135,25 @@ if [ ! -e $__DOTNET_PATH ]; then
135135 echo " Copying '$DotNetBootstrapCliTarPath ' to '$__DOTNET_PATH /dotnet.tar'"
136136 cp $DotNetBootstrapCliTarPath $__DOTNET_PATH /dotnet.tar
137137 fi
138- cd $__DOTNET_PATH
139- tar -xf $__DOTNET_PATH /dotnet.tar
138+ cd " $__DOTNET_PATH "
139+ tar -xf " $__DOTNET_PATH /dotnet.tar"
140140 }
141141 execute_with_retry install_dotnet_cli >> " $__init_tools_log " 2>&1
142142
143- cd $__scriptpath
143+ cd " $__scriptpath "
144144fi
145145
146- if [ ! -e $__BUILD_TOOLS_PATH ]; then
146+ if [ ! -e " $__BUILD_TOOLS_PATH " ]; then
147147 echo " Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION ..."
148- echo " Running: $__DOTNET_CMD restore \" $__INIT_TOOLS_RESTORE_PROJECT \" --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION " >> $__init_tools_log
149- $__DOTNET_CMD restore " $__INIT_TOOLS_RESTORE_PROJECT " --no-cache --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE /p:BuildToolsPackageVersion=$__BUILD_TOOLS_PACKAGE_VERSION >> $__init_tools_log
148+ 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 "
149+ " $__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 "
150150 if [ ! -e " $__BUILD_TOOLS_PATH /init-tools.sh" ]; then
151151 echo " ERROR: Could not restore build tools correctly." 1>&2
152152 display_error_message
153153 fi
154154fi
155155
156- if [ -z " $__ILASM_RID " ]; then
156+ if [ -z " ${ __ILASM_RID-} " ]; then
157157 __ILASM_RID=$__PKG_RID -$__PKG_ARCH
158158fi
159159
@@ -162,17 +162,17 @@ echo "Using RID $__ILASM_RID for BuildTools native tools"
162162export ILASMCOMPILER_VERSION=$__ILASM_VERSION
163163export NATIVE_TOOLS_RID=$__ILASM_RID
164164
165- if [ ! " $DotNetBootstrapCliTarPath " = " " ]; then
165+ if [ -n " ${ DotNetBootstrapCliTarPath-} " ]; then
166166 # Assume ilasm is not in nuget yet when bootstrapping...
167167 unset ILASMCOMPILER_VERSION
168168fi
169169
170170echo " Initializing BuildTools..."
171- echo " Running: $__BUILD_TOOLS_PATH /init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR " >> $__init_tools_log
171+ echo " Running: $__BUILD_TOOLS_PATH /init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR " >> " $__init_tools_log "
172172
173173# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
174- chmod +x $__BUILD_TOOLS_PATH /init-tools.sh
175- $__BUILD_TOOLS_PATH /init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR $__PACKAGES_DIR >> $__init_tools_log
174+ chmod +x " $__BUILD_TOOLS_PATH /init-tools.sh"
175+ " $__BUILD_TOOLS_PATH /init-tools.sh" " $__scriptpath " " $__DOTNET_CMD " " $__TOOLRUNTIME_DIR " " $__PACKAGES_DIR " >> " $__init_tools_log "
176176if [ " $? " != " 0" ]; then
177177 echo " ERROR: An error occurred when trying to initialize the tools." 1>&2
178178 display_error_message
181181
182182echo " Making all .sh files executable under Tools."
183183# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
184- ls $__scriptpath /Tools/* .sh | xargs chmod +x
185- ls $__scriptpath /Tools/scripts/docker/* .sh | xargs chmod +x
184+ ls " $__scriptpath /Tools/" * .sh | xargs chmod +x
185+ ls " $__scriptpath /Tools/scripts/docker/" * .sh | xargs chmod +x
186186
187- Tools/crossgen.sh $__scriptpath /Tools
187+ " $__scriptpath / Tools/crossgen.sh" " $__scriptpath /Tools"
188188
189- mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch $__BUILD_TOOLS_SEMAPHORE
189+ mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch " $__BUILD_TOOLS_SEMAPHORE "
190190
191191echo " Done initializing tools."
192192
0 commit comments