diff --git a/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.0.0.1-pre.nupkg b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.0.0.1-pre.nupkg new file mode 100644 index 000000000..5b4bf4f33 Binary files /dev/null and b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.0.0.1-pre.nupkg differ diff --git a/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.nuspec b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.nuspec new file mode 100644 index 000000000..192ec2a6f --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension.nuspec @@ -0,0 +1,38 @@ + + + + + chocolatey-preinstaller-checks.extension + 0.0.1-pre + bcurran3 + https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension + Chocolatey Preinstaller Checks Extension + Bill Curran + https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension + https://raw.githubusercontent.com/bcurran3/ChocolateyPackages/master/chocolatey-preinstaller-checks.extension_icon.png + public domain + https://wiki.creativecommons.org/wiki/Public_domain + false + https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension + https://github.com/bcurran3/ChocolateyPackages/issues + bcurran3 unofficial choco preinstaller checks extension + Chocolatey Preinstaller Checks Extension is a collection of installer add-ons. + + +#PRERELEASE - TESTING AND FEEDBACK IS HIGHLY ENCOURAGED! +#KNOWN BUG - DOESN'T WORK WITH AUTO UNINSTALLER (YET!) + +##**Chocolatey Preinstaller Checks Extension** is a Chocolatey extension that intercepts and runs checks before installing or uninstalling a program. This extension will start working automatically once installed and does NOT need to be implemented by package creators/maintainers. #**Chocolatey Preinstaller Checks Extension** is meant to be installed and thus used directly by Chocolatey end users. + +###PURPOSE: +**Chocolatey Preinstaller Checks Extension**'s main purpose to fend off specific types of problems before they occur. Currently Chocolatey (choco.exe) is not multi-instance friendly. If you try to install packages using choco install or cinst in two Command Prompts at the same time, strange things may occur. **Chocolatey Preinstaller Checks Extension** avoids these strange things by intercepting calls to install programs and making choco.exe wait for previous instances to finish. **Chocolatey Preinstaller Checks Extension** also checks Windows Installer to see if it's busy and will make MSI installer programs wait until Windows Installer has finished processing the other program. **Chocolatey Preinstaller Checks Extension** will pause and retry until [commandExecutionTimeoutSeconds](https://chocolatey.org/docs/chocolatey-configuration) hits it's threshold of 2700 seconds/45 minutes (default) and then choco will abort. **Chocolatey Preinstaller Checks Extension** only runs before program installations. It does not perform any functions related to portable packages or other choco commands. + +###FEATURES: +* **Chocolatey Preinstaller Checks Extension** will check if there is a pending reboot and warn you about it if so. +* **Chocolatey Preinstaller Checks Extension** will check if there are instances of choco.exe already running and wait for them to finish. +* **Chocolatey Preinstaller Checks Extension** will check if Windows Installer is already running and wait for it to finish. + +**[PACKAGE NOTES](https://github.com/bcurran3/ChocolateyPackages/blob/master/chocolatey-preinstaller-checks.extension/readme.md)** + + + diff --git a/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_icon.png b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_icon.png new file mode 100644 index 000000000..ef1a37a81 Binary files /dev/null and b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_icon.png differ diff --git a/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_screenshot.png b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_screenshot.png new file mode 100644 index 000000000..f8b046f97 Binary files /dev/null and b/chocolatey-preinstaller-checks.extension/chocolatey-preinstaller-checks.extension_screenshot.png differ diff --git a/chocolatey-preinstaller-checks.extension/extensions/Chocolatey-Preinstaller-Checks.extension.psm1 b/chocolatey-preinstaller-checks.extension/extensions/Chocolatey-Preinstaller-Checks.extension.psm1 new file mode 100644 index 000000000..33dcb843c --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Chocolatey-Preinstaller-Checks.extension.psm1 @@ -0,0 +1,15 @@ +$scriptRoot = Split-Path -Path $MyInvocation.MyCommand.Definition + +$publicFunctions = @( + 'Get-chocoStatus', + 'Get-PendingRebootStatus', + 'Get-WindowsInstallerStatus', + 'Start-PreinstallChecks', + 'Start-PreuninstallChecks' +) + +Get-ChildItem -Path "$scriptRoot\*.ps1" | ForEach-Object { . $_ } +Export-ModuleMember -Function $publicFunctions + +Set-Alias Install-ChocolateyInstallPackage Start-PreinstallChecks -Force -Scope Global +Set-Alias Uninstall-ChocolateyPackage Start-PreuninstallChecks -Force -Scope Global \ No newline at end of file diff --git a/chocolatey-preinstaller-checks.extension/extensions/Get-PendingRebootStatus.ps1 b/chocolatey-preinstaller-checks.extension/extensions/Get-PendingRebootStatus.ps1 new file mode 100644 index 000000000..3476d7a7d --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Get-PendingRebootStatus.ps1 @@ -0,0 +1,15 @@ +function Get-PendingRebootStatus{ +# thanks http://ilovepowershell.com/2015/09/10/how-to-check-if-a-server-needs-a-reboot/ +if (Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction SilentlyContinue) { return $true } +if (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue) { return $true } +if (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue) { return $true } + try { + $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities" + $status = $util.DetermineIfRebootPending() + if(($status -ne $null) -and $status.RebootPending){ + return $true + } + }catch{} + + return $false +} \ No newline at end of file diff --git a/chocolatey-preinstaller-checks.extension/extensions/Get-WindowsInstallerStatus.ps1 b/chocolatey-preinstaller-checks.extension/extensions/Get-WindowsInstallerStatus.ps1 new file mode 100644 index 000000000..8dfcbe9fb --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Get-WindowsInstallerStatus.ps1 @@ -0,0 +1,16 @@ +function Get-WindowsInstallerStatus{ +$msiexecInstances = @(Get-Process -ea silentlycontinue msiexec).count +# From my observations, msiexec sticks around after a .msi is run. Running a .msi causes 2-3 occurrences of msiexec. + +if ($msiexecInstances -gt 1) + { + while ($msiexecInstances -gt 1) + { + Write-Host " ** WARNING: Windows Installer IS currently running. Pausing 30 seconds..." -foreground red + Start-Sleep -seconds 30 + $msiexecInstances = @(Get-Process -ea silentlycontinue msiexec).count + } + } +Write-Host " ** Windows Installer IS NOT currently running" -foreground green +} + diff --git a/chocolatey-preinstaller-checks.extension/extensions/Get-chocoStatus.ps1 b/chocolatey-preinstaller-checks.extension/extensions/Get-chocoStatus.ps1 new file mode 100644 index 000000000..e8c9d9ed3 --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Get-chocoStatus.ps1 @@ -0,0 +1,19 @@ +function Get-chocoStatus($AllowedChocos){ +$chocoInstances = @(Get-Process -ea silentlycontinue choco).count +# running choco got you here and is one instance! +# install causes one instance +# uninstall seems to always cause two instances + +if ($chocoInstances -gt $AllowedChocos) + { + while ($chocoInstances -gt $AllowedChocos) + { + Write-Host " ** WARNING: Found multiple instances of choco.exe running. Pausing 30 seconds..." -foreground red + Start-Sleep -seconds 30 + $chocoInstances = @(Get-Process -ea silentlycontinue choco).count + } + } +Write-Host " ** choco.exe IS NOT running multiple instances." -foreground green +} + + diff --git a/chocolatey-preinstaller-checks.extension/extensions/Start-PreinstallChecks.ps1 b/chocolatey-preinstaller-checks.extension/extensions/Start-PreinstallChecks.ps1 new file mode 100644 index 000000000..87bc4ab3d --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Start-PreinstallChecks.ps1 @@ -0,0 +1,14 @@ +function Start-PreInstallChecks{ + +Write-Host "PRE-INSTALLATION CHECKS:" -foreground magenta +if (Get-PendingRebootStatus) + { + Write-Host " ** WARNING: Pending reboot found." -foreground red + } else { + Write-Host " ** Pending reboot NOT found." -foreground green + } +Get-WindowsInstallerStatus +Get-chocoStatus 1 +Remove-Item alias:\Install-ChocolateyInstallPackage +Install-ChocolateyInstallPackage @args +} diff --git a/chocolatey-preinstaller-checks.extension/extensions/Start-PreuninstallChecks.ps1 b/chocolatey-preinstaller-checks.extension/extensions/Start-PreuninstallChecks.ps1 new file mode 100644 index 000000000..898b51763 --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/extensions/Start-PreuninstallChecks.ps1 @@ -0,0 +1,14 @@ +function Start-PreuninstallChecks{ + +Write-Host "PRE-UNINSTALLATION CHECKS:" -foreground magenta +if (Get-PendingRebootStatus) + { + Write-Host " ** WARNING: Pending reboot found." -foreground red + } else { + Write-Host " ** Pending reboot NOT found." -foreground green + } +Get-WindowsInstallerStatus +Get-chocoStatus 2 +Remove-Item alias:\Uninstall-ChocolateyPackage +Uninstall-ChocolateyPackage @args +} diff --git a/chocolatey-preinstaller-checks.extension/localtest.bat b/chocolatey-preinstaller-checks.extension/localtest.bat new file mode 100644 index 000000000..81909d528 --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/localtest.bat @@ -0,0 +1,4 @@ +@echo off +choco uninstall chocolatey-preinstaller-checks.extension +cpack +cinst chocolatey-preinstaller-checks.extension.0.0.1-pre.nupkg diff --git a/chocolatey-preinstaller-checks.extension/readme.md b/chocolatey-preinstaller-checks.extension/readme.md new file mode 100644 index 000000000..89a8a08f1 --- /dev/null +++ b/chocolatey-preinstaller-checks.extension/readme.md @@ -0,0 +1,23 @@ +**BCURRAN3'S PACKAGE NOTES:** + +* A BCURRAN3 original! +* I personally use and endorse this extension. + +CHANGE LOG: +0.0.1 - initial release + +ROADMAP: + + +Like my [packages](https://chocolatey.org/profiles/bcurran3)? + +Find them useful? + +**Want to buy me a beer?** + +https://www.paypal.me/bcurran3donations + +If applicable, please always consider donating to the developer or purchasing the software first - this includes Chocolatey licensed editions. + + +