packages/chocolatey/tools/chocolateyinstall.ps1 164 lines View on github.com → Search inside
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+".~" $f45# 1. See the _TODO.md that is generated top level and read through that6# 2. Follow the documentation below to learn how to create a package for the package type you are creating.7# 3. In Chocolatey scripts, ALWAYS use absolute paths - $toolsDir gets you to the package's tools directory.8$ErrorActionPreference = 'Stop'; # stop on all errors9#Items that could be replaced based on what you call chocopkgup.exe with10#{{PackageName}} - Package Name (should be same as nuspec file and folder) |/p11#{{PackageVersion}} - The updated version | /v12#{{DownloadUrl}} - The url for the native file | /u13#{{PackageFilePath}} - Downloaded file if including it in package | /pp14#{{PackageGuid}} - This will be used later | /pg15#{{DownloadUrlx64}} - The 64-bit url for the native file | /u6416#{{Checksum}} - The checksum for the url | /c17#{{Checksumx64}} - The checksum for the 64-bit url | /c6418#{{ChecksumType}} - The checksum type for the url | /ct19#{{ChecksumTypex64}} - The checksum type for the 64-bit url | /ct642021$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"22# Internal packages (organizations) or software that has redistribution rights (community repo)23# - Use `Install-ChocolateyInstallPackage` instead of `Install-ChocolateyPackage`24#   and put the binaries directly into the tools folder (we call it embedding)25#$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE'26# If embedding binaries increase total nupkg size to over 1GB, use share location or download from urls27#$fileLocation = '\\SHARE_LOCATION\to\INSTALLER_FILE'28# Community Repo: Use official urls for non-redist binaries or redist where total package size is over 200MB29# Internal/Organization: Download from internal location (internet sources are unreliable)30$url        = '{{DownloadUrl}}' # download url, HTTPS preferred31$url64      = '{{DownloadUrlx64}}' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url3233$packageArgs = @{34  packageName   = $env:ChocolateyPackageName35  unzipLocation = $toolsDir36  fileType      = 'exe' #only one of these: exe, msi, msu37  url           = $url38  url64bit      = $url6439  #file         = $fileLocation4041  softwareName  = 'scc*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique4243  # Checksums are now required as of 0.10.0.44  # To determine checksums, you can get that from the original site if provided. 45  # You can also use checksum.exe (choco install checksum) and use it 46  # e.g. checksum -t sha256 -f path\to\file47  checksum      = '{{Checksum}}'48  checksumType  = '{{ChecksumType}}' #default is md5, can also be sha1, sha256 or sha51249  checksum64    = '{{Checksumx64}}'50  checksumType64= '{{ChecksumTypex64}}' #default is checksumType5152  # MSI53  silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=054  validExitCodes= @(0, 3010, 1641)55  # OTHERS56  # Uncomment matching EXE type (sorted by most to least common)57  #silentArgs   = '/S'           # NSIS58  #silentArgs   = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup59  #silentArgs   = '/s'           # InstallShield60  #silentArgs   = '/s /v"/qn"'   # InstallShield with MSI61  #silentArgs   = '/s'           # Wise InstallMaster62  #silentArgs   = '-s'           # Squirrel63  #silentArgs   = '-q'           # Install4j64  #silentArgs   = '-s'           # Ghost65  # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.66  #silentArgs   = ''             # none; make silent with input macro script like AutoHotKey (AHK)67                                 #       https://chocolatey.org/packages/autohotkey.portable68  #validExitCodes= @(0) #please insert other valid exit codes here69}7071Install-ChocolateyPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-package72#Install-ChocolateyZipPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-zip-package73## If you are making your own internal packages (organizations), you can embed the installer or 74## put on internal file share and use the following instead (you'll need to add $file to the above)75#Install-ChocolateyInstallPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-install-package7677## Main helper functions - these have error handling tucked into them already78## see https://chocolatey.org/docs/helpers-reference7980## Install an application, will assert administrative rights81## - https://chocolatey.org/docs/helpers-install-chocolatey-package82## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package83## add additional optional arguments as necessary84##Install-ChocolateyPackage $packageName $fileType $silentArgs $url [$url64 -validExitCodes $validExitCodes -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64]8586## Download and unpack a zip file - https://chocolatey.org/docs/helpers-install-chocolatey-zip-package87##Install-ChocolateyZipPackage $packageName $url $toolsDir [$url64 -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64]8889## Install Visual Studio Package - https://chocolatey.org/docs/helpers-install-chocolatey-vsix-package90#Install-ChocolateyVsixPackage $packageName $url [$vsVersion] [-checksum $checksum -checksumType $checksumType]91#Install-ChocolateyVsixPackage @packageArgs9293## see the full list at https://chocolatey.org/docs/helpers-reference9495## downloader that the main helpers use to download items96## if removing $url64, please remove from here97## - https://chocolatey.org/docs/helpers-get-chocolatey-web-file98#Get-ChocolateyWebFile $packageName 'DOWNLOAD_TO_FILE_FULL_PATH' $url $url6499100## Installer, will assert administrative rights - used by Install-ChocolateyPackage101## use this for embedding installers in the package when not going to community feed or when you have distribution rights102## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package103#Install-ChocolateyInstallPackage $packageName $fileType $silentArgs '_FULLFILEPATH_' -validExitCodes $validExitCodes104105## Unzips a file to the specified location - auto overwrites existing content106## - https://chocolatey.org/docs/helpers-get-chocolatey-unzip107#Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" $toolsDir108109## Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage110## - https://chocolatey.org/docs/helpers-start-chocolatey-process-as-admin111#Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes112113## To avoid quoting issues, you can also assemble your -Statements in another variable and pass it in114#$appPath = "$env:ProgramFiles\appname"115##Will resolve to C:\Program Files\appname116#$statementsToRun = "/C `"$appPath\bin\installservice.bat`""117#Start-ChocolateyProcessAsAdmin $statementsToRun cmd -validExitCodes $validExitCodes118    119## add specific folders to the path - any executables found in the chocolatey package 120## folder will already be on the path. This is used in addition to that or for cases 121## when a native installer doesn't add things to the path.122## - https://chocolatey.org/docs/helpers-install-chocolatey-path123#Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights124125## Add specific files as shortcuts to the desktop126## - https://chocolatey.org/docs/helpers-install-chocolatey-shortcut127#$target = Join-Path $toolsDir "$($packageName).exe"128# Install-ChocolateyShortcut -shortcutFilePath "<path>" -targetPath "<path>" [-workDirectory "C:\" -arguments "C:\test.txt" -iconLocation "C:\test.ico" -description "This is the description"]129130## Outputs the bitness of the OS (either "32" or "64")131## - https://chocolatey.org/docs/helpers-get-o-s-architecture-width132#$osBitness = Get-ProcessorBits133134## Set persistent Environment variables135## - https://chocolatey.org/docs/helpers-install-chocolatey-environment-variable136#Install-ChocolateyEnvironmentVariable -variableName "SOMEVAR" -variableValue "value" [-variableType = 'Machine' #Defaults to 'User']137138## Set up a file association139## - https://chocolatey.org/docs/helpers-install-chocolatey-file-association140#Install-ChocolateyFileAssociation 141142## Adding a shim when not automatically found - Cocolatey automatically shims exe files found in package directory.143## - https://chocolatey.org/docs/helpers-install-bin-file144## - https://chocolatey.org/docs/create-packages#how-do-i-exclude-executables-from-getting-shims145#Install-BinFile146147##PORTABLE EXAMPLE148#$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"149# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives150#Install-ChocolateyZipPackage $packageName $url $toolsDir $url64151## END PORTABLE EXAMPLE152153## [DEPRECATING] PORTABLE EXAMPLE154#$binRoot = Get-BinRoot155#$installDir = Join-Path $binRoot "$packageName"156#Write-Host "Adding `'$installDir`' to the path and the current shell path"157#Install-ChocolateyPath "$installDir"158#$env:Path = "$($env:Path);$installDir"159160# if removing $url64, please remove from here161# despite the name "Install-ChocolateyZipPackage" this also works with 7z archives162#Install-ChocolateyZipPackage "$packageName" "$url" "$installDir" "$url64"163## END PORTABLE EXAMPLE

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.