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

Add PSADT template #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/psadt-silent.template/psadt-silent.template.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>psadt-silent.template</id>
Copy link
Member

Choose a reason for hiding this comment

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

Since all Chocolatey packages should be silent, this could be simplified to psadt.template

<version>1.0.0</version>
<packageSourceUrl>https://github.com/chocolatey-community/chocolatey-templates/tree/main/src/psadt-silent.template</packageSourceUrl>
<owners>Stephen Valdinger, Chocolatey-Community</owners>
<title>PSADT Template</title>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<title>PSADT Template</title>
<title>PSAppDeployToolkit Template</title>

<authors>Stephen Valdinger, The Chocolatey Team,Chocolatey Community Team</authors>
<projectUrl>https://github.com/chocolatey-community/chocolatey-templates</projectUrl>
<!--<iconUrl>http://rawcdn.githack.com/__REPLACE_YOUR_REPO__/master/icons/psadt-silent.template.png</iconUrl>-->
<copyright>Chocolatey Community Team 2023-present</copyright>
<licenseUrl>https://raw.githubusercontent.com/chocolatey-community/chocolatey-templates/main/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/chocolatey-community/chocolatey-templates</projectSourceUrl>
<bugTrackerUrl>https://github.com/chocolatey-community/chocolatey-templates/issues</bugTrackerUrl>
<tags>psadt-silent.template SPACE_SEPARATED</tags>
<summary>PSADT Chocolatey Template</summary>
<description>### Chocolatey PSADT Template
This adds a template for PSADT applications

</description>
<releaseNotes>
### 1.0.0

initial
</releaseNotes>
</metadata>
<files>
<!-- this section controls what actually gets packaged into the Chocolatey package -->
<file src="templates\**" target="templates" />
</files>
</package>
22 changes: 22 additions & 0 deletions src/psadt-silent.template/templates/file.nuspec.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>[[PackageNameLower]]</id>
<version>[[PackageVersion]]</version>
<title>[[Software]] (Install)</title>
<authors>UpdateAuthorHere</authors>
<!-- copyright is usually years and software vendor, but not required for internal feeds -->
<copyright>2023 CompanyName</copyright>
<tags>[[Software]] psadt</tags>
<summary>Installs [[Software]] via PSADT interactively</summary>
<description>
Uses existing PSADT framework to install [[Software]] via Chocolatey
</description>
</metadata>
<!-- this section controls what actually gets packaged into the Chocolatey package -->
<files>
<file src="tools\**" target="tools" />
</files>
</package>
67 changes: 67 additions & 0 deletions src/psadt-silent.template/templates/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
$ErrorActionPreference = 'Stop' # stop on all errors
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$zipArchive = Join-Path $toolsDir -ChildPath '[[Zip]]'
$destination = (Join-Path $toolsDir -ChildPath $env:ChocolateyPackageName)

Get-ChocolateyUnzip -FileFullPath $zipArchive -Destination $destination
Copy link
Member

Choose a reason for hiding this comment

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

Since the zip archive is embedded, it is probably best to include the license and verification template files.


$adtFolder = 'AppDeployToolkit'
$modulePath = Join-Path $destination -ChildPath "$adtFolder"
$module = Join-Path $modulePath -ChildPath 'AppDeployToolkitMain.ps1'
. $module
$adtExe = Join-Path $destination -ChildPath "Deploy-Application.exe"
$deployScript = Join-Path $destination -ChildPath 'Deploy-Application.ps1'

try {
$packageArgs = @{
packagename = $env:ChocolateyPackageName
filetype = 'exe'
file = $adtExe
silentArgs = "-DeploymentType 'Install' -DeployMode 'Silent'"
validExitCodes = @(0)
softwareName = '[[Software]]*'
}

Install-ChocolateyInstallPackage @packageArgs
} catch {
$packageArgs = @{
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason this catch block is needed? It seems to be doing pretty much the same thing as the try block.

ExetoRun = $adtExe
statements = "-DeploymentType 'Install' -DeployMode 'Silent'"
}

Start-ChocolateyProcessAsAdmin @packageArgs
} finally {
$packageArgs = @{
statements = "& { & '$deployScript' -DeploymentType 'Install'}"
}

Start-ChocolateyProcessAsAdmin @packageArgs
}

<#
try {
$packageArgs = @{
ExetoRun = $adtExe
statements = "-DeploymentType 'Install' -DeployMode 'Silent'"
}

Start-ChocolateyProcessAsAdmin @packageArgs
}

catch {
$packageArgs = @{

statements = "& { & '$deployScript' -DeploymentType 'Install'}"
}

Start-ChocolateyProcessAsAdmin @packageArgs
}
#>

#Cleanup
Remove-Item $zipArchive

#Prevent shims
if(-not (Test-Path "$destination\*.ignore")){
Get-ChildItem $toolsDir -Recurse -Filter '*.exe' | Foreach-Object { $null = New-Item "$destination\$($_.Name).ignore" -ItemType File }
}
13 changes: 13 additions & 0 deletions src/psadt-silent.template/templates/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ErrorActionPreference = 'Stop' # stop on all errors
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$destination = (Join-Path $toolsDir -ChildPath $env:ChocolateyPackageName)


$adtExe = Join-Path $destination -ChildPath "Deploy-Application.exe"
Copy link
Member

Choose a reason for hiding this comment

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

Does this deploy-application.exe needed to be excluded from the package reducer?


$packageArgs = @{
ExetoRun = $adtExe
statements = "-DeploymentType 'Uninstall' -DeployMode 'Silent'"
}

Start-ChocolateyProcessAsAdmin @packageArgs
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest switching to Uninstall-ChocolateyPackage if possible, as that has support for valid exit codes.