PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
483 stars 92 forks source link

Install-PSResource Failing with Scripts on Ubuntu 22.04 #1540

Closed natescherer closed 7 months ago

natescherer commented 7 months ago

Prerequisites

Steps to reproduce

Hello! I am experiencing a bug with PSRG 1.0.1 where scripts seemingly won't install on Ubuntu 22.04. This seems to happen with multiple scripts, but I used Assert-SameFile from https://www.powershellgallery.com/packages/Assert-SameFile/1.1.0 and tried it with PowerShell 7.4.1 on Windows 11 22H2, macOS 14.2.1, and Ubuntu 22.04, and only Ubuntu is showing this error.

After testing, it seems that running one of the two the below (depending on the scope you are trying to install with) before trying to install a script is an effective workaround:

mkdir -p ~/.local/share/powershell/Scripts/InstalledScriptInfos
mkdir -p /usr/local/share/powershell/Scripts/InstalledScriptInfos

Expected behavior

(taken from successful test on Windows 11 22h2)
PS C:\Users\nate> Install-PSResource Assert-SameFile

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by
running the Set-PSResourceRepository cmdlet. Are you sure you want to install the PSResource from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
WARNING: The installation path for the script does not currently appear in the CurrentUser path environment variable. To make the script discoverable, add the script installation path, C:\Users\nate\Documents\PowerShell\Scripts, to the environment PATH variable.
PS C:\Users\nate> Get-InstalledPSResource -Name Assert-SameFile

Name            Version Prerelease Repository Description
----            ------- ---------- ---------- -----------
Assert-SameFile 1.1.0              PSGallery  This script automates one typical test scenario, it compares the sample …

PS C:\Users\nate>

Actual behavior

PS /home/vscode> Install-PSResource Assert-SameFile

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by running the 
Set-PSResourceRepository cmdlet. Are you sure you want to install the PSResource from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
Install-PSResource: Unable to successfully install package 'Assert-SameFile': 'Could not find a part of the path '/home/vscode/.local/share/powershell/Scripts/InstalledScriptInfos/Assert-SameFile_InstalledScriptInfo.xml'.'
Install-PSResource: Operation is not valid due to the current state of the object.
Install-PSResource: Package(s) 'Assert-SameFile' could not be installed from repository 'PSGallery'.
PS /home/vscode>

Error details

Exception             : 
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package(s) 'Assert-SameFile' could not be installed from repository 'PSGallery'.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
CategoryInfo          : InvalidData: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResource], ResourceNotFoundException
FullyQualifiedErrorId : InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
InvocationInfo        : 
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 10
    Line             : Install-PSResource Assert-SameFile
    Statement        : Install-PSResource Assert-SameFile
    PositionMessage  : At line:1 char:1
                       + Install-PSResource Assert-SameFile
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.0.1                 Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSS…

Key   : PSVersion
Value : 7.4.1
Name  : PSVersion

Key   : PSEdition
Value : Core
Name  : PSEdition

Key   : GitCommitId
Value : 7.4.1
Name  : GitCommitId

Key   : OS
Value : Ubuntu 22.04.3 LTS
Name  : OS

Key   : Platform
Value : Unix
Name  : Platform

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Visuals

No response

natescherer commented 7 months ago

Wow, quick work. Thanks @anamnavi!