From 4572f5648cd59e13cdeafcebdffa5ce6a9a3b611 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 5 Jun 2018 13:39:09 -0700 Subject: [PATCH 1/3] change the package template to make the product id a placeholder --- tools/packaging/packaging.strings.psd1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/packaging/packaging.strings.psd1 b/tools/packaging/packaging.strings.psd1 index 3c0db575c4d..f120b88f14f 100644 --- a/tools/packaging/packaging.strings.psd1 +++ b/tools/packaging/packaging.strings.psd1 @@ -60,7 +60,7 @@ OsxDistributionTemplate = @' - + @@ -68,9 +68,9 @@ OsxDistributionTemplate = @' - + - {2} + {2} '@ NuspecTemplate = @' From 8f3286040effb3a67ca2ba48509e645060ece67c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 5 Jun 2018 13:41:22 -0700 Subject: [PATCH 2/3] fix utime workaround to work when it requires sudo --- tools/packaging/packaging.psm1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index 67e15b92064..cc67249e9ff 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -32,7 +32,9 @@ function Start-PSPackage { [Switch] $Force, - [Switch] $SkipReleaseChecks + [Switch] $SkipReleaseChecks, + + [switch] $NoSudo ) DynamicParam { @@ -318,6 +320,7 @@ function Start-PSPackage { Name = $Name Version = $Version Force = $Force + NoSudo = $NoSudo } foreach ($Distro in $Script:DebianDistributions) { $Arguments["Distribution"] = $Distro @@ -333,6 +336,7 @@ function Start-PSPackage { Name = $Name Version = $Version Force = $Force + NoSudo = $NoSudo } if ($PSCmdlet.ShouldProcess("Create $_ Package")) { @@ -534,7 +538,10 @@ function New-UnixPackage { [string]$Iteration = "1", [Switch] - $Force + $Force, + + [switch] + $NoSudo ) DynamicParam { @@ -555,6 +562,10 @@ function New-UnixPackage { } End { + # This allows sudo install to be optional; needed when running in containers / as root + # Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly + $sudo = if (!$NoSudo) { "sudo" } + # Validate platform $ErrorMessage = "Must be on {0} to build '$Type' packages!" switch ($Type) { @@ -655,7 +666,7 @@ function New-UnixPackage { if ($Environment.IsMacOS) { if (Test-Path $symlink_dest) { Write-Warning "Move $symlink_dest to $hack_dest (fpm utime bug)" - Move-Item $symlink_dest $hack_dest + Start-NativeExecution ([ScriptBlock]::Create("$sudo mv $symlink_dest $hack_dest")) } } @@ -723,7 +734,7 @@ function New-UnixPackage { # this is continuation of a fpm hack for a weird bug if (Test-Path $hack_dest) { Write-Warning "Move $hack_dest to $symlink_dest (fpm utime bug)" - Move-Item $hack_dest $symlink_dest + Start-NativeExecution ([ScriptBlock]::Create("$sudo mv $hack_dest $symlink_dest")) } } if ($AfterScriptInfo.AfterInstallScript) { From a8665e8fa476bbcff7affd7f7516babaedd8316b Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 5 Jun 2018 13:44:03 -0700 Subject: [PATCH 3/3] make path on macOS be /usr/local/microsoft/powershell/6 for stable releases and /usr/local/microsoft/powershell/6-preview for other releases. --- tools/packaging/packaging.psm1 | 57 +++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index cc67249e9ff..35523b8d0ea 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -612,7 +612,7 @@ function New-UnixPackage { } # Determine if the version is a preview version - $IsPreview = $Version.Contains("-preview") + $IsPreview = Test-IsPreview -Version $Version # Preview versions have preview in the name $Name = if ($IsPreview) { "powershell-preview" } else { "powershell" } @@ -752,7 +752,7 @@ function New-UnixPackage { if ($Environment.IsMacOS) { if ($pscmdlet.ShouldProcess("Add distribution information and Fix PackageName")) { - $createdPackage = New-MacOsDistributionPackage -FpmPackage $createdPackage + $createdPackage = New-MacOsDistributionPackage -FpmPackage $createdPackage -IsPreview:$IsPreview } } @@ -772,7 +772,8 @@ function New-MacOsDistributionPackage { param( [Parameter(Mandatory,HelpMessage='The FileInfo of the file created by FPM')] - [System.IO.FileInfo]$FpmPackage + [System.IO.FileInfo]$FpmPackage, + [Switch] $IsPreview ) if(!$Environment.IsMacOS) @@ -811,12 +812,15 @@ function New-MacOsDistributionPackage # Create the distribution xml $distributionXmlPath = Join-Path -Path $tempDir -ChildPath 'powershellDistribution.xml' + $packageId = Get-MacOSPackageId -IsPreview:$IsPreview.IsPresent + # format distribution template with: # 0 - title # 1 - version # 2 - package path - # 2 - minimum os version - $PackagingStrings.OsxDistributionTemplate -f "PowerShell - $packageVersion", $packageVersion, $packageName, '10.12' | Out-File -Encoding ascii -FilePath $distributionXmlPath -Force + # 3 - minimum os version + # 4 - Package Identifier + $PackagingStrings.OsxDistributionTemplate -f "PowerShell - $packageVersion", $packageVersion, $packageName, '10.12', $packageId | Out-File -Encoding ascii -FilePath $distributionXmlPath -Force Write-Log "Applying distribution.xml to package..." Push-Location $tempDir @@ -1097,6 +1101,24 @@ function New-ManGzip ManFile = $ManFile } } + +# Returns the macOS Package Identifier +function Get-MacOSPackageId +{ + param( + [switch] + $IsPreview + ) + if($IsPreview.IsPresent) + { + return 'com.microsoft.powershell-preview' + } + else + { + return 'com.microsoft.powershell' + } +} + function New-MacOSLauncher { param( @@ -1104,6 +1126,9 @@ function New-MacOSLauncher [String]$Version ) + $IsPreview = Test-IsPreview -Version $Version + $packageId = Get-MacOSPackageId -IsPreview:$IsPreview + # Define folder for launch application. $macosapp = "$PSScriptRoot/macos/launcher/ROOT/Applications/Powershell.app" @@ -1118,7 +1143,7 @@ function New-MacOSLauncher # Set values in plist. $plist = "$macosapp/Contents/Info.plist" Start-NativeExecution { - defaults write $plist CFBundleIdentifier com.microsoft.powershell + defaults write $plist CFBundleIdentifier $packageId defaults write $plist CFBundleVersion $Version defaults write $plist CFBundleShortVersionString $Version defaults write $plist CFBundleGetInfoString $Version @@ -2223,6 +2248,24 @@ function New-MSIPatch Remove-Item -Path $filesToCleanup -Force -Recurse -ErrorAction SilentlyContinue } +<# + .Synopsis + Tests if a version is preview + .EXAMPLE + Test-IsPreview -version '6.1.0-sometthing' # returns true + Test-IsPreview -version '6.1.0' # returns false +#> +function Test-IsPreview +{ + param( + [parameter(Mandatory)] + [string] + $Version + ) + + return $Version -like '*-*' +} + <# .Synopsis Creates a Windows installer MSI package and assumes that the binaries are already built using 'Start-PSBuild'. @@ -2294,7 +2337,7 @@ function New-MSIPackage $ProductSemanticVersion = Get-PackageSemanticVersion -Version $ProductVersion $simpleProductVersion = '6' - $isPreview = $ProductSemanticVersion -like '*-*' + $isPreview = Test-IsPreview -Version $ProductSemanticVersion if($isPreview) { $simpleProductVersion += '-preview'