Update bootstrappers
This commit is contained in:
Родитель
ffca98b5e1
Коммит
c81de4e885
17
run.ps1
17
run.ps1
|
@ -29,6 +29,9 @@ Updates KoreBuild to the latest version even if a lock file is present.
|
||||||
.PARAMETER ConfigFile
|
.PARAMETER ConfigFile
|
||||||
The path to the configuration file that stores values. Defaults to korebuild.json.
|
The path to the configuration file that stores values. Defaults to korebuild.json.
|
||||||
|
|
||||||
|
.PARAMETER ToolsSourceSuffix
|
||||||
|
The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores.
|
||||||
|
|
||||||
.PARAMETER Arguments
|
.PARAMETER Arguments
|
||||||
Arguments to be passed to the command
|
Arguments to be passed to the command
|
||||||
|
|
||||||
|
@ -51,7 +54,7 @@ Example config file:
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(PositionalBinding = $false)]
|
[CmdletBinding(PositionalBinding = $false)]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true, Position = 0)]
|
[Parameter(Mandatory = $true, Position = 0)]
|
||||||
[string]$Command,
|
[string]$Command,
|
||||||
[string]$Path = $PSScriptRoot,
|
[string]$Path = $PSScriptRoot,
|
||||||
[Alias('c')]
|
[Alias('c')]
|
||||||
|
@ -63,6 +66,7 @@ param(
|
||||||
[Alias('u')]
|
[Alias('u')]
|
||||||
[switch]$Update,
|
[switch]$Update,
|
||||||
[string]$ConfigFile,
|
[string]$ConfigFile,
|
||||||
|
[string]$ToolsSourceSuffix,
|
||||||
[Parameter(ValueFromRemainingArguments = $true)]
|
[Parameter(ValueFromRemainingArguments = $true)]
|
||||||
[string[]]$Arguments
|
[string[]]$Arguments
|
||||||
)
|
)
|
||||||
|
@ -79,7 +83,7 @@ function Get-KoreBuild {
|
||||||
$lockFile = Join-Path $Path 'korebuild-lock.txt'
|
$lockFile = Join-Path $Path 'korebuild-lock.txt'
|
||||||
|
|
||||||
if (!(Test-Path $lockFile) -or $Update) {
|
if (!(Test-Path $lockFile) -or $Update) {
|
||||||
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile
|
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
|
$version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
|
||||||
|
@ -96,7 +100,7 @@ function Get-KoreBuild {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
|
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
|
||||||
Get-RemoteFile $remotePath $tmpfile
|
Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix
|
||||||
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
|
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
|
||||||
# Use built-in commands where possible as they are cross-plat compatible
|
# Use built-in commands where possible as they are cross-plat compatible
|
||||||
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
|
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
|
||||||
|
@ -124,7 +128,7 @@ function Join-Paths([string]$path, [string[]]$childPaths) {
|
||||||
return $path
|
return $path
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
|
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) {
|
||||||
if ($RemotePath -notlike 'http*') {
|
if ($RemotePath -notlike 'http*') {
|
||||||
Copy-Item $RemotePath $LocalPath
|
Copy-Item $RemotePath $LocalPath
|
||||||
return
|
return
|
||||||
|
@ -134,7 +138,7 @@ function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
|
||||||
while ($retries -gt 0) {
|
while ($retries -gt 0) {
|
||||||
$retries -= 1
|
$retries -= 1
|
||||||
try {
|
try {
|
||||||
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
|
Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
@ -161,7 +165,8 @@ if (Test-Path $ConfigFile) {
|
||||||
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
|
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
|
||||||
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
|
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
|
||||||
}
|
}
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
|
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
|
||||||
Write-Warning $Error[0]
|
Write-Warning $Error[0]
|
||||||
}
|
}
|
||||||
|
|
30
run.sh
30
run.sh
|
@ -17,6 +17,7 @@ update=false
|
||||||
repo_path="$DIR"
|
repo_path="$DIR"
|
||||||
channel=''
|
channel=''
|
||||||
tools_source=''
|
tools_source=''
|
||||||
|
tools_source_suffix=''
|
||||||
|
|
||||||
#
|
#
|
||||||
# Functions
|
# Functions
|
||||||
|
@ -29,13 +30,14 @@ __usage() {
|
||||||
echo " <Arguments>... Arguments passed to the command. Variable number of arguments allowed."
|
echo " <Arguments>... Arguments passed to the command. Variable number of arguments allowed."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " --verbose Show verbose output."
|
echo " --verbose Show verbose output."
|
||||||
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
|
echo " -c|--channel <CHANNEL> The channel of KoreBuild to download. Overrides the value from the config file.."
|
||||||
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
|
echo " --config-file <FILE> The path to the configuration file that stores values. Defaults to korebuild.json."
|
||||||
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
|
echo " -d|--dotnet-home <DIR> The directory where .NET Core tools will be stored. Defaults to '\$DOTNET_HOME' or '\$HOME/.dotnet."
|
||||||
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
|
echo " --path <PATH> The directory to build. Defaults to the directory containing the script."
|
||||||
echo " -s|--tools-source|-ToolsSource <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
|
echo " -s|--tools-source|-ToolsSource <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
|
||||||
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
|
echo " --tools-source-suffix|-ToolsSourceSuffix <SUFFIX> The suffix to append to tools-source. Useful for query strings."
|
||||||
|
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Description:"
|
echo "Description:"
|
||||||
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."
|
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() {
|
||||||
local version
|
local version
|
||||||
local lock_file="$repo_path/korebuild-lock.txt"
|
local lock_file="$repo_path/korebuild-lock.txt"
|
||||||
if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
|
if [ ! -f "$lock_file" ] || [ "$update" = true ]; then
|
||||||
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file"
|
__get_remote_file "$tools_source/korebuild/channels/$channel/latest.txt" "$lock_file" "$tools_source_suffix"
|
||||||
fi
|
fi
|
||||||
version="$(grep 'version:*' -m 1 "$lock_file")"
|
version="$(grep 'version:*' -m 1 "$lock_file")"
|
||||||
if [[ "$version" == '' ]]; then
|
if [[ "$version" == '' ]]; then
|
||||||
|
@ -66,7 +68,7 @@ get_korebuild() {
|
||||||
local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
|
local remote_path="$tools_source/korebuild/artifacts/$version/korebuild.$version.zip"
|
||||||
tmpfile="$(mktemp)"
|
tmpfile="$(mktemp)"
|
||||||
echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
|
echo -e "${MAGENTA}Downloading KoreBuild ${version}${RESET}"
|
||||||
if __get_remote_file "$remote_path" "$tmpfile"; then
|
if __get_remote_file "$remote_path" "$tmpfile" "$tools_source_suffix"; then
|
||||||
unzip -q -d "$korebuild_path" "$tmpfile"
|
unzip -q -d "$korebuild_path" "$tmpfile"
|
||||||
fi
|
fi
|
||||||
rm "$tmpfile" || true
|
rm "$tmpfile" || true
|
||||||
|
@ -98,6 +100,7 @@ __machine_has() {
|
||||||
__get_remote_file() {
|
__get_remote_file() {
|
||||||
local remote_path=$1
|
local remote_path=$1
|
||||||
local local_path=$2
|
local local_path=$2
|
||||||
|
local remote_path_suffix=$3
|
||||||
|
|
||||||
if [[ "$remote_path" != 'http'* ]]; then
|
if [[ "$remote_path" != 'http'* ]]; then
|
||||||
cp "$remote_path" "$local_path"
|
cp "$remote_path" "$local_path"
|
||||||
|
@ -106,14 +109,14 @@ __get_remote_file() {
|
||||||
|
|
||||||
local failed=false
|
local failed=false
|
||||||
if __machine_has wget; then
|
if __machine_has wget; then
|
||||||
wget --tries 10 --quiet -O "$local_path" "$remote_path" || failed=true
|
wget --tries 10 --quiet -O "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
|
||||||
else
|
else
|
||||||
failed=true
|
failed=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$failed" = true ] && __machine_has curl; then
|
if [ "$failed" = true ] && __machine_has curl; then
|
||||||
failed=false
|
failed=false
|
||||||
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "$remote_path" || failed=true
|
curl --retry 10 -sSL -f --create-dirs -o "$local_path" "${remote_path}${remote_path_suffix}" || failed=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$failed" = true ]; then
|
if [ "$failed" = true ]; then
|
||||||
|
@ -164,6 +167,11 @@ while [[ $# -gt 0 ]]; do
|
||||||
tools_source="${1:-}"
|
tools_source="${1:-}"
|
||||||
[ -z "$tools_source" ] && __usage
|
[ -z "$tools_source" ] && __usage
|
||||||
;;
|
;;
|
||||||
|
--tools-source-suffix|-ToolsSourceSuffix)
|
||||||
|
shift
|
||||||
|
tools_source_suffix="${1:-}"
|
||||||
|
[ -z "$tools_source_suffix" ] && __usage
|
||||||
|
;;
|
||||||
-u|--update|-Update)
|
-u|--update|-Update)
|
||||||
update=true
|
update=true
|
||||||
;;
|
;;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче