Skip to content

Commit 04bcd3d

Browse files
committed
chocolatey package started
1 parent e87a91e commit 04bcd3d

File tree

7 files changed

+422
-0
lines changed

7 files changed

+422
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Summary
2+
How do I create packages? See https://chocolatey.org/docs/create-packages
3+
4+
If you are submitting packages to the community feed (https://chocolatey.org)
5+
always try to ensure you have read, understood and adhere to the create
6+
packages wiki link above.
7+
8+
## Automatic Packaging Updates?
9+
Consider making this package an automatic package, for the best
10+
maintainability over time. Read up at https://chocolatey.org/docs/automatic-packages
11+
12+
## Shim Generation
13+
Any executables you include in the package or download (but don't call
14+
install against using the built-in functions) will be automatically shimmed.
15+
16+
This means those executables will automatically be included on the path.
17+
Shim generation runs whether the package is self-contained or uses automation
18+
scripts.
19+
20+
By default, these are considered console applications.
21+
22+
If the application is a GUI, you should create an empty file next to the exe
23+
named 'name.exe.gui' e.g. 'bob.exe' would need a file named 'bob.exe.gui'.
24+
See https://chocolatey.org/docs/create-packages#how-do-i-set-up-shims-for-applications-that-have-a-gui
25+
26+
If you want to ignore the executable, create an empty file next to the exe
27+
named 'name.exe.ignore' e.g. 'bob.exe' would need a file named
28+
'bob.exe.ignore'.
29+
See https://chocolatey.org/docs/create-packages#how-do-i-exclude-executables-from-getting-shims
30+
31+
## Self-Contained?
32+
If you have a self-contained package, you can remove the automation scripts
33+
entirely and just include the executables, they will automatically get shimmed,
34+
which puts them on the path. Ensure you have the legal right to distribute
35+
the application though. See https://chocolatey.org/docs/legal.
36+
37+
You should read up on the Shim Generation section to familiarize yourself
38+
on what to do with GUI applications and/or ignoring shims.
39+
40+
## Automation Scripts
41+
You have a powerful use of Chocolatey, as you are using PowerShell. So you
42+
can do just about anything you need. Choco has some very handy built-in
43+
functions that you can use, these are sometimes called the helpers.
44+
45+
### Built-In Functions
46+
https://chocolatey.org/docs/helpers-reference
47+
48+
A note about a couple:
49+
* Get-BinRoot - this is a horribly named function that doesn't do what new folks think it does. It gets you the 'tools' root, which by default is set to 'c:\tools', not the chocolateyInstall bin folder - see https://chocolatey.org/docs/helpers-get-tools-location
50+
* Install-BinFile - used for non-exe files - executables are automatically shimmed... - see https://chocolatey.org/docs/helpers-install-bin-file
51+
* Uninstall-BinFile - used for non-exe files - executables are automatically shimmed - see https://chocolatey.org/docs/helpers-uninstall-bin-file
52+
53+
### Getting package specific information
54+
Use the package parameters pattern - see https://chocolatey.org/docs/how-to-parse-package-parameters-argument
55+
56+
### Need to mount an ISO?
57+
https://chocolatey.org/docs/how-to-mount-an-iso-in-chocolatey-package
58+
59+
60+
### Environment Variables
61+
Chocolatey makes a number of environment variables available (You can access any of these with $env:TheVariableNameBelow):
62+
63+
* TEMP = Overridden to the CacheLocation, but may be the same as the original TEMP folder
64+
* ChocolateyInstall = Top level folder where Chocolatey is installed
65+
* chocolateyPackageName = The name of the package, equivalent to the id in the nuspec (0.9.9+)
66+
* chocolateyPackageVersion = The version of the package, equivalent to the version in the nuspec (0.9.9+)
67+
* chocolateyPackageFolder = The top level location of the package folder
68+
69+
#### Advanced Environment Variables
70+
The following are more advanced settings:
71+
72+
* chocolateyPackageParameters = (0.9.8.22+)
73+
* CHOCOLATEY_VERSION = The version of Choco you normally see. Use if you are 'lighting' things up based on choco version. (0.9.9+)
74+
- Otherwise take a dependency on the specific version you need.
75+
* chocolateyForceX86 = If available and set to 'true', then user has requested 32bit version. (0.9.9+)
76+
- Automatically handled in built in Choco functions.
77+
* OS_PLATFORM = Like Windows, OSX, Linux. (0.9.9+)
78+
* OS_VERSION = The version of OS, like 6.1 something something for Windows. (0.9.9+)
79+
* OS_NAME = The reported name of the OS. (0.9.9+)
80+
* IS_PROCESSELEVATED = Is the process elevated? (0.9.9+)
81+
82+
#### Experimental Environment Variables
83+
The following are experimental or use not recommended:
84+
85+
* OS_IS64BIT = This may not return correctly - it may depend on the process the app is running under (0.9.9+)
86+
* CHOCOLATEY_VERSION_PRODUCT = the version of Choco that may match CHOCOLATEY_VERSION but may be different (0.9.9+)
87+
- it's based on git describe
88+
* IS_ADMIN = Is the user an administrator? But doesn't tell you if the process is elevated. (0.9.9+)
89+
* chocolateyInstallOverride = Not for use in package automation scripts. (0.9.9+)
90+
* chocolateyInstallArguments = the installer arguments meant for the native installer. You should use chocolateyPackageParameters intead. (0.9.9+)
91+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
Note: Include this file if including binaries you have the right to distribute.
3+
Otherwise delete. this file.
4+
5+
===DELETE ABOVE THIS LINE AND THIS LINE===
6+
7+
From: <insert applicable license url here>
8+
9+
LICENSE
10+
11+
<Insert License Here>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
Note: Include this file if including binaries you have the right to distribute.
3+
Otherwise delete. this file.
4+
5+
===DELETE ABOVE THIS LINE AND THIS LINE===
6+
7+
VERIFICATION
8+
Verification is intended to assist the Chocolatey moderators and community
9+
in verifying that this package's contents are trustworthy.
10+
11+
<Include details of how to verify checksum contents>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This runs in 0.9.10+ before upgrade and uninstall.
2+
# Use this file to do things like stop services prior to upgrade or uninstall.
3+
# NOTE: It is an anti-pattern to call chocolateyUninstall.ps1 from here. If you
4+
# need to uninstall an MSI prior to upgrade, put the functionality in this
5+
# file without calling the uninstall script. Make it idempotent in the
6+
# uninstall script so that it doesn't fail when it is already uninstalled.
7+
# NOTE: For upgrades - like the uninstall script, this script always runs from
8+
# the currently installed version, not from the new upgraded package version.
9+
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
2+
# $f='c:\path\to\thisFile.ps1'
3+
# gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f
4+
5+
$ErrorActionPreference = 'Stop'; # stop on all errors
6+
7+
$packageName= 'usecasemaker' # arbitrary name for the package, used in messages
8+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
9+
$url = 'https://github.com/hsharpsoftware/use-case-maker/releases/download/v2.0.0.3/setup.exe' # download url, HTTPS preferred
10+
$url64 = 'https://github.com/hsharpsoftware/use-case-maker/releases/download/v2.0.0.3/setup.exe' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url
11+
#$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE'
12+
#$fileLocation = '\\SHARE_LOCATION\to\INSTALLER_FILE'
13+
14+
$packageArgs = @{
15+
packageName = $packageName
16+
unzipLocation = $toolsDir
17+
fileType = 'exe' #only one of these: exe, msi, msu
18+
url = $url
19+
url64bit = $url64
20+
#file = $fileLocation
21+
22+
softwareName = 'Use Case Maker' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
23+
24+
# Checksums are now required as of 0.10.0.
25+
# To determine checksums, you can get that from the original site if provided.
26+
# You can also use checksum.exe (choco install checksum) and use it
27+
# e.g. checksum -t sha256 -f path\to\file
28+
checksum = '2B58142B9D3D87C41AE8178CBF5280070368D1D06D8D3BE9D833D2E8273B1A80'
29+
checksumType = 'sha256' #default is md5, can also be sha1, sha256 or sha512
30+
checksum64 = '2B58142B9D3D87C41AE8178CBF5280070368D1D06D8D3BE9D833D2E8273B1A80'
31+
checksumType64= 'sha256' #default is checksumType
32+
33+
#MSI
34+
#silentArgs = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0
35+
validExitCodes= @(0, 3010, 1641)
36+
#OTHERS
37+
# Uncomment matching EXE type (sorted by most to least common)
38+
#silentArgs = '/S' # NSIS
39+
#silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup
40+
#silentArgs = '/s' # InstallShield
41+
#silentArgs = '/s /v"/qn"' # InstallShield with MSI
42+
#silentArgs = '/s' # Wise InstallMaster
43+
#silentArgs = '-s' # Squirrel
44+
#silentArgs = '-q' # Install4j
45+
#silentArgs = '-s -u' # Ghost
46+
# Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.
47+
#silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK)
48+
# https://chocolatey.org/packages/autohotkey.portable
49+
#validExitCodes= @(0) #please insert other valid exit codes here
50+
}
51+
52+
Install-ChocolateyPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-package
53+
#Install-ChocolateyZipPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-zip-package
54+
## If you are making your own internal packages (organizations), you can embed the installer or
55+
## put on internal file share and use the following instead (you'll need to add $file to the above)
56+
#Install-ChocolateyInstallPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-install-package
57+
58+
## Main helper functions - these have error handling tucked into them already
59+
## see https://chocolatey.org/docs/helpers-reference
60+
61+
## Install an application, will assert administrative rights
62+
## - https://chocolatey.org/docs/helpers-install-chocolatey-package
63+
## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package
64+
## add additional optional arguments as necessary
65+
##Install-ChocolateyPackage $packageName $fileType $silentArgs $url [$url64 -validExitCodes $validExitCodes -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64]
66+
67+
## Download and unpack a zip file - https://chocolatey.org/docs/helpers-install-chocolatey-zip-package
68+
##Install-ChocolateyZipPackage $packageName $url $toolsDir [$url64 -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64]
69+
70+
## Install Visual Studio Package - https://chocolatey.org/docs/helpers-install-chocolatey-vsix-package
71+
#Install-ChocolateyVsixPackage $packageName $url [$vsVersion] [-checksum $checksum -checksumType $checksumType]
72+
#Install-ChocolateyVsixPackage @packageArgs
73+
74+
## see the full list at https://chocolatey.org/docs/helpers-reference
75+
76+
## downloader that the main helpers use to download items
77+
## if removing $url64, please remove from here
78+
## - https://chocolatey.org/docs/helpers-get-chocolatey-web-file
79+
#Get-ChocolateyWebFile $packageName 'DOWNLOAD_TO_FILE_FULL_PATH' $url $url64
80+
81+
## Installer, will assert administrative rights - used by Install-ChocolateyPackage
82+
## use this for embedding installers in the package when not going to community feed or when you have distribution rights
83+
## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package
84+
#Install-ChocolateyInstallPackage $packageName $fileType $silentArgs '_FULLFILEPATH_' -validExitCodes $validExitCodes
85+
86+
## Unzips a file to the specified location - auto overwrites existing content
87+
## - https://chocolatey.org/docs/helpers-get-chocolatey-unzip
88+
#Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" $toolsDir
89+
90+
## Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage
91+
## - https://chocolatey.org/docs/helpers-start-chocolatey-process-as-admin
92+
#Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes
93+
94+
## add specific folders to the path - any executables found in the chocolatey package
95+
## folder will already be on the path. This is used in addition to that or for cases
96+
## when a native installer doesn't add things to the path.
97+
## - https://chocolatey.org/docs/helpers-install-chocolatey-path
98+
#Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights
99+
100+
## Add specific files as shortcuts to the desktop
101+
## - https://chocolatey.org/docs/helpers-install-chocolatey-shortcut
102+
#$target = Join-Path $toolsDir "$($packageName).exe"
103+
# Install-ChocolateyShortcut -shortcutFilePath "<path>" -targetPath "<path>" [-workDirectory "C:\" -arguments "C:\test.txt" -iconLocation "C:\test.ico" -description "This is the description"]
104+
105+
## Outputs the bitness of the OS (either "32" or "64")
106+
## - https://chocolatey.org/docs/helpers-get-o-s-architecture-width
107+
#$osBitness = Get-ProcessorBits
108+
109+
## Set persistent Environment variables
110+
## - https://chocolatey.org/docs/helpers-install-chocolatey-environment-variable
111+
#Install-ChocolateyEnvironmentVariable -variableName "SOMEVAR" -variableValue "value" [-variableType = 'Machine' #Defaults to 'User']
112+
113+
## Set up a file association
114+
## - https://chocolatey.org/docs/helpers-install-chocolatey-file-association
115+
#Install-ChocolateyFileAssociation
116+
117+
## Adding a shim when not automatically found - Cocolatey automatically shims exe files found in package directory.
118+
## - https://chocolatey.org/docs/helpers-install-bin-file
119+
## - https://chocolatey.org/docs/create-packages#how-do-i-exclude-executables-from-getting-shims
120+
#Install-BinFile
121+
122+
##PORTABLE EXAMPLE
123+
#$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
124+
# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives
125+
#Install-ChocolateyZipPackage $packageName $url $toolsDir $url64
126+
## END PORTABLE EXAMPLE
127+
128+
## [DEPRECATING] PORTABLE EXAMPLE
129+
#$binRoot = Get-BinRoot
130+
#$installDir = Join-Path $binRoot "$packageName"
131+
#Write-Host "Adding `'$installDir`' to the path and the current shell path"
132+
#Install-ChocolateyPath "$installDir"
133+
#$env:Path = "$($env:Path);$installDir"
134+
135+
# if removing $url64, please remove from here
136+
# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives
137+
#Install-ChocolateyZipPackage "$packageName" "$url" "$installDir" "$url64"
138+
## END PORTABLE EXAMPLE
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# IMPORTANT: Before releasing this package, copy/paste the next 2 lines into PowerShell to remove all comments from this file:
2+
# $f='c:\path\to\thisFile.ps1'
3+
# gc $f | ? {$_ -notmatch "^\s*#"} | % {$_ -replace '(^.*?)\s*?[^``]#.*','$1'} | Out-File $f+".~" -en utf8; mv -fo $f+".~" $f
4+
5+
## NOTE: In 80-90% of the cases (95% with licensed versions due to Package Synchronizer and other enhancements), you may
6+
## not need this file due to AutoUninstaller. See https://chocolatey.org/docs/commands-uninstall
7+
8+
## If this is an MSI, cleaning up comments is all you need.
9+
## If this is an exe, change installerType and silentArgs
10+
## Auto Uninstaller should be able to detect and handle registry uninstalls (if it is turned on, it is in preview for 0.9.9).
11+
## - https://chocolatey.org/docs/helpers-uninstall-chocolatey-package
12+
13+
$ErrorActionPreference = 'Stop'; # stop on all errors
14+
15+
$packageName = 'usecasemaker'
16+
$softwareName = 'usecasemaker*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
17+
$installerType = 'MSI'
18+
#$installerType = 'EXE'
19+
20+
$silentArgs = '/qn /norestart'
21+
# https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx
22+
$validExitCodes = @(0, 3010, 1605, 1614, 1641)
23+
if ($installerType -ne 'MSI') {
24+
# The below is somewhat naive and built for EXE installers
25+
# Uncomment matching EXE type (sorted by most to least common)
26+
#$silentArgs = '/S' # NSIS
27+
#$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup
28+
#$silentArgs = '/s' # InstallShield
29+
#$silentArgs = '/s /v"/qn"' # InstallShield with MSI
30+
#$silentArgs = '/s' # Wise InstallMaster
31+
#$silentArgs = '-s' # Squirrel
32+
#$silentArgs = '-q' # Install4j
33+
#$silentArgs = '-s -u' # Ghost
34+
# Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.
35+
#$silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK)
36+
# https://chocolatey.org/packages/autohotkey.portable
37+
$validExitCodes = @(0)
38+
}
39+
40+
$uninstalled = $false
41+
# Get-UninstallRegistryKey is new to 0.9.10, if supporting 0.9.9.x and below,
42+
# take a dependency on "chocolatey-uninstall.extension" in your nuspec file.
43+
# This is only a fuzzy search if $softwareName includes '*'. Otherwise it is
44+
# exact. In the case of versions in key names, we recommend removing the version
45+
# and using '*'.
46+
[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName
47+
48+
if ($key.Count -eq 1) {
49+
$key | % {
50+
$file = "$($_.UninstallString)"
51+
52+
if ($installerType -eq 'MSI') {
53+
# The Product Code GUID is all that should be passed for MSI, and very
54+
# FIRST, because it comes directly after /x, which is already set in the
55+
# Uninstall-ChocolateyPackage msiargs (facepalm).
56+
$silentArgs = "$($_.PSChildName) $silentArgs"
57+
58+
# Don't pass anything for file, it is ignored for msi (facepalm number 2)
59+
# Alternatively if you need to pass a path to an msi, determine that and
60+
# use it instead of the above in silentArgs, still very first
61+
$file = ''
62+
}
63+
64+
Uninstall-ChocolateyPackage -PackageName $packageName `
65+
-FileType $installerType `
66+
-SilentArgs "$silentArgs" `
67+
-ValidExitCodes $validExitCodes `
68+
-File "$file"
69+
}
70+
} elseif ($key.Count -eq 0) {
71+
Write-Warning "$packageName has already been uninstalled by other means."
72+
} elseif ($key.Count -gt 1) {
73+
Write-Warning "$key.Count matches found!"
74+
Write-Warning "To prevent accidental data loss, no programs will be uninstalled."
75+
Write-Warning "Please alert package maintainer the following keys were matched:"
76+
$key | % {Write-Warning "- $_.DisplayName"}
77+
}
78+
79+
80+
## OTHER HELPERS
81+
## https://chocolatey.org/docs/helpers-reference
82+
#Uninstall-ChocolateyZipPackage $packageName # Only necessary if you did not unpack to package directory - see https://chocolatey.org/docs/helpers-uninstall-chocolatey-zip-package
83+
#Uninstall-ChocolateyEnvironmentVariable # 0.9.10+ - https://chocolatey.org/docs/helpers-uninstall-chocolatey-environment-variable
84+
#Uninstall-BinFile # Only needed if you used Install-BinFile - see https://chocolatey.org/docs/helpers-uninstall-bin-file
85+
## Remove any shortcuts you added
86+

0 commit comments

Comments
 (0)