Skip to content

Commit

Permalink
(GH-366) Further enhance package template
Browse files Browse the repository at this point in the history
This includes suggestions from @dtgm on even better ways to clean up
the install templates.
  • Loading branch information
ferventcoder committed Oct 2, 2015
1 parent f87bc08 commit 804458c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 33 deletions.
Expand Up @@ -18,8 +18,9 @@ namespace chocolatey.infrastructure.app.templates
public class ChocolateyInstallTemplate
{
public static string Template =
@"#NOTE: Please remove any commented lines to tidy up prior to releasing the package, including this one
# REMOVE ANYTHING BELOW THAT IS NOT NEEDED
@"# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
# $f='c:\path\to\thisFile.ps1'
# gc $f | ? {$_ -notmatch ""^\s*#""} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+"".~"" -en utf8; mv -fo $f+"".~"" $f
$ErrorActionPreference = 'Stop'; # stop on all errors
Expand All @@ -28,19 +29,33 @@ public class ChocolateyInstallTemplate
$toolsDir = ""$(Split-Path -parent $MyInvocation.MyCommand.Definition)""
$url = '[[Url]]' # download url
$url64 = '[[Url64]]' # 64bit URL here or remove - if installer is both, use $url
#$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE'
#$fileLocation = Join-Path $toolsDir 'SHARE_LOCATION_OF_INSTALLER_FILE'
$packageArgs = @{
packageName = $packageName
unzipLocation = $toolsDir
fileType = '[[InstallerType]]' #only one of these: exe, msi, msu
url = $url
url64bit = $url64
#file = $fileLocation
#MSI
silentArgs = ""/qn /norestart /l*v `""$env:TEMP\chocolatey\$($packageName)\$($packageName).MsiInstall.log`"""" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0
validExitCodes= @(0, 3010, 1641)
#OTHERS
#silentArgs ='[[SilentArgs]]' # /s /S /q /Q /quiet /silent /SILENT /VERYSILENT -s - try any of these to get the silent installer
# Uncomment matching EXE type (sorted by most to least common)
#silentArgs = '/S' # NSIS
#silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup
#silentArgs = '/s' # InstallShield
#silentArgs = '/s /v""/qn""' # InstallShield with MSI
#silentArgs = '/s' # Wise InstallMaster
#silentArgs = '-s' # Squirrel
#silentArgs = '-q' # Install4j
#silentArgs = '-s -u' # Ghost
# Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.
#silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK)
# https://chocolatey.org/packages/autohotkey.portable
#validExitCodes= @(0) #please insert other valid exit codes here
# optional, highly recommended
Expand All @@ -53,6 +68,9 @@ public class ChocolateyInstallTemplate
Install-ChocolateyPackage @packageArgs
#Install-ChocolateyZipPackage @packageArgs
# if you are making your own internal packages (organizations), you can embed the installer or
# put on internal file share and use the following instead (you'll need to add $file to the above)
#Install-ChocolateyInstallPackage @packageArgs
## Main helper functions - these have error handling tucked into them already
## see https://github.com/chocolatey/choco/wiki/HelpersReference
Expand Down
Expand Up @@ -18,8 +18,10 @@ namespace chocolatey.infrastructure.app.templates
public class ChocolateyUninstallTemplate
{
public static string Template =
@"#NOTE: Please remove any commented lines to tidy up prior to releasing the package, including this one
# REMOVE ANYTHING BELOW THAT IS NOT NEEDED
@"# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
# $f='c:\path\to\thisFile.ps1'
# gc $f | ? {$_ -notmatch ""^\s*#""} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+"".~"" -en utf8; mv -fo $f+"".~"" $f
# If this is an MSI, cleaning up comments is all you need.
# If this is an exe, change installerType and silentArgs
# Auto Uninstaller should be able to detect and handle registry uninstalls (if it is turned on, it is in preview for 0.9.9).
Expand All @@ -36,7 +38,18 @@ public class ChocolateyUninstallTemplate
$validExitCodes = @(0, 3010, 1605, 1614, 1641)
if ($installerType -ne 'MSI') {
# The below is somewhat naive and built for EXE installers
$silentArgs = '/S' # /s /S /q /Q /quiet /silent /SILENT /VERYSILENT -s - try any of these to get the silent installer
# Uncomment matching EXE type (sorted by most to least common)
#$silentArgs = '/S' # NSIS
#$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup
#$silentArgs = '/s' # InstallShield
#$silentArgs = '/s /v""/qn""' # InstallShield with MSI
#$silentArgs = '/s' # Wise InstallMaster
#$silentArgs = '-s' # Squirrel
#$silentArgs = '-q' # Install4j
#$silentArgs = '-s -u' # Ghost
# Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.
#$silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK)
# https://chocolatey.org/packages/autohotkey.portable
$validExitCodes = @(0)
}
Expand All @@ -45,35 +58,39 @@ public class ChocolateyUninstallTemplate
$machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
-ErrorAction SilentlyContinue `
| ? { $_.DisplayName -like ""$softwareName"" } `
| Select -First 1 `
| % {
$file = ""$($_.UninstallString)""
if ($installerType -eq 'MSI') {
# The Product Code GUID is all that should be passed for MSI, and very
# FIRST, because it comes directly after /x, which is already set in the
# Uninstall-ChocolateyPackage msiargs (facepalm).
$silentArgs = ""$($_.PSChildName) $silentArgs""
# Don't pass anything for file, it is ignored for msi (facepalm number 2)
# Alternatively if you need to pass a path to an msi, determine that and
# use it instead of the above in silentArgs, still very first
$file = ''
}
$key = Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
-ErrorAction SilentlyContinue `
| ? { $_.DisplayName -like ""$softwareName"" }
if ($key.Count -eq 1) {
$key | % {
$file = ""$($_.UninstallString)""
Uninstall-ChocolateyPackage -PackageName $packageName `
-FileType $installerType `
-SilentArgs ""$silentArgs"" `
-ValidExitCodes $validExitCodes `
-File ""$file""
$uninstalled = $true
}
if ($installerType -eq 'MSI') {
# The Product Code GUID is all that should be passed for MSI, and very
# FIRST, because it comes directly after /x, which is already set in the
# Uninstall-ChocolateyPackage msiargs (facepalm).
$silentArgs = ""$($_.PSChildName) $silentArgs""
# Don't pass anything for file, it is ignored for msi (facepalm number 2)
# Alternatively if you need to pass a path to an msi, determine that and
# use it instead of the above in silentArgs, still very first
$file = ''
}
if (!($uninstalled)) {
Write-Warning ""$packageName has already been uninstalled by other means.""
Uninstall-ChocolateyPackage -PackageName $packageName `
-FileType $installerType `
-SilentArgs ""$silentArgs"" `
-ValidExitCodes $validExitCodes `
-File ""$file""
}
} elseif ($key.Count -eq 0) {
Write-Warning ""$packageName has already been uninstalled by other means.""
} elseif ($key.Count -gt 1) {
Write-Warning ""$key.Count matches found!""
Write-Warning ""To prevent accidental data loss, no programs will be uninstalled.""
Write-Warning ""Please alert package maintainer the following keys were matched:""
$key | % {Write-Warning ""- $_.DisplayName""}
}
Expand Down

2 comments on commit 804458c

@dtgm
Copy link
Contributor

@dtgm dtgm commented on 804458c Oct 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ferventcoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.