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

Provide ability to execute PowerShell script right before installation starts when using Install-ChocolateyPackage #1060

Closed
flcdrg opened this issue Nov 24, 2016 · 6 comments · Fixed by #1436

Comments

@flcdrg
Copy link
Member

flcdrg commented Nov 24, 2016

I would like to execute some logic between the download and the install.. eg. around here: https://github.com/chocolatey/choco/blob/stable/src/chocolatey.resources/helpers/functions/Install-ChocolateyPackage.ps1#L313

If there was a new optional argument for Install-ChocolateyPackage that was of type [ScriptBlock] that was executed just before the call to Install-ChocolateyInstallPackage, that would do the job.

My particular scenario is needing to configure some firewall rules (to avoid Windows Firewall displaying a dialog about an application requiring access). I'm currently doing this before the call to Install-ChocolateyPackage, but ideally it would be done as late as possible, but before the actual install takes place, such that if there was a problem with the download then the firewall would not have been set.

@ferventcoder
Copy link
Member

You can do this now though.

Install-ChocolateyPackage is a combination of

  • Get-ChocolateyWebFile
  • Install-ChocolateyInstallPackage.

Not saying this isn't a good idea, just saying you have more options.

@flcdrg
Copy link
Member Author

flcdrg commented Nov 25, 2016

I take your point. I'd be happy to do a PR for this if you like the idea though.

@ferventcoder
Copy link
Member

Sure thing! I was thinking of adding a script block for no icons function. :)

flcdrg added a commit to flcdrg/choco that referenced this issue Oct 27, 2017
- Add a ScriptBlock parameter to Install-ChocolateyPackage.ps1 that if present, is called after download but before install.
flcdrg added a commit to flcdrg/choco that referenced this issue Oct 27, 2017
…Package.ps1

- Add a ScriptBlock parameter `BeforeInstall` to Install-ChocolateyPackage.ps1. If supplied, the script block is called after download but before install.
@ferventcoder ferventcoder added this to the 0.10.12 milestone Jan 18, 2019
flcdrg added a commit to flcdrg/choco that referenced this issue Jan 18, 2019
…Package.ps1

- Add a ScriptBlock parameter `BeforeInstall` to Install-ChocolateyPackage.ps1. If supplied, the script block is called after download but before install.
@flcdrg
Copy link
Member Author

flcdrg commented Jan 18, 2019

Rebased, just for good measure

@ferventcoder ferventcoder modified the milestones: 0.10.12, 0.10.13, 0.10.14 Mar 13, 2019
@ferventcoder ferventcoder modified the milestones: 0.10.14, 0.10.15 Apr 1, 2019
@gep13 gep13 modified the milestones: 0.10.15, 0.10.16 May 31, 2019
gep13 pushed a commit to flcdrg/choco that referenced this issue Apr 16, 2021
…Package.ps1

- Add a ScriptBlock parameter `BeforeInstall` to Install-ChocolateyPackage.ps1. If supplied, the script block is called after download but before install.
gep13 pushed a commit to flcdrg/choco that referenced this issue Apr 16, 2021
…Package.ps1

- Add a ScriptBlock parameter `BeforeInstall` to Install-ChocolateyPackage.ps1. If supplied, the script block is called after download but before install.
gep13 added a commit that referenced this issue Apr 16, 2021
(GH-1060) Add BeforeInstall parameter to Install-ChocolateyPackage.ps1
@gep13 gep13 removed the 2 - Working label Apr 16, 2021
@gep13 gep13 added the 4 - Done label Apr 16, 2021
@gep13 gep13 closed this as completed Apr 16, 2021
gep13 added a commit that referenced this issue Apr 19, 2021
* stable:
  (#1861) Improves terminology in help documentation
  (#1998) Add authorization header to Get-WebFile
  (maint) Repalce RawGit with raw.githack.com CDN
  (#1899) Remove unused variables
  (GH-1060) Add BeforeInstall parameter to Install-ChocolateyPackage.ps1
  (maint) Improve log message
  (GH-2092) Take all registry keys into account
  (GH-1364) Template create .nuspec encoded without BOM
  (#1866) Limit pending package removal to top level
  (GH-2203) Get-ChocolateyUnzip add unzipLocation alias
  (GH-1889) Fix: Removal of ApiKey broken
  (#2114) Remove unused variable
  (GH-2048) update deprecation note to outdated
  (maint) Spelling and grammar fixes
  (maint) Replace tabs with spaces
  (#2078) Skip importing Chocolatey GUI Extension
  (#2227) Use latest Mono and Ubuntu on Travis
steviecoaster added a commit to steviecoaster/choco that referenced this issue May 11, 2021
…GH2112

* 'GH2112' of https://github.com/steviecoaster/choco:
  (chocolatey#2112) Add msp support to Install helper
  (maint) Switch to using a Regex match
  (maint) Change formatting
  (maint) Remove use of PowerShell aliases
  (maint) Replace " with '
  (chocolatey#2044) Fix for changing $env:Temp
  (chocolatey#2259) Switched to versioned NuGet.Core
  (chocolatey#2111) Deep copy config
  (chocolatey#2244) Add Mac build into main workflow
  (chocolatey#2238) Mono build don't hardcode xbuild path
  (maint) Fix artifact paths on AppVeyor
  (chocolatey#2244) Fix syntax for running on Windows
  (chocolatey#2244) Initial workflow for Windows and Ubuntu
  (doc) Remove Mono instructions for other distributions
  (doc) Add Ubuntu 20.04 mono install instructions
  (chocolatey#2227) Bump Mono version in Dockerfile and README
  (chocolatey#2236) Mono test work with merged usr systems
  (chocolatey#2190) Clarify help for SpecificFolder parameter
  (chocolatey#1962) Use different message on error
  (chocolatey#1861) Improves terminology in help documentation
  (chocolatey#1998) Add authorization header to Get-WebFile
  (maint) Repalce RawGit with raw.githack.com CDN
  (chocolatey#1899) Remove unused variables
  (chocolateyGH-1060) Add BeforeInstall parameter to Install-ChocolateyPackage.ps1
  (maint) Improve log message
  (chocolateyGH-2092) Take all registry keys into account
  (chocolateyGH-1364) Template create .nuspec encoded without BOM
  (chocolatey#1866) Limit pending package removal to top level
  (chocolateyGH-2203) Get-ChocolateyUnzip add unzipLocation alias
  (chocolateyGH-1889) Fix: Removal of ApiKey broken
  (chocolatey#2114) Remove unused variable
  (chocolateyGH-2048) update deprecation note to outdated
  (maint) Spelling and grammar fixes
  (maint) Replace tabs with spaces
  (chocolatey#2078) Skip importing Chocolatey GUI Extension
  (chocolatey#2227) Use latest Mono and Ubuntu on Travis
  (chocolatey#2205) Remove mention of private repository
  (chocolatey#2205) Update remaining URLs to new location
  (maint) Remove unnecessary whitespace
  (chocolatey#2231) Change default repository URL
  (maint) Remove unnecessary whitespace
  (chocolatey#2205) Update all chocolatey.org/docs URLs
  (maint) Remove unnecessary whitespace
  (chocolatey#2205) Update automatic-packages docs links
  (doc) Update to prefer # rather than GH-
  (maint) Fix replacement
  (maint) Revert change to earlier commit
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (doc) Update script to Statiq format
  (maint) Add missing backtick in example
  (maint) Added explicit link to new function name
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (maint) Fix spelling mistake
  (maint) Remove generated docs files
  (maint) Add docs/generated folder to ignore list
  (chocolateyGH-2105) Update link to Chocolatey workshop
@gep13 gep13 changed the title Add -BeforeInstall ScriptBlock for Install-ChocolateyPackage Provide ability to execute PowerShell script right before installation starts when using Install-ChocolateyPackage May 18, 2021
@ferventcoder
Copy link
Member

Just a follow up on this one - how does Write-FunctionCallLogMessage handle the script block? This question is for @flcdrg and @gep13. That function is the call that logs the parameters. Just curious if it handles the script block properly or if an issue should be filed as a followup on this to be fixed in a later Chocolatey release.

@AdmiringWorm
Copy link
Member

@ferventcoder we have verified that the beforeInstall script block parameter will be logged correctly and that the value set to the parameter will be outputted to the log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants