1
1
#! /usr/bin/env bash
2
2
3
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
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
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
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 /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
19
19
echo " Tools are already initialized"
20
20
return # return instead of exit because this script is inlined in other scripts which we don't want to exit
21
21
fi
22
22
23
- if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR ; fi
23
+ if [ -e " $__TOOLRUNTIME_DIR " ]; then rm -rf -- " $__TOOLRUNTIME_DIR " ; fi
24
24
25
- if [ -d " $DotNetBuildToolsDir " ]; then
25
+ if [ -d " ${ DotNetBuildToolsDir:- } " ]; then
26
26
echo " Using tools from '$DotNetBuildToolsDir '."
27
27
ln -s " $DotNetBuildToolsDir " " $__TOOLRUNTIME_DIR "
28
28
@@ -32,11 +32,11 @@ if [ -d "$DotNetBuildToolsDir" ]; then
32
32
fi
33
33
34
34
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 "
36
36
return # return instead of exit because this script is inlined in other scripts which we don't want to exit
37
37
fi
38
38
39
- echo " Running: $__scriptpath /init-tools.sh" > $__init_tools_log
39
+ echo " Running: $__scriptpath /init-tools.sh" > " $__init_tools_log "
40
40
41
41
display_error_message ()
42
42
{
@@ -48,15 +48,15 @@ display_error_message()
48
48
execute_with_retry () {
49
49
local count=0
50
50
local retries=${retries:- 5}
51
- local waitFactor=${waitFactor:- 6}
51
+ local waitFactor=${waitFactor:- 6}
52
52
until " $@ " ; do
53
53
local exit=$?
54
54
count=$(( $count + 1 ))
55
55
if [ $count -lt $retries ]; then
56
56
local wait=$(( waitFactor ** (( count - 1 )) ))
57
57
echo " Retry $count /$retries exited $exit , retrying in $wait seconds..."
58
58
sleep $wait
59
- else
59
+ else
60
60
say_err " Retry $count /$retries exited $exit , no more retries left."
61
61
return $exit
62
62
fi
@@ -65,8 +65,8 @@ execute_with_retry() {
65
65
return 0
66
66
}
67
67
68
- if [ ! -e $__DOTNET_PATH ]; then
69
- if [ -z " $__DOTNET_PKG " ]; then
68
+ if [ ! -e " $__DOTNET_PATH " ]; then
69
+ if [ -z " ${ __DOTNET_PKG:- } " ]; then
70
70
if [ " $( uname -m | grep " i[3456]86" ) " = " i686" ]; then
71
71
echo " Warning: build not supported on 32 bit Unix"
72
72
fi
@@ -96,12 +96,12 @@ if [ ! -e $__DOTNET_PATH ]; then
96
96
if [[ $ID == " alpine" ]]; then
97
97
# remove the last version digit
98
98
VERSION_ID=${VERSION_ID% .* }
99
- __PKG_RID=alpine.$VERSION_ID
99
+ __PKG_RID=alpine.$VERSION_ID
100
100
fi
101
101
elif [ -e /etc/redhat-release ]; then
102
102
redhatRelease=$( < /etc/redhat-release)
103
103
if [[ $redhatRelease == " CentOS release 6." * || $redhatRelease == " Red Hat Enterprise Linux Server release 6." * ]]; then
104
- __PKG_RID=rhel.6
104
+ __PKG_RID=rhel.6
105
105
fi
106
106
fi
107
107
@@ -112,16 +112,17 @@ if [ ! -e $__DOTNET_PATH ]; then
112
112
OS=Linux
113
113
__PKG_RID=linux
114
114
;;
115
- esac
116
- __DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION} -$__PKG_RID -$__PKG_ARCH
115
+ esac
116
+
117
+ __DOTNET_PKG=dotnet-sdk-${__DOTNET_TOOLS_VERSION} -$__PKG_RID -$__PKG_ARCH
117
118
fi
118
119
mkdir -p " $__DOTNET_PATH "
119
120
120
121
echo " Installing dotnet cli..."
121
122
__DOTNET_LOCATION=" https://dotnetcli.azureedge.net/dotnet/Sdk/${__DOTNET_TOOLS_VERSION} /${__DOTNET_PKG} .tar.gz"
122
123
123
124
install_dotnet_cli () {
124
- if [[ " $ DotNetBootstrapCliTarPath" = " " ]]; then
125
+ if [[ -z " ${ DotNetBootstrapCliTarPath-} " ]]; then
125
126
echo " Installing '${__DOTNET_LOCATION} ' to '$__DOTNET_PATH /dotnet.tar'"
126
127
rm -rf -- " $__DOTNET_PATH /*"
127
128
# curl has HTTPS CA trust-issues less often than wget, so lets try that first.
@@ -134,25 +135,25 @@ if [ ! -e $__DOTNET_PATH ]; then
134
135
echo " Copying '$DotNetBootstrapCliTarPath ' to '$__DOTNET_PATH /dotnet.tar'"
135
136
cp $DotNetBootstrapCliTarPath $__DOTNET_PATH /dotnet.tar
136
137
fi
137
- cd $__DOTNET_PATH
138
- tar -xf $__DOTNET_PATH /dotnet.tar
138
+ cd " $__DOTNET_PATH "
139
+ tar -xf " $__DOTNET_PATH /dotnet.tar"
139
140
}
140
141
execute_with_retry install_dotnet_cli >> " $__init_tools_log " 2>&1
141
142
142
- cd $__scriptpath
143
+ cd " $__scriptpath "
143
144
fi
144
145
145
- if [ ! -e $__BUILD_TOOLS_PATH ]; then
146
+ if [ ! -e " $__BUILD_TOOLS_PATH " ]; then
146
147
echo " Restoring BuildTools version $__BUILD_TOOLS_PACKAGE_VERSION ..."
147
- 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
148
- $__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
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 "
149
150
if [ ! -e " $__BUILD_TOOLS_PATH /init-tools.sh" ]; then
150
151
echo " ERROR: Could not restore build tools correctly." 1>&2
151
152
display_error_message
152
153
fi
153
154
fi
154
155
155
- if [ -z " $__ILASM_RID " ]; then
156
+ if [ -z " ${ __ILASM_RID-} " ]; then
156
157
__ILASM_RID=$__PKG_RID -$__PKG_ARCH
157
158
fi
158
159
@@ -161,17 +162,17 @@ echo "Using RID $__ILASM_RID for BuildTools native tools"
161
162
export ILASMCOMPILER_VERSION=$__ILASM_VERSION
162
163
export NATIVE_TOOLS_RID=$__ILASM_RID
163
164
164
- if [ ! " $DotNetBootstrapCliTarPath " = " " ]; then
165
+ if [ -n " ${ DotNetBootstrapCliTarPath-} " ]; then
165
166
# Assume ilasm is not in nuget yet when bootstrapping...
166
167
unset ILASMCOMPILER_VERSION
167
168
fi
168
169
169
170
echo " Initializing BuildTools..."
170
- 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 "
171
172
172
173
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
173
- chmod +x $__BUILD_TOOLS_PATH /init-tools.sh
174
- $__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 "
175
176
if [ " $? " != " 0" ]; then
176
177
echo " ERROR: An error occurred when trying to initialize the tools." 1>&2
177
178
display_error_message
180
181
181
182
echo " Making all .sh files executable under Tools."
182
183
# Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
183
- ls $__scriptpath /Tools/* .sh | xargs chmod +x
184
- 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
185
186
186
- Tools/crossgen.sh $__scriptpath /Tools
187
+ " $__scriptpath / Tools/crossgen.sh" " $__scriptpath /Tools"
187
188
188
- mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch $__BUILD_TOOLS_SEMAPHORE
189
+ mkdir -p " $( dirname " $__BUILD_TOOLS_SEMAPHORE " ) " && touch " $__BUILD_TOOLS_SEMAPHORE "
189
190
190
191
echo " Done initializing tools."
191
192
0 commit comments