Skip to content

Commit e6285f3

Browse files
Update bootstrappers
1 parent bd5793e commit e6285f3

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

run.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Updates KoreBuild to the latest version even if a lock file is present.
2929
.PARAMETER ConfigFile
3030
The path to the configuration file that stores values. Defaults to korebuild.json.
3131
32+
.PARAMETER ToolsSourceSuffix
33+
The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores.
34+
3235
.PARAMETER Arguments
3336
Arguments to be passed to the command
3437
@@ -51,7 +54,7 @@ Example config file:
5154
#>
5255
[CmdletBinding(PositionalBinding = $false)]
5356
param(
54-
[Parameter(Mandatory=$true, Position = 0)]
57+
[Parameter(Mandatory = $true, Position = 0)]
5558
[string]$Command,
5659
[string]$Path = $PSScriptRoot,
5760
[Alias('c')]
@@ -63,6 +66,7 @@ param(
6366
[Alias('u')]
6467
[switch]$Update,
6568
[string]$ConfigFile,
69+
[string]$ToolsSourceSuffix,
6670
[Parameter(ValueFromRemainingArguments = $true)]
6771
[string[]]$Arguments
6872
)
@@ -79,7 +83,7 @@ function Get-KoreBuild {
7983
$lockFile = Join-Path $Path 'korebuild-lock.txt'
8084

8185
if (!(Test-Path $lockFile) -or $Update) {
82-
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile
86+
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix
8387
}
8488

8589
$version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
@@ -96,7 +100,7 @@ function Get-KoreBuild {
96100

97101
try {
98102
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
99-
Get-RemoteFile $remotePath $tmpfile
103+
Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix
100104
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
101105
# Use built-in commands where possible as they are cross-plat compatible
102106
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
@@ -124,7 +128,7 @@ function Join-Paths([string]$path, [string[]]$childPaths) {
124128
return $path
125129
}
126130

127-
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
131+
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) {
128132
if ($RemotePath -notlike 'http*') {
129133
Copy-Item $RemotePath $LocalPath
130134
return
@@ -134,7 +138,7 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
134138
while ($retries -gt 0) {
135139
$retries -= 1
136140
try {
137-
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
141+
Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath
138142
return
139143
}
140144
catch {
@@ -161,7 +165,8 @@ if (Test-Path $ConfigFile) {
161165
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
162166
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
163167
}
164-
} catch {
168+
}
169+
catch {
165170
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
166171
Write-Warning $Error[0]
167172
}

run.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ update=false
1717
repo_path="$DIR"
1818
channel=''
1919
tools_source=''
20+
tools_source_suffix=''
2021

2122
#
2223
# Functions
@@ -29,13 +30,14 @@ __usage() {
2930
echo " <Arguments>... Arguments passed to the command. Variable number of arguments allowed."
3031
echo ""
3132
echo "Options:"
32-
echo " --verbose Show verbose output."
33-
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
34-
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
35-
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
36-
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
37-
echo " -s|--tools-source|-ToolsSource <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
38-
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
33+
echo " --verbose Show verbose output."
34+
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
35+
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
36+
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
37+
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
38+
echo " -s|--tools-source|-ToolsSource <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
39+
echo " --tools-source-suffix|-ToolsSourceSuffix <SUFFIX> The suffix to append to tools-source. Useful for query strings."
40+
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
3941
echo ""
4042
echo "Description:"
4143
echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be."
@@ -50,7 +52,7 @@ get_korebuild() {
5052
local version
5153
local lock_file="$repo_path/korebuild-lock.txt"
5254
if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
53-
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file"
55+
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" "$tools_source_suffix"
5456
fi
5557
version="$(grep 'version:*' -m 1 "$lock_file")"
5658
if [[ "$version" == '' ]]; then
@@ -66,7 +68,7 @@ get_korebuild() {
6668
local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
6769
tmpfile="$(mktemp)"
6870
echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
69-
if __get_remote_file "$remote_path" "$tmpfile"; then
71+
if __get_remote_file "$remote_path" "$tmpfile" "$tools_source_suffix"; then
7072
unzip -q -d "$korebuild_path" "$tmpfile"
7173
fi
7274
rm "$tmpfile" || true
@@ -98,6 +100,7 @@ __machine_has() {
98100
__get_remote_file() {
99101
local remote_path=$1
100102
local local_path=$2
103+
local remote_path_suffix=$3
101104

102105
if [[ "$remote_path" != 'http'* ]]; then
103106
cp "$remote_path" "$local_path"
@@ -106,14 +109,14 @@ __get_remote_file() {
106109

107110
local failed=false
108111
if __machine_has wget; then
109-
wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true
112+
wget --tries 10 --quiet -O "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
110113
else
111114
failed=true
112115
fi
113116

114117
if [ "$failed" = true ] && __machine_has curl; then
115118
failed=false
116-
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true
119+
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
117120
fi
118121

119122
if [ "$failed" = true ]; then
@@ -164,6 +167,11 @@ while [[ $# -gt 0 ]]; do
164167
tools_source="${1:-}"
165168
[ -z "$tools_source" ] && __usage
166169
;;
170+
--tools-source-suffix|-ToolsSourceSuffix)
171+
shift
172+
tools_source_suffix="${1:-}"
173+
[ -z "$tools_source_suffix" ] && __usage
174+
;;
167175
-u|--update|-Update)
168176
update=true
169177
;;

0 commit comments

Comments
 (0)