diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs index 79f8f12c2b..4ea5182448 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs @@ -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 @@ -28,6 +29,8 @@ 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 @@ -35,12 +38,24 @@ public class ChocolateyInstallTemplate 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 @@ -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 diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs index 620b87fa44..f871d546ac 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyUninstallTemplate.cs @@ -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). @@ -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) } @@ -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""} }