From 5ed38f97afbb107040a0e881d6df45ef1b7fc579 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 8 Aug 2017 10:22:20 -0400 Subject: [PATCH 1/4] Allow powershell bootstrap script to specify PY2 or 3 This fixes the links for installing 2017.7.0 (the executor link has changed to include a "Py2" or "Py3" section). It also allows the user to specify if the Py2 or Py3 executor should be used. This option only works for Salt >= 2017.7.0. Example for Py2 (default behavior): ``` ./bootstrap-salt.ps1 -pythonVersion 2 ``` Example for Py3: ``` ./bootstrap-salt.ps1 -pythonVersion 3 ``` --- bootstrap-salt.ps1 | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index 7cf636f..fdfc30f 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -13,9 +13,14 @@ Runs without any parameters. Uses all the default values/settings. .EXAMPLE - ./bootstrap-salt.ps1 -version 2015.4.1-3 + ./bootstrap-salt.ps1 -version 2017.7.0 Specifies a particular version of the installer. +.EXAMPLE + ./bootstrap-salt.ps1 -pythonVersion 3 + Specifies the Python version of the installer. Can be "2" or "3". Defaults to "2". + Python 3 installers are only available for Salt 2017.7.0 and newer. + .EXAMPLE ./bootstrap-salt.ps1 -runservice false Specifies the salt-minion service to stop and be set to manual. Useful for @@ -27,12 +32,18 @@ installer values of host name for the minion id and "salt" for the master. .EXAMPLE - ./bootstrap-salt.ps1 -minion minion-box -master master-box -version 2015.5.2 -runservice false + ./bootstrap-salt.ps1 -minion minion-box -master master-box -version 2017.7.0 -runservice false Specifies all the optional parameters in no particular order. .PARAMETER version Default version defined in this script. +.PARAMETER pythonVersion + The version of Python the installer should use. Specify either "2" or "3". + Beginning with Salt 2017.7.0, Salt will run on either Python 2 or Python 3. + The default is Python 2 if not specified. This parameter only works for Salt + versions >= 2017.7.0. + .PARAMETER runservice Boolean flag to start or stop the minion service. True will start the minion service. False will stop the minion service and set it to "manual". The @@ -69,6 +80,11 @@ Param( [ValidatePattern('^201\d\.\d{1,2}\.\d{1,2}(\-\d{1})?|(rc\d)$')] [string]$version = '', + [Parameter(Mandatory=$false,ValueFromPipeline=$true)] + # Doesn't support versions prior to "2017.7.0" + [ValidateSet("2","3")] + [string]$pythonVersion = "", + [Parameter(Mandatory=$false,ValueFromPipeline=$true)] [ValidateSet("true","false")] [string]$runservice = "true", @@ -113,6 +129,7 @@ If (!(Get-IsAdministrator)) { If($master -ne "not-specified") {$parameters = "$parameters -master $master"} If($runservice -eq $false) {$parameters = "$parameters -runservice false"} If($version -ne '') {$parameters = "$parameters -version $version"} + If($pythonVersion -ne "") {$parameters = "$parameters -pythonVersion $pythonVersion"} $newProcess.Arguments = $myInvocation.MyCommand.Definition, $parameters # Specify the current working directory @@ -214,10 +231,23 @@ If (!$version) { $version = $($returnMatches[$returnMatches.Count -1]).Split(("n-","-A","-x"),([System.StringSplitOptions]::RemoveEmptyEntries))[1] } +$year = $version.Substring(0, 3) +If ([int]$year -lt 2017) { + $pythonVersion = "" +} +Else { + If ($pythonVersion -eq "3") { + $pythonVersion = "Py3-" + } + Else { + $pythonVersion = "Py2-" + } +} + #=============================================================================== # Download minion setup file #=============================================================================== -$saltExe = "Salt-Minion-$version-$arch-Setup.exe" +$saltExe = "Salt-Minion-$version-$pythonVersion$arch-Setup.exe" Write-Output "Downloading Salt minion installer $saltExe" $webclient = New-Object System.Net.WebClient $url = "$repourl/$saltExe" From e27dd0a167363bb0e48f708f7a52871dd3e464c3 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 8 Aug 2017 10:32:50 -0400 Subject: [PATCH 2/4] Create a $versionSection variable for exe link This is a little more cautious/explicit with the variables setup in the $saltExe definition. --- bootstrap-salt.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index fdfc30f..e25e258 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -237,17 +237,18 @@ If ([int]$year -lt 2017) { } Else { If ($pythonVersion -eq "3") { - $pythonVersion = "Py3-" + $pythonVersion = "-Py3" } Else { - $pythonVersion = "Py2-" + $pythonVersion = "-Py2" } } +$versionSection = $version + $pythonVersion #=============================================================================== # Download minion setup file #=============================================================================== -$saltExe = "Salt-Minion-$version-$pythonVersion$arch-Setup.exe" +$saltExe = "Salt-Minion-$versionSection-$arch-Setup.exe" Write-Output "Downloading Salt minion installer $saltExe" $webclient = New-Object System.Net.WebClient $url = "$repourl/$saltExe" From 12c0468e524d4a0cdd0971528cc9ae040de66339 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 8 Aug 2017 10:37:30 -0400 Subject: [PATCH 3/4] Simplify logic: pythonVersion already defaults to "" --- bootstrap-salt.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index e25e258..9a7671a 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -232,10 +232,7 @@ If (!$version) { } $year = $version.Substring(0, 3) -If ([int]$year -lt 2017) { - $pythonVersion = "" -} -Else { +If ([int]$year -ge 2017) { If ($pythonVersion -eq "3") { $pythonVersion = "-Py3" } From e1cb060e655c564cecb857f179e0656ff8faf784 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 8 Aug 2017 09:52:36 -0600 Subject: [PATCH 4/4] Fix version detection, versionSection creation --- bootstrap-salt.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index 9a7671a..747c74d 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -228,19 +228,20 @@ If (!$version) { $returnMatches = $returnMatches | Where {$_ -like "Salt-Minion*AMD64-Setup.exe"} } - $version = $($returnMatches[$returnMatches.Count -1]).Split(("n-","-A","-x"),([System.StringSplitOptions]::RemoveEmptyEntries))[1] + $version = $($returnMatches[$returnMatches.Count -1]).Split(("n-","-A","-x","-P"),([System.StringSplitOptions]::RemoveEmptyEntries))[1] } -$year = $version.Substring(0, 3) +$versionSection = $version + +$year = $version.Substring(0, 4) If ([int]$year -ge 2017) { If ($pythonVersion -eq "3") { - $pythonVersion = "-Py3" + $versionSection = "$version-Py3" } Else { - $pythonVersion = "-Py2" + $versionSection = "$version-Py2" } } -$versionSection = $version + $pythonVersion #=============================================================================== # Download minion setup file