├── .gitignore ├── Dockerfile ├── README.md ├── bin └── choco └── example ├── Dockerfile ├── README.md └── mypackage ├── ReadMe.md ├── _TODO.txt ├── mypackage.nuspec └── tools ├── LICENSE.txt ├── VERIFICATION.txt ├── chocolateybeforemodify.ps1 ├── chocolateyinstall.ps1 └── chocolateyuninstall.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | *.nupkg 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mono:6.12.0 2 | ARG CHOCOVERSION=stable 3 | 4 | # Make sure we have these tools 5 | RUN apt-get update && apt-get install -y wget tar gzip 6 | 7 | # Download, extract, and move chocolatey installer 8 | WORKDIR /usr/local/src 9 | RUN wget "https://github.com/chocolatey/choco/archive/${CHOCOVERSION}.tar.gz" && \ 10 | tar -xzf "${CHOCOVERSION}.tar.gz" && \ 11 | rm "${CHOCOVERSION}.tar.gz" && \ 12 | mv "choco-${CHOCOVERSION}" choco 13 | 14 | # Build chocolatey 15 | WORKDIR /usr/local/src/choco 16 | RUN chmod +x build.sh zip.sh 17 | RUN ./build.sh -v 18 | 19 | # Symlink the build output to our install directory 20 | RUN ln -s /usr/local/src/choco/code_drop/chocolatey /opt/chocolatey 21 | 22 | # Copy in the choco helper script 23 | COPY bin/choco /usr/bin/choco 24 | 25 | ENV ChocolateyInstall /opt/chocolatey 26 | 27 | ENTRYPOINT ["/usr/bin/choco"] 28 | CMD ["-h"] 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mono-choco 2 | 3 | [Latest Build Status](https://hub.docker.com/r/linuturk/mono-choco/builds) 4 | 5 | Docker image for creating a container with Chocolatey running on Mono 6 | 7 | ## Usage 8 | 9 | Test the image using `docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco` 10 | 11 | See [the example directory](./example/README.md) for a basic package example. 12 | 13 | ## FAQ 14 | 15 | 1. "Cannot create a package that has no dependencies nor content." 16 | 17 | The nuspec file most likely requires this for the files section: 18 | ```xml 19 | 20 | 21 | 22 | 23 | ``` 24 | Note the comment in the nuspec template that reads: 25 | 26 | ```xml 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /bin/choco: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Wrap the mono choco.exe command 5 | mono /opt/chocolatey/console/choco.exe "$@" --allow-unofficial -------------------------------------------------------------------------------- /example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM linuturk/mono-choco 2 | 3 | ENV PACKAGE=mypackage 4 | ENV VERSION=1.0.0 5 | 6 | WORKDIR /opt/choco 7 | 8 | # Copy our package files into the container 9 | COPY ${PACKAGE} /opt/choco 10 | 11 | # Check the files that were copied 12 | RUN ls -R /opt/choco 13 | 14 | # Check our version 15 | RUN choco --version 16 | 17 | # Pack the nupkg 18 | RUN choco pack -vd /opt/choco/${PACKAGE}.nuspec --outputdirectory /opt/choco 19 | 20 | # Example push command 21 | #RUN choco push -vd --timeout 30 /opt/choco/${PACKAGE}.${VERSION}.nupkg 22 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example Usage 2 | 3 | This directory contains an example package and Dockerfile. 4 | 5 | ## Generating a new package 6 | 7 | The **mypackage** directory was generated using the following command. Note you will need to fix the ownership of these files as they are generated as the root user inside the container. 8 | 9 | ```bash 10 | docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco new mypackage --version 1.0.0 --maintainer "Justin Phelps" 11 | ``` 12 | 13 | There are some modifications necessary to the generated nuspec file before it will generate a package. Check the file's git history to see those changes. 14 | 15 | ## Recommended packing method 16 | 17 | I recommend you use the Dockerfile example in this directory to pack your nuget packages. Doing everything from inside the Docker container is cleaner. If you would still like to run this with a volume mount, here is an example of that command: 18 | 19 | ```bash 20 | cd /path/to/mypackage 21 | docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco pack mypackage.nuspec 22 | Chocolatey v0.10.9.0 23 | Directory 'opt/chocolatey/lib' does not exist. 24 | 25 | Chocolatey is not an official build (bypassed with --allow-unofficial). 26 | If you are seeing this message and it is not expected, your system may 27 | now be in a bad state. Only official builds are to be trusted. 28 | 29 | Attempting to build package from 'mypackage.nuspec'. 30 | Successfully created package 'mono-choco/example/mypackage/mypackage.1.0.0.nupkg' 31 | ``` 32 | -------------------------------------------------------------------------------- /example/mypackage/ReadMe.md: -------------------------------------------------------------------------------- 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 | ### Environment Variables 60 | Chocolatey makes a number of environment variables available (You can access any of these with $env:TheVariableNameBelow): 61 | 62 | * TEMP/TMP - Overridden to the CacheLocation, but may be the same as the original TEMP folder 63 | * ChocolateyInstall - Top level folder where Chocolatey is installed 64 | * ChocolateyPackageName - The name of the package, equivalent to the `` field in the nuspec (0.9.9+) 65 | * ChocolateyPackageTitle - The title of the package, equivalent to the `` field in the nuspec (0.10.1+) 66 | * ChocolateyPackageVersion - The version of the package, equivalent to the `<version />` field in the nuspec (0.9.9+) 67 | * ChocolateyPackageFolder - The top level location of the package folder - the folder where Chocolatey has downloaded and extracted the NuGet package, typically `C:\ProgramData\chocolatey\lib\packageName`. 68 | 69 | #### Advanced Environment Variables 70 | The following are more advanced settings: 71 | 72 | * ChocolateyPackageParameters - Parameters to use with packaging, not the same as install arguments (which are passed directly to the native installer). Based on `--package-parameters`. (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+) - Otherwise take a dependency on the specific version you need. 74 | * ChocolateyForceX86 = If available and set to 'true', then user has requested 32bit version. (0.9.9+) - Automatically handled in built in Choco functions. 75 | * OS_PLATFORM - Like Windows, OSX, Linux. (0.9.9+) 76 | * OS_VERSION - The version of OS, like 6.1 something something for Windows. (0.9.9+) 77 | * OS_NAME - The reported name of the OS. (0.9.9+) 78 | * USER_NAME = The user name (0.10.6+) 79 | * USER_DOMAIN = The user domain name (could also be local computer name) (0.10.6+) 80 | * IS_PROCESSELEVATED = Is the process elevated? (0.9.9+) 81 | * IS_SYSTEM = Is the user the system account? (0.10.6+) 82 | * IS_REMOTEDESKTOP = Is the user in a terminal services session? (0.10.6+) 83 | * ChocolateyToolsLocation - formerly 'ChocolateyBinRoot' ('ChocolateyBinRoot' will be removed with Chocolatey v2.0.0), this is where tools being installed outside of Chocolatey packaging will go. (0.9.10+) 84 | 85 | #### Set By Options and Configuration 86 | Some environment variables are set based on options that are passed, configuration and/or features that are turned on: 87 | 88 | * ChocolateyEnvironmentDebug - Was `--debug` passed? If using the built-in PowerShell host, this is always true (but only logs debug messages to console if `--debug` was passed) (0.9.10+) 89 | * ChocolateyEnvironmentVerbose - Was `--verbose` passed? If using the built-in PowerShell host, this is always true (but only logs verbose messages to console if `--verbose` was passed). (0.9.10+) 90 | * ChocolateyForce - Was `--force` passed? (0.9.10+) 91 | * ChocolateyForceX86 - Was `-x86` passed? (CHECK) 92 | * ChocolateyRequestTimeout - How long before a web request will time out. Set by config `webRequestTimeoutSeconds` (CHECK) 93 | * ChocolateyResponseTimeout - How long to wait for a download to complete? Set by config `commandExecutionTimeoutSeconds` (CHECK) 94 | * ChocolateyPowerShellHost - Are we using the built-in PowerShell host? Set by `--use-system-powershell` or the feature `powershellHost` (0.9.10+) 95 | 96 | #### Business Edition Variables 97 | 98 | * ChocolateyInstallArgumentsSensitive - Encrypted arguments passed from command line `--install-arguments-sensitive` that are not logged anywhere. (0.10.1+ and licensed editions 1.6.0+) 99 | * ChocolateyPackageParametersSensitive - Package parameters passed from command line `--package-parameters-senstivite` that are not logged anywhere. (0.10.1+ and licensed editions 1.6.0+) 100 | * ChocolateyLicensedVersion - What version is the licensed edition on? 101 | * ChocolateyLicenseType - What edition / type of the licensed edition is installed? 102 | * USER_CONTEXT - The original user context - different when self-service is used (Licensed v1.10.0+) 103 | 104 | #### Experimental Environment Variables 105 | The following are experimental or use not recommended: 106 | 107 | * OS_IS64BIT = This may not return correctly - it may depend on the process the app is running under (0.9.9+) 108 | * CHOCOLATEY_VERSION_PRODUCT = the version of Choco that may match CHOCOLATEY_VERSION but may be different (0.9.9+) - based on git describe 109 | * IS_ADMIN = Is the user an administrator? But doesn't tell you if the process is elevated. (0.9.9+) 110 | * IS_REMOTE = Is the user in a remote session? (0.10.6+) 111 | 112 | #### Not Useful Or Anti-Pattern If Used 113 | 114 | * ChocolateyInstallOverride = Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+) 115 | * ChocolateyInstallArguments = The installer arguments meant for the native installer. You should use chocolateyPackageParameters intead. Based on `--install-arguments` being passed. (0.9.9+) 116 | * ChocolateyIgnoreChecksums - Was `--ignore-checksums` passed or the feature `checksumFiles` turned off? (0.9.9.9+) 117 | * ChocolateyAllowEmptyChecksums - Was `--allow-empty-checksums` passed or the feature `allowEmptyChecksums` turned on? (0.10.0+) 118 | * ChocolateyAllowEmptyChecksumsSecure - Was `--allow-empty-checksums-secure` passed or the feature `allowEmptyChecksumsSecure` turned on? (0.10.0+) 119 | * ChocolateyCheckLastExitCode - Should Chocolatey check LASTEXITCODE? Is the feature `scriptsCheckLastExitCode` turned on? (0.10.3+) 120 | * ChocolateyChecksum32 - Was `--download-checksum` passed? (0.10.0+) 121 | * ChocolateyChecksumType32 - Was `--download-checksum-type` passed? (0.10.0+) 122 | * ChocolateyChecksum64 - Was `--download-checksum-x64` passed? (0.10.0)+ 123 | * ChocolateyChecksumType64 - Was `--download-checksum-type-x64` passed? (0.10.0)+ 124 | * ChocolateyPackageExitCode - The exit code of the script that just ran - usually set by `Set-PowerShellExitCode` (CHECK) 125 | * ChocolateyLastPathUpdate - Set by Chocolatey as part of install, but not used for anything in particular in packaging. 126 | * ChocolateyProxyLocation - The explicit proxy location as set in the configuration `proxy` (0.9.9.9+) 127 | * ChocolateyDownloadCache - Use available download cache? Set by `--skip-download-cache`, `--use-download-cache`, or feature `downloadCache` (0.9.10+ and licensed editions 1.1.0+) 128 | * ChocolateyProxyBypassList - Explicitly set locations to ignore in configuration `proxyBypassList` (0.10.4+) 129 | * ChocolateyProxyBypassOnLocal - Should the proxy bypass on local connections? Set based on configuration `proxyBypassOnLocal` (0.10.4+) 130 | * http_proxy - Set by original `http_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+) 131 | * https_proxy - Set by original `https_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+) 132 | * no_proxy- Set by original `no_proxy` passthrough, or same as `ChocolateyProxyBypassList` if explicitly set. (0.10.4+) 133 | 134 | -------------------------------------------------------------------------------- /example/mypackage/_TODO.txt: -------------------------------------------------------------------------------- 1 | TODO 2 | 3 | 1. Determine Package Use: 4 | 5 | Organization? Internal Use? - You are not subject to distribution 6 | rights when you keep everything internal. Put the binaries directly 7 | into the tools directory (as long as total nupkg size is under 1GB). 8 | When bigger, look to use from a share or download binaries from an 9 | internal location. Embedded binaries makes for the most reliable use 10 | of Chocolatey. Use `$fileLocation` (`$file`/`$file64`) and 11 | `Install-ChocolateyInstallPackage`/`Get-ChocolateyUnzip` in 12 | tools\chocolateyInstall.ps1. 13 | 14 | You can also choose to download from internal urls, see the next 15 | section, but ignore whether you have distribution rights or not, it 16 | doesn't apply. Under no circumstances should download from the 17 | internet, it is completely unreliable. See 18 | https://chocolatey.org/docs/community-packages-disclaimer#organizations 19 | to understand the limitations of a publicly available repository. 20 | 21 | Community Repository? 22 | Have Distribution Rights? 23 | If you are the software vendor OR the software EXPLICITLY allows 24 | redistribution and the total nupkg size will be under 200MB, you 25 | have the option to embed the binaries directly into the package to 26 | provide the most reliable install experience. Put the binaries 27 | directly into the tools folder, use `$fileLocation` (`$file`/ 28 | `$file64`) and `Install-ChocolateyInstallPackage`/ 29 | `Get-ChocolateyUnzip` in tools\chocolateyInstall.ps1. Additionally, 30 | fill out the LICENSE and VERIFICATION file (see 3 below and those 31 | files for specifics). 32 | 33 | NOTE: You can choose to download binaries at runtime, but be sure 34 | the download location will remain stable. See the next section. 35 | 36 | Do Not Have Distribution Rights? 37 | - Note: Packages built this way cannot be 100% reliable, but it's a 38 | constraint of publicly available packages and there is little 39 | that can be done to change that. See 40 | https://chocolatey.org/docs/community-packages-disclaimer#organizations 41 | to better understand the limitations of a publicly available 42 | repository. 43 | Download Location is Publicly Available? 44 | You will need to download the runtime files from their official 45 | location at runtime. Use `$url`/`$url64` and 46 | `Install-ChocolateyPackage`/`Install-ChocolateyZipPackage` in 47 | tools\chocolateyInstall.ps1. 48 | Download Location is Not Publicly Available? 49 | Stop here, you can't push this to the community repository. You 50 | can ask the vendor for permission to embed, then include a PDF of 51 | that signed permission directly in the package. Otherwise you 52 | will need to seek alternate locations to non-publicly host the 53 | package. 54 | Download Location Is Same For All Versions? 55 | You still need to point to those urls, but you may wish to set up 56 | something like Automatic Updater (AU) so that when a new version 57 | of the software becomes available, the new package version 58 | automatically gets pushed up to the community repository. See 59 | https://chocolatey.org/docs/automatic-packages#automatic-updater-au 60 | 61 | 2. Determine Package Type: 62 | 63 | - Installer Package - contains an installer (everything in template is 64 | geared towards this type of package) 65 | - Zip Package - downloads or embeds and unpacks archives, may unpack 66 | and run an installer using `Install-ChocolateyInstallPackage` as a 67 | secondary step. 68 | - Portable Package - Contains runtime binaries (or unpacks them as a 69 | zip package) - cannot require administrative permissions to install 70 | or use 71 | - Config Package - sets config like files, registry keys, etc 72 | - Extension Package - Packages that add PowerShell functions to 73 | Chocolatey - https://chocolatey.org/docs/how-to-create-extensions 74 | - Template Package - Packages that add templates like this for `choco 75 | new -t=name` - https://chocolatey.org/docs/how-to-create-custom-package-templates 76 | - Other - there are other types of packages as well, these are the main 77 | package types seen in the wild 78 | 79 | 3. Fill out the package contents: 80 | 81 | - tools\chocolateyBeforeModify.ps1 - remove if you have no processes 82 | or services to shut down before upgrade/uninstall 83 | - tools\LICENSE.txt / tools\VERIFICATION.txt - Remove if you are not 84 | embedding binaries. Keep and fill out if you are embedding binaries 85 | in the package AND pushing to the community repository, even if you 86 | are the author of software. The file becomes easier to fill out 87 | (does not require changes each version) if you are the software 88 | vendor. If you are building packages for internal use (organization, 89 | etc), you don't need these files as you are not subject to 90 | distribution rights internally. 91 | - tools\chocolateyUninstall.ps1 - remove if autouninstaller can 92 | automatically uninstall and you have nothing additional to do during 93 | uninstall 94 | - Readme.txt - delete this file once you have read over and used 95 | anything you've needed from here 96 | - nuspec - fill this out, then clean out all the comments (you may wish 97 | to leave the headers for the package vs software metadata) 98 | - tools\chocolateyInstall.ps1 - instructions in next section. 99 | 100 | 4. ChocolateyInstall.ps1: 101 | 102 | - For embedded binaries - use `$fileLocation` (`$file`/`$file64`) and 103 | `Install-ChocolateyInstallPackage`/ `Get-ChocolateyUnzip`. 104 | - Downloading binaries at runtime - use `$url`/`$url64` and 105 | `Install-ChocolateyPackage` / `Install-ChocolateyZipPackage`. 106 | - Other needs (creating files, setting registry keys), use regular 107 | PowerShell to do so or see if there is a function already defined: 108 | https://chocolatey.org/docs/helpers-reference 109 | - There may also be functions available in extension packages, see 110 | https://chocolatey.org/packages?q=id%3A.extension for examples and 111 | availability. 112 | - Clean out the comments and sections you are not using. 113 | 114 | 5. Test the package to ensure install/uninstall work appropriately. 115 | There is a test environment you can use for this - 116 | https://github.com/chocolatey/chocolatey-test-environment 117 | 118 | 6. Learn more about Chocolatey packaging - go through the workshop at 119 | https://github.com/ferventcoder/chocolatey-workshop 120 | You will learn about 121 | - General packaging 122 | - Customizing package behavior at runtime (package parameters) 123 | - Extension packages 124 | - Custom packaging templates 125 | - Setting up an internal Chocolatey.Server repository 126 | - Adding and using internal repositories 127 | - Reporting 128 | - Advanced packaging techniques when installers are not friendly to 129 | automation 130 | 131 | 7. Delete this file. 132 | -------------------------------------------------------------------------------- /example/mypackage/mypackage.nuspec: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <!-- Read this before creating packages: https://chocolatey.org/docs/create-packages --> 3 | <!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://chocolatey.org/packages). --> 4 | 5 | <!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment --> 6 | 7 | <!-- 8 | This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Reference. Chocolatey uses a special version of NuGet.Core that allows us to do more than was initially possible. As such there are certain things to be aware of: 9 | 10 | * the package xmlns schema url may cause issues with nuget.exe 11 | * Any of the following elements can ONLY be used by choco tools - projectSourceUrl, docsUrl, mailingListUrl, bugTrackerUrl, packageSourceUrl, provides, conflicts, replaces 12 | * nuget.exe can still install packages with those elements but they are ignored. Any authoring tools or commands will error on those elements 13 | --> 14 | 15 | <!-- You can embed software files directly into packages, as long as you are not bound by distribution rights. --> 16 | <!-- * If you are an organization making private packages, you probably have no issues here --> 17 | <!-- * If you are releasing to the community feed, you need to consider distribution rights. --> 18 | <!-- 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. --> 19 | <package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"> 20 | <metadata> 21 | <!-- == PACKAGE SPECIFIC SECTION == --> 22 | <!-- This section is about this package, although id and version have ties back to the software --> 23 | <!-- id is lowercase and if you want a good separator for words, use '-', not '.'. Dots are only acceptable as suffixes for certain types of packages, e.g. .install, .portable, .extension, .template --> 24 | <!-- If the software is cross-platform, attempt to use the same id as the debian/rpm package(s) if possible. --> 25 | <id>mypackage</id> 26 | <!-- version should MATCH as closely as possible with the underlying software --> 27 | <!-- Is the version a prerelease of a version? https://docs.nuget.org/create/versioning#creating-prerelease-packages --> 28 | <!-- Note that unstable versions like 0.0.1 can be considered a released version, but it's possible that one can release a 0.0.1-beta before you release a 0.0.1 version. If the version number is final, that is considered a released version and not a prerelease. --> 29 | <version>1.0.0</version> 30 | <!-- <packageSourceUrl>Where is this Chocolatey package located (think GitHub)? packageSourceUrl is highly recommended for the community feed</packageSourceUrl>--> 31 | <!-- owners is a poor name for maintainers of the package. It sticks around by this name for compatibility reasons. It basically means you. --> 32 | <!--<owners>Justin</owners>--> 33 | <!-- ============================== --> 34 | 35 | <!-- == SOFTWARE SPECIFIC SECTION == --> 36 | <!-- This section is about the software itself --> 37 | <title>mypackage (Install) 38 | Justin Phelps 39 | 40 | https://github.com/Linuturk/mono-choco 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | mypackage SPACE_SEPARATED 51 | A basic example nuget package. 52 | A basic example nuget package. 53 | 54 | 55 | 56 | 57 | 58 | 63 | 64 | 65 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /example/mypackage/tools/LICENSE.txt: -------------------------------------------------------------------------------- 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: 8 | 9 | LICENSE 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/mypackage/tools/VERIFICATION.txt: -------------------------------------------------------------------------------- 1 |  2 | Note: Include this file if including binaries you have the right to distribute. 3 | Otherwise delete. this file. If you are the software author, you can change this 4 | mention you are the author of the software. 5 | 6 | ===DELETE ABOVE THIS LINE AND THIS LINE=== 7 | 8 | VERIFICATION 9 | Verification is intended to assist the Chocolatey moderators and community 10 | in verifying that this package's contents are trustworthy. 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/mypackage/tools/chocolateybeforemodify.ps1: -------------------------------------------------------------------------------- 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 | 10 | -------------------------------------------------------------------------------- /example/mypackage/tools/chocolateyinstall.ps1: -------------------------------------------------------------------------------- 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 | # 1. See the _TODO.md that is generated top level and read through that 6 | # 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 errors 9 | $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" 10 | # Internal packages (organizations) or software that has redistribution rights (community repo) 11 | # - Use `Install-ChocolateyInstallPackage` instead of `Install-ChocolateyPackage` 12 | # and put the binaries directly into the tools folder (we call it embedding) 13 | #$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE' 14 | # If embedding binaries increase total nupkg size to over 1GB, use share location or download from urls 15 | #$fileLocation = '\\SHARE_LOCATION\to\INSTALLER_FILE' 16 | # Community Repo: Use official urls for non-redist binaries or redist where total package size is over 200MB 17 | # Internal/Organization: Download from internal location (internet sources are unreliable) 18 | $url = '' # download url, HTTPS preferred 19 | $url64 = '' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url 20 | 21 | $packageArgs = @{ 22 | packageName = $env:ChocolateyPackageName 23 | unzipLocation = $toolsDir 24 | fileType = 'EXE_MSI_OR_MSU' #only one of these: exe, msi, msu 25 | url = $url 26 | url64bit = $url64 27 | #file = $fileLocation 28 | 29 | softwareName = 'mypackage*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique 30 | 31 | # Checksums are now required as of 0.10.0. 32 | # To determine checksums, you can get that from the original site if provided. 33 | # You can also use checksum.exe (choco install checksum) and use it 34 | # e.g. checksum -t sha256 -f path\to\file 35 | checksum = '' 36 | checksumType = 'sha256' #default is md5, can also be sha1, sha256 or sha512 37 | checksum64 = '' 38 | checksumType64= 'sha256' #default is checksumType 39 | 40 | # MSI 41 | silentArgs = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0 42 | validExitCodes= @(0, 3010, 1641) 43 | # OTHERS 44 | # Uncomment matching EXE type (sorted by most to least common) 45 | #silentArgs = '/S' # NSIS 46 | #silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup 47 | #silentArgs = '/s' # InstallShield 48 | #silentArgs = '/s /v"/qn"' # InstallShield with MSI 49 | #silentArgs = '/s' # Wise InstallMaster 50 | #silentArgs = '-s' # Squirrel 51 | #silentArgs = '-q' # Install4j 52 | #silentArgs = '-s' # Ghost 53 | # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence. 54 | #silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) 55 | # https://chocolatey.org/packages/autohotkey.portable 56 | #validExitCodes= @(0) #please insert other valid exit codes here 57 | } 58 | 59 | Install-ChocolateyPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-package 60 | #Install-ChocolateyZipPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-zip-package 61 | ## If you are making your own internal packages (organizations), you can embed the installer or 62 | ## put on internal file share and use the following instead (you'll need to add $file to the above) 63 | #Install-ChocolateyInstallPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-install-package 64 | 65 | ## Main helper functions - these have error handling tucked into them already 66 | ## see https://chocolatey.org/docs/helpers-reference 67 | 68 | ## Install an application, will assert administrative rights 69 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-package 70 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package 71 | ## add additional optional arguments as necessary 72 | ##Install-ChocolateyPackage $packageName $fileType $silentArgs $url [$url64 -validExitCodes $validExitCodes -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64] 73 | 74 | ## Download and unpack a zip file - https://chocolatey.org/docs/helpers-install-chocolatey-zip-package 75 | ##Install-ChocolateyZipPackage $packageName $url $toolsDir [$url64 -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64] 76 | 77 | ## Install Visual Studio Package - https://chocolatey.org/docs/helpers-install-chocolatey-vsix-package 78 | #Install-ChocolateyVsixPackage $packageName $url [$vsVersion] [-checksum $checksum -checksumType $checksumType] 79 | #Install-ChocolateyVsixPackage @packageArgs 80 | 81 | ## see the full list at https://chocolatey.org/docs/helpers-reference 82 | 83 | ## downloader that the main helpers use to download items 84 | ## if removing $url64, please remove from here 85 | ## - https://chocolatey.org/docs/helpers-get-chocolatey-web-file 86 | #Get-ChocolateyWebFile $packageName 'DOWNLOAD_TO_FILE_FULL_PATH' $url $url64 87 | 88 | ## Installer, will assert administrative rights - used by Install-ChocolateyPackage 89 | ## use this for embedding installers in the package when not going to community feed or when you have distribution rights 90 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-install-package 91 | #Install-ChocolateyInstallPackage $packageName $fileType $silentArgs '_FULLFILEPATH_' -validExitCodes $validExitCodes 92 | 93 | ## Unzips a file to the specified location - auto overwrites existing content 94 | ## - https://chocolatey.org/docs/helpers-get-chocolatey-unzip 95 | #Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" $toolsDir 96 | 97 | ## Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage 98 | ## - https://chocolatey.org/docs/helpers-start-chocolatey-process-as-admin 99 | #Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes 100 | 101 | ## To avoid quoting issues, you can also assemble your -Statements in another variable and pass it in 102 | #$appPath = "$env:ProgramFiles\appname" 103 | ##Will resolve to C:\Program Files\appname 104 | #$statementsToRun = "/C `"$appPath\bin\installservice.bat`"" 105 | #Start-ChocolateyProcessAsAdmin $statementsToRun cmd -validExitCodes $validExitCodes 106 | 107 | ## add specific folders to the path - any executables found in the chocolatey package 108 | ## folder will already be on the path. This is used in addition to that or for cases 109 | ## when a native installer doesn't add things to the path. 110 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-path 111 | #Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights 112 | 113 | ## Add specific files as shortcuts to the desktop 114 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-shortcut 115 | #$target = Join-Path $toolsDir "$($packageName).exe" 116 | # Install-ChocolateyShortcut -shortcutFilePath "" -targetPath "" [-workDirectory "C:\" -arguments "C:\test.txt" -iconLocation "C:\test.ico" -description "This is the description"] 117 | 118 | ## Outputs the bitness of the OS (either "32" or "64") 119 | ## - https://chocolatey.org/docs/helpers-get-o-s-architecture-width 120 | #$osBitness = Get-ProcessorBits 121 | 122 | ## Set persistent Environment variables 123 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-environment-variable 124 | #Install-ChocolateyEnvironmentVariable -variableName "SOMEVAR" -variableValue "value" [-variableType = 'Machine' #Defaults to 'User'] 125 | 126 | ## Set up a file association 127 | ## - https://chocolatey.org/docs/helpers-install-chocolatey-file-association 128 | #Install-ChocolateyFileAssociation 129 | 130 | ## Adding a shim when not automatically found - Cocolatey automatically shims exe files found in package directory. 131 | ## - https://chocolatey.org/docs/helpers-install-bin-file 132 | ## - https://chocolatey.org/docs/create-packages#how-do-i-exclude-executables-from-getting-shims 133 | #Install-BinFile 134 | 135 | ##PORTABLE EXAMPLE 136 | #$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" 137 | # despite the name "Install-ChocolateyZipPackage" this also works with 7z archives 138 | #Install-ChocolateyZipPackage $packageName $url $toolsDir $url64 139 | ## END PORTABLE EXAMPLE 140 | 141 | ## [DEPRECATING] PORTABLE EXAMPLE 142 | #$binRoot = Get-BinRoot 143 | #$installDir = Join-Path $binRoot "$packageName" 144 | #Write-Host "Adding `'$installDir`' to the path and the current shell path" 145 | #Install-ChocolateyPath "$installDir" 146 | #$env:Path = "$($env:Path);$installDir" 147 | 148 | # if removing $url64, please remove from here 149 | # despite the name "Install-ChocolateyZipPackage" this also works with 7z archives 150 | #Install-ChocolateyZipPackage "$packageName" "$url" "$installDir" "$url64" 151 | ## END PORTABLE EXAMPLE 152 | -------------------------------------------------------------------------------- /example/mypackage/tools/chocolateyuninstall.ps1: -------------------------------------------------------------------------------- 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), 6 | ## AutoUninstaller should be able to detect and handle registry uninstalls without a chocolateyUninstall.ps1. 7 | ## See https://chocolatey.org/docs/commands-uninstall 8 | ## and https://chocolatey.org/docs/helpers-uninstall-chocolatey-package 9 | 10 | ## If this is an MSI, ensure 'softwareName' is appropriate, then clean up comments and you are done. 11 | ## If this is an exe, change fileType, silentArgs, and validExitCodes 12 | 13 | $ErrorActionPreference = 'Stop'; # stop on all errors 14 | $packageArgs = @{ 15 | packageName = $env:ChocolateyPackageName 16 | softwareName = 'mypackage*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique 17 | fileType = 'EXE_MSI_OR_MSU' #only one of these: MSI or EXE (ignore MSU for now) 18 | # MSI 19 | silentArgs = "/qn /norestart" 20 | validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx 21 | # OTHERS 22 | # Uncomment matching EXE type (sorted by most to least common) 23 | #silentArgs = '/S' # NSIS 24 | #silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup 25 | #silentArgs = '/s' # InstallShield 26 | #silentArgs = '/s /v"/qn"' # InstallShield with MSI 27 | #silentArgs = '/s' # Wise InstallMaster 28 | #silentArgs = '-s' # Squirrel 29 | #silentArgs = '-q' # Install4j 30 | #silentArgs = '-s -u' # Ghost 31 | # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence. 32 | #silentArgs = '' # none; make silent with input macro script like AutoHotKey (AHK) 33 | # https://chocolatey.org/packages/autohotkey.portable 34 | #validExitCodes= @(0) #please insert other valid exit codes here 35 | } 36 | 37 | $uninstalled = $false 38 | # Get-UninstallRegistryKey is new to 0.9.10, if supporting 0.9.9.x and below, 39 | # take a dependency on "chocolatey-core.extension" in your nuspec file. 40 | # This is only a fuzzy search if $softwareName includes '*'. Otherwise it is 41 | # exact. In the case of versions in key names, we recommend removing the version 42 | # and using '*'. 43 | [array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName'] 44 | 45 | if ($key.Count -eq 1) { 46 | $key | % { 47 | $packageArgs['file'] = "$($_.UninstallString)" 48 | if ($packageArgs['fileType'] -eq 'MSI') { 49 | # The Product Code GUID is all that should be passed for MSI, and very 50 | # FIRST, because it comes directly after /x, which is already set in the 51 | # Uninstall-ChocolateyPackage msiargs (facepalm). 52 | $packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])" 53 | 54 | # Don't pass anything for file, it is ignored for msi (facepalm number 2) 55 | # Alternatively if you need to pass a path to an msi, determine that and 56 | # use it instead of the above in silentArgs, still very first 57 | $packageArgs['file'] = '' 58 | } 59 | 60 | Uninstall-ChocolateyPackage @packageArgs 61 | } 62 | } elseif ($key.Count -eq 0) { 63 | Write-Warning "$packageName has already been uninstalled by other means." 64 | } elseif ($key.Count -gt 1) { 65 | Write-Warning "$($key.Count) matches found!" 66 | Write-Warning "To prevent accidental data loss, no programs will be uninstalled." 67 | Write-Warning "Please alert package maintainer the following keys were matched:" 68 | $key | % {Write-Warning "- $($_.DisplayName)"} 69 | } 70 | 71 | ## OTHER POWERSHELL FUNCTIONS 72 | ## https://chocolatey.org/docs/helpers-reference 73 | #Uninstall-ChocolateyZipPackage $packageName # Only necessary if you did not unpack to package directory - see https://chocolatey.org/docs/helpers-uninstall-chocolatey-zip-package 74 | #Uninstall-ChocolateyEnvironmentVariable # 0.9.10+ - https://chocolatey.org/docs/helpers-uninstall-chocolatey-environment-variable 75 | #Uninstall-BinFile # Only needed if you used Install-BinFile - see https://chocolatey.org/docs/helpers-uninstall-bin-file 76 | ## Remove any shortcuts you added in the install script. 77 | 78 | --------------------------------------------------------------------------------