From df271c48cc9a1e780e45d803c8c5b6e21170a032 Mon Sep 17 00:00:00 2001 From: Manikyam Bavandla Date: Thu, 7 Jul 2016 18:06:20 -0700 Subject: [PATCH] PowerShellGet changes for Linux --- .../Shared/PowerShellGet/PSGet.Resource.psd1 | Bin 78998 -> 78920 bytes .../Shared/PowerShellGet/PSModule.psm1 | 131 +++++++++++------- 2 files changed, 82 insertions(+), 49 deletions(-) diff --git a/src/Modules/Shared/PowerShellGet/PSGet.Resource.psd1 b/src/Modules/Shared/PowerShellGet/PSGet.Resource.psd1 index 6dfd08222a2a507b315dee74819f83970a894f7c..5fc17b600e3eaabd4f23e4fb60444702931817f7 100644 GIT binary patch delta 307 zcmbRClI6q;mWC~it2o#d7!n!s7*Zw&vWv4iGvqTAO=eV5-+qpRah2%wJI0K&CMzfk zO#UFtvwemfqYBsLs5YMM30jPHtn!Ww3JkssnGDGcML=!EK%B-I{3Q$-K#NL%ddh)x@pMNuM)Aom@?!kSK#h4otvO($N+uUNN>0D0 z%P7Hb#8Ati4pg58Ha~ZIp$?p6MNGjB?W#7&Edl>oF)yPK*_wd~ONH^gFtY zVv{%AVzI0QYARw#1v;b@Xe!9cOrQ-4Kz=0P(j~VT^-&yv2}Fh#3IJ`%n=8 delta 288 zcmX@{f@RuEmWC~it2ic`Nr_E1P~_YGg@bXG==3agMv=)MWO=rS$TO;NO`3 zd2-=t(aAlZ_@-abXJnhcMjPnPm=dnZK1-w~E3mLl4lop(9M#6Ny+xDJj&=Ga9mcZh z2V@zIU^;}Rcj+=#O%6~Ln=WR=D8QWwbe96qL-`CP(^d5tgD0~oLHuoI$SA}N0K#ui AW&i*H diff --git a/src/Modules/Shared/PowerShellGet/PSModule.psm1 b/src/Modules/Shared/PowerShellGet/PSModule.psm1 index 6f53550ef0..c3d986e34e 100644 --- a/src/Modules/Shared/PowerShellGet/PSModule.psm1 +++ b/src/Modules/Shared/PowerShellGet/PSModule.psm1 @@ -14,25 +14,40 @@ Microsoft.PowerShell.Core\Set-StrictMode -Version Latest # Check if this is nano server. [System.Runtime.Loader.AssemblyLoadContext] is only available on NanoServer $script:isNanoServer = $null -ne ('System.Runtime.Loader.AssemblyLoadContext' -as [Type]) -try + +if($IsWindows) { - $script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments") + $script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell" } -catch +else { - $script:MyDocumentsFolderPath = $null + $script:ProgramFilesPSPath = $PSHome } -$script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell" +if($IsWindows) +{ + try + { + $script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments") + } + catch + { + $script:MyDocumentsFolderPath = $null + } -$script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath) - { - Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell" - } - else - { - Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell" - } + $script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath) + { + Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell" + } + else + { + Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell" + } +} +else +{ + $script:MyDocumentsPSPath = Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath ".local/share/PowerShell" +} $script:ProgramFilesModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath "Modules" $script:MyDocumentsModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath "Modules" @@ -43,8 +58,18 @@ $script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:TempPath = ([System.IO.DirectoryInfo]$env:TEMP).FullName $script:PSGetItemInfoFileName = "PSGetModuleInfo.xml" -$script:PSGetProgramDataPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramData -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' -$script:PSGetAppLocalPath = Microsoft.PowerShell.Management\Join-Path -Path $env:LOCALAPPDATA -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' + +if($IsWindows) +{ + $script:PSGetProgramDataPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramData -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' + $script:PSGetAppLocalPath = Microsoft.PowerShell.Management\Join-Path -Path $env:LOCALAPPDATA -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\' +} +else +{ + $script:PSGetProgramDataPath = "$HOME/.config/powershell/PowerShellGet" #TODO: Get $env:ProgramData equivalent + $script:PSGetAppLocalPath = "$HOME/.config/powershell/PowerShellGet" +} + $script:PSGetModuleSourcesFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:PSGetAppLocalPath -ChildPath "PSRepositories.xml" $script:PSGetModuleSources = $null $script:PSGetInstalledModules = $null @@ -89,8 +114,8 @@ $script:NuGetProviderVersion = [Version]'2.8.5.201' $script:SupportsPSModulesFeatureName="supports-powershell-modules" $script:FastPackRefHastable = @{} -$script:NuGetBinaryProgramDataPath="$env:ProgramFiles\PackageManagement\ProviderAssemblies" -$script:NuGetBinaryLocalAppDataPath="$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies" +$script:NuGetBinaryProgramDataPath=if($IsWindows) {"$env:ProgramFiles\PackageManagement\ProviderAssemblies"} +$script:NuGetBinaryLocalAppDataPath=if($IsWindows) {"$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies"} # go fwlink for 'https://nuget.org/nuget.exe' $script:NuGetClientSourceURL = 'http://go.microsoft.com/fwlink/?LinkID=690216&clcid=0x409' $script:NuGetExeName = 'NuGet.exe' @@ -577,7 +602,7 @@ catch # Ignore the error and try adding the type below } -if(-not $script:TelemetryEnabled) +if(-not $script:TelemetryEnabled -and $IsWindows) { try { @@ -682,7 +707,7 @@ function Publish-Module Begin { - if($script:isNanoServer) { + if($script:isNanoServer -or $IsCore) { $message = $LocalizedData.PublishPSArtifactUnsupportedOnNano -f "Module" ThrowError -ExceptionName "System.InvalidOperationException" ` -ExceptionMessage $message ` @@ -1808,10 +1833,6 @@ function Update-Module [PSCredential] $ProxyCredential, - [Parameter()] - [switch] - $SkipPublisherCheck, - [Parameter()] [Switch] $Force @@ -2485,7 +2506,7 @@ function Publish-Script Begin { - if($script:isNanoServer) { + if($script:isNanoServer -or $IsCore) { $message = $LocalizedData.PublishPSArtifactUnsupportedOnNano -f "Script" ThrowError -ExceptionName "System.InvalidOperationException" ` -ExceptionMessage $message ` @@ -6129,7 +6150,7 @@ function Ping-Endpoint $results = @{} $WebProxy = $null - if($Proxy) + if($Proxy -and $IsWindows) { $ProxyNetworkCredential = $null if($ProxyCredential) @@ -6359,6 +6380,11 @@ function ValidateAndSet-PATHVariableIfUserAccepts $Request ) + if(-not $IsWindows) + { + return + } + Set-PSGetSettingsVariable # Check and add the scope path to PATH environment variable if USER accepts the prompt. @@ -7154,9 +7180,10 @@ function Install-NuGetClientBinaries $Force ) - if($script:NuGetProvider -and - (-not $BootstrapNuGetExe -or - ($script:NuGetExePath -and (Microsoft.PowerShell.Management\Test-Path -Path $script:NuGetExePath)))) + if(-not $IsWindows -or + ($script:NuGetProvider -and + (-not $BootstrapNuGetExe -or + ($script:NuGetExePath -and (Microsoft.PowerShell.Management\Test-Path -Path $script:NuGetExePath))))) { return } @@ -7256,7 +7283,7 @@ function Install-NuGetClientBinaries } # On Nano server we don't need NuGet.exe - if(-not $bootstrapNuGetProvider -and ($script:isNanoServer -or -not $BootstrapNuGetExe)) + if(-not $bootstrapNuGetProvider -and ($script:isNanoServer -or $IsCore -or -not $BootstrapNuGetExe)) { return } @@ -7313,7 +7340,7 @@ function Install-NuGetClientBinaries } } - if($BootstrapNuGetExe -and -not $script:isNanoServer) + if($BootstrapNuGetExe -and -not $script:isNanoServer -and -not $IsCore) { Write-Verbose -Message $LocalizedData.DownloadingNugetExe @@ -7397,10 +7424,19 @@ function Test-RunningAsElevated [OutputType([bool])] Param() - $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent() - $prp=new-object System.Security.Principal.WindowsPrincipal($wid) - $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator - return $prp.IsInRole($adm) + if($IsWindows) + { + $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent() + $prp=new-object System.Security.Principal.WindowsPrincipal($wid) + $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator + return $prp.IsInRole($adm) + } + elseif($IsLinux) + { + return ($env:SUDO_UID -eq '1000') + } + + return $false } function Get-EscapedString @@ -13638,6 +13674,10 @@ function Validate-ModuleAuthenticodeSignature [string] $InstallLocation, + [Parameter()] + [Switch] + $IsUpdateOperation, + [Parameter()] [Switch] $SkipPublisherCheck @@ -13652,21 +13692,13 @@ function Validate-ModuleAuthenticodeSignature } # Skip the publisher check when -SkipPublisherCheck is specified and - # previously-installed module is not signed by Microsoft - if($SkipPublisherCheck) + # it is not an update operation. + if(-not $IsUpdateOperation -and $SkipPublisherCheck) { - if($InstalledModuleDetails -and $InstalledModuleDetails.IsMicrosoftCertificate) - { - $Message = $LocalizedData.ProceedingWithPublisherCheckForMicrosoftModules -f ($CurrentModuleInfo.Name) - Write-Verbose -Message $message - } - else - { - $Message = $LocalizedData.SkippingPublisherCheck -f ($CurrentModuleInfo.Version, $CurrentModuleInfo.Name) - Write-Verbose -Message $message + $Message = $LocalizedData.SkippingPublisherCheck -f ($CurrentModuleInfo.Version, $CurrentModuleInfo.Name) + Write-Verbose -Message $message - return $true - } + return $true } # Validate the catalog signature for the current module being installed. @@ -13744,7 +13776,7 @@ function Validate-ModuleAuthenticodeSignature } else { - $Message = $LocalizedData.PublishersMismatch -f ($CurrentModuleAuthenticodePublisher, $CurrentModuleInfo.Name, $CurrentModuleInfo.Version, $InstalledModuleAuthenticodePublisher, $InstalledModuleInfo.Name, $InstalledModuleVersion) + $Message = $LocalizedData.PublishersMismatch -f ($InstalledModuleInfo.Name, $InstalledModuleVersion, $CurrentModuleInfo.Name, $CurrentModuleAuthenticodePublisher, $CurrentModuleInfo.Version) ThrowError -ExceptionName 'System.InvalidOperationException' ` -ExceptionMessage $message ` -ErrorId 'PublishersMismatch' ` @@ -14130,10 +14162,11 @@ function Test-ValidManifestModule -CallerPSCmdlet $PSCmdlet ` -ErrorCategory InvalidOperation } - else + elseif($IsWindows) { $ValidationResult = Validate-ModuleAuthenticodeSignature -CurrentModuleInfo $PSModuleInfo ` -InstallLocation $InstallLocation ` + -IsUpdateOperation:$IsUpdateOperation ` -SkipPublisherCheck:$SkipPublisherCheck if($ValidationResult)