Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bcurran3 authored May 24, 2018
1 parent 7bec37d commit 0b770e6
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>chocolatey-preinstaller-checks.extension</id>
<version>0.0.1-pre</version>
<owners>bcurran3</owners>
<packageSourceUrl>https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension</packageSourceUrl>
<title>Chocolatey Preinstaller Checks Extension</title>
<authors>Bill Curran</authors>
<projectUrl>https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension</projectUrl>
<iconUrl>https://raw.githubusercontent.com/bcurran3/ChocolateyPackages/master/chocolatey-preinstaller-checks.extension_icon.png</iconUrl>
<copyright>public domain</copyright>
<licenseUrl>https://wiki.creativecommons.org/wiki/Public_domain</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/bcurran3/ChocolateyPackages/tree/master/chocolatey-preinstaller-checks.extension</projectSourceUrl>
<bugTrackerUrl>https://github.com/bcurran3/ChocolateyPackages/issues</bugTrackerUrl>
<tags>bcurran3 unofficial choco preinstaller checks extension</tags>
<summary>Chocolatey Preinstaller Checks Extension is a collection of installer add-ons.</summary>
<description>

#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)**
</description>
</metadata>
</package>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
@@ -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
}


Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions chocolatey-preinstaller-checks.extension/localtest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
choco uninstall chocolatey-preinstaller-checks.extension
cpack
cinst chocolatey-preinstaller-checks.extension.0.0.1-pre.nupkg
23 changes: 23 additions & 0 deletions chocolatey-preinstaller-checks.extension/readme.md
Original file line number Diff line number Diff line change
@@ -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.



0 comments on commit 0b770e6

Please sign in to comment.