Fixup the run.sh build script

- add the --reinstall flag
 - add error messages when parameters are missing values
 - use arrays to property concatenate pass-thru args
This commit is contained in:
Nate McMaster 2017-12-20 09:34:09 -08:00
parent ee8d0f30eb
commit d66405bef1
2 changed files with 26 additions and 9 deletions

View File

@ -26,6 +26,9 @@ The base url where build tools can be downloaded. Overrides the value from the c
.PARAMETER Update .PARAMETER Update
Updates KoreBuild to the latest version even if a lock file is present. Updates KoreBuild to the latest version even if a lock file is present.
.PARAMETER Reinstall
Re-installs KoreBuild
.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.
@ -74,6 +77,7 @@ param(
[string]$ToolsSource, [string]$ToolsSource,
[Alias('u')] [Alias('u')]
[switch]$Update, [switch]$Update,
[switch]$Reinstall,
[string]$ConfigFile, [string]$ConfigFile,
[string]$PackageVersionPropsUrl = $null, [string]$PackageVersionPropsUrl = $null,
[string]$AccessTokenSuffix = $null, [string]$AccessTokenSuffix = $null,
@ -105,6 +109,10 @@ function Get-KoreBuild {
$version = $version.TrimStart('version:').Trim() $version = $version.TrimStart('version:').Trim()
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version) $korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
if ($Reinstall -and (Test-Path $korebuildPath)) {
Remove-Item -Force -Recurse $korebuildPath
}
if (!(Test-Path $korebuildPath)) { if (!(Test-Path $korebuildPath)) {
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version" Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
New-Item -ItemType Directory -Path $korebuildPath | Out-Null New-Item -ItemType Directory -Path $korebuildPath | Out-Null

27
run.sh
View File

@ -14,6 +14,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet" [ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
verbose=false verbose=false
update=false update=false
reinstall=false
repo_path="$DIR" repo_path="$DIR"
channel='' channel=''
tools_source='' tools_source=''
@ -44,6 +45,7 @@ __usage() {
echo " --access-token <Token> The query string to append to any blob store access for PackageVersionPropsUrl, if any." echo " --access-token <Token> The query string to append to any blob store access for PackageVersionPropsUrl, if any."
echo " --restore-sources <Sources> Semi-colon delimited list of additional NuGet feeds to use as part of restore." echo " --restore-sources <Sources> Semi-colon delimited list of additional NuGet feeds to use as part of restore."
echo " -u|--update Update to the latest KoreBuild even if the lock file is present." echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
echo " --reinstall Reinstall KoreBuild."
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."
@ -68,6 +70,10 @@ get_korebuild() {
version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version" local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version"
if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then
rm -rf "$korebuild_path"
fi
{ {
if [ ! -d "$korebuild_path" ]; then if [ ! -d "$korebuild_path" ]; then
mkdir -p "$korebuild_path" mkdir -p "$korebuild_path"
@ -146,12 +152,12 @@ while [[ $# -gt 0 ]]; do
-c|--channel|-Channel) -c|--channel|-Channel)
shift shift
channel="${1:-}" channel="${1:-}"
[ -z "$channel" ] && __usage [ -z "$channel" ] && __error "Missing value for parameter --channel" && __usage
;; ;;
--config-file|-ConfigFile) --config-file|-ConfigFile)
shift shift
config_file="${1:-}" config_file="${1:-}"
[ -z "$config_file" ] && __usage [ -z "$config_file" ] && __error "Missing value for parameter --config-file" && __usage
if [ ! -f "$config_file" ]; then if [ ! -f "$config_file" ]; then
__error "Invalid value for --config-file. $config_file does not exist." __error "Invalid value for --config-file. $config_file does not exist."
exit 1 exit 1
@ -160,41 +166,44 @@ while [[ $# -gt 0 ]]; do
-d|--dotnet-home|-DotNetHome) -d|--dotnet-home|-DotNetHome)
shift shift
DOTNET_HOME="${1:-}" DOTNET_HOME="${1:-}"
[ -z "$DOTNET_HOME" ] && __usage [ -z "$DOTNET_HOME" ] && __error "Missing value for parameter --dotnet-home" && __usage
;; ;;
--path|-Path) --path|-Path)
shift shift
repo_path="${1:-}" repo_path="${1:-}"
[ -z "$repo_path" ] && __usage [ -z "$repo_path" ] && __error "Missing value for parameter --path" && __usage
;; ;;
-s|--tools-source|-ToolsSource) -s|--tools-source|-ToolsSource)
shift shift
tools_source="${1:-}" tools_source="${1:-}"
[ -z "$tools_source" ] && __usage [ -z "$tools_source" ] && __error "Missing value for parameter --tools-source" && __usage
;; ;;
--package-version-props-url|-PackageVersionPropsUrl) --package-version-props-url|-PackageVersionPropsUrl)
shift shift
package_version_props_url="${1:-}" package_version_props_url="${1:-}"
[ -z "$package_version_props_url" ] && __usage [ -z "$package_version_props_url" ] && __error "Missing value for parameter --package-version-props-url" && __usage
;; ;;
--access-token-suffix|-AccessTokenSuffix) --access-token-suffix|-AccessTokenSuffix)
shift shift
access_token_suffix="${1:-}" access_token_suffix="${1:-}"
[ -z "$access_token_suffix" ] && __usage # This suffix can be empty
;; ;;
--restore-sources|-RestoreSources) --restore-sources|-RestoreSources)
shift shift
restore_sources="${1:-}" restore_sources="${1:-}"
[ -z "$restore_sources" ] && __usage [ -z "$restore_sources" ] && __error "Missing value for parameter --restore-sources" && __usage
;; ;;
--asset-root-url|-AssetRootUrl) --asset-root-url|-AssetRootUrl)
shift shift
asset_root_url="${1:-}" asset_root_url="${1:-}"
[ -z "$asset_root_url" ] && __usage [ -z "$asset_root_url" ] && __error "Missing value for parameter --asset-root-url" && __usage
;; ;;
-u|--update|-Update) -u|--update|-Update)
update=true update=true
;; ;;
--reinstall|-Reinstall)
reinstall=true
;;
--verbose|-Verbose) --verbose|-Verbose)
verbose=true verbose=true
;; ;;