Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow global install of PowerShell modules #5611

Merged
merged 4 commits into from
Oct 5, 2023

Conversation

gerardog
Copy link
Contributor

@gerardog gerardog commented Aug 18, 2023

Allow global install of PowerShell modules

Description

Motivation and Context

Closes #5601 #5597

How Has This Been Tested?

By installing, updating, uninstalling gsudo.

scoop install gsudo -g
scoop uninstall gsudo -g

scoop install gsudo@2.1.0 -g
scoop install gsudo@2.3.0 -g

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@gerardog
Copy link
Contributor Author

By installing them to $env:ProgramFiles\WindowsPowerShell\Modules which is the folder where both Windows PowerShell and PowerShell core use. (See https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath )

Another alternative would be to install to a new folder named C:\ProgramData\scoop\Modules\, analog to current per user module: C:\Users\gerar\scoop\modules, and add that folder to the system $env:PSModulePath

@HUMORCE
Copy link
Member

HUMORCE commented Aug 22, 2023

Another alternative would be to install to a new folder named C:\ProgramData\scoop\Modules, analog to current per user module: C:\Users\gerar\scoop\modules, and add that folder to the system $env:PSModulePath

This is more in line with current Scoop directory structure.

@gerardog
Copy link
Contributor Author

Yeah! I may have dreamed about it or something like that because it suddenly made sense that the first commit was not the best way to address the issue!

@gerardog
Copy link
Contributor Author

Fixed!

Install:

PS C:\Windows\System32> scoop install gsudo -g
Installing 'gsudo' (2.3.0) [64bit] from main bucket
Loading gsudo.setup.x64.msi from cache
Checking hash of gsudo.setup.x64.msi ... ok.
Extracting gsudo.setup.x64.msi ... done.
Linking C:\ProgramData\scoop\apps\gsudo\current => C:\ProgramData\scoop\apps\gsudo\2.3.0
Creating shim for 'sudo'.
Adding C:\ProgramData\scoop\modules to global PowerShell module path.
Installing PowerShell module 'gsudoModule'
Linking C:\ProgramData\scoop\modules\gsudoModule => C:\ProgramData\scoop\apps\gsudo\current
Running post_install script...
'gsudo' (2.3.0) was installed successfully!
Notes
-----
gsudo has a PowerShell module that adds `gsudo !!` to elevate the last command.
Use the module by running: 'Import-Module gsudoModule'.
Add it to your $PROFILE to make it permanent.

(note: Adding C:\ProgramData\scoop\modules to global PowerShell module path.)

Is Module Available?

PS C:\Windows\System32> Get-Module gsudoModule -All |% Path
C:\ProgramData\scoop\modules\gsudoModule\gsudoModule.psm1

Uninstall:

PS C:\Windows\System32> scoop uninstall gsudo -g
Uninstalling 'gsudo' (2.3.0).
Removing shim 'sudo.shim'.
Removing shim 'sudo.exe'.
Unlinking C:\ProgramData\scoop\apps\gsudo\current
Uninstalling PowerShell module 'gsudoModule'.
Removing C:\ProgramData\scoop\modules\gsudoModule
Removing C:\ProgramData\scoop\apps\gsudo\current from your path.
'gsudo' was uninstalled.

RegKey Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment:

Before: %ProgramFiles%\WindowsPowerShell\Modules;%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules
After: C:\ProgramData\scoop\modules;%ProgramFiles%\WindowsPowerShell\Modules;%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules

@HUMORCE
Copy link
Member

HUMORCE commented Aug 23, 2023

LGTM

@rashil2000 rashil2000 merged commit ab34b7f into ScoopInstaller:develop Oct 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants