From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search

A silent installer for Chocolately (, which in turn does silent Windows software installs.

This downloads the install.ps1 script, which will download and install chocolatey to %programdata%\chocolatey.

Once this is installed, you can use commands like "choco install 7zip -y" to install software automatically. This can be useful to save having to update WPKG packages for common tools, as chocolatey has a central repository.

An example of how packages might be installed using WPKG to trigger chocolatey installs is given below.

<?xml version="1.0" encoding="UTF-8"?>

<packages:packages xmlns:packages=""
	xmlns:wpkg="" xmlns:xsi=""
	xsi:schemaLocation=" ../xsd/packages.xsd">

		<variable name="version" value="" />

		<check type="file" condition="exists" path='%programdata%\chocolatey\bin\chocolatey.exe' value="%version%" />
		<variable name="installerPath" value="chocolatey\install.ps1"/>
		<variable name="installerURL" value="" />

		<!-- standard variables - usually in config.xml -->
		<variable name="SOFTWARE" value="software" 		/>	
		<variable name="DOWNLOADERPATH" value="tools\downloader\downloader.cmd"  />  
		<!-- conditional download -->
		<install cmd='"%DOWNLOADERPATH%" "%installerURL%"	"%software%\%installerPath%"  >NUL'>
			<condition><check type="logical" condition="not"><check type="file" condition="exists" path="%SOFTWARE%\%installerPath%" /></check></condition>
		<install cmd='powershell "%SOFTWARE%\%installerPath%"'  /> 
		<upgrade include="install" />
		<remove cmd='cmd /c rmdir /s /q "%programdata%\chocolatey\"' /> 

                name="Basic packages (using Chocolatey)"

		<depends package-id="chocolatey" /> 
		<!-- See . Can use more than one:
			<variable name="PKGNAMES" value="vlc firefox nssm notepadplusplus git 7zip" />
		<variable name="PKGNAMES" value="classic-shell googlechrome notepadplusplus" />
		<!-- check for a version of each package -->
		<check path='Classic Shell' 	value='4.3.0' 			type='uninstall' condition='versiongreaterorequal' />
		<check path='Google Chrome' 	value='61.0.3163.100' 	type='uninstall' condition='versiongreaterorequal' />
		<check path='Notepad\+\+.*' 	value='7.5.1' 			type='uninstall' condition='versiongreaterorequal' />
		Or could possibly use choco list in a .cmd file like this, though harder to catch versiongreaterorequal:
			choco list - -localonly | findstr /ib /c:%1
			exit %ERRORLEVEL%
		<check type="execute" path='chocotest.cmd "7zip "' condition="exitcodeequalto" value="0"/>		
		<!-- "choco upgrade" command installs or upgrades as appropriate. -->
		<install cmd='%COMSPEC% /v /c set ChocolateyInstall=%programdata%\chocolatey&amp;&amp; %programdata%\chocolatey\choco upgrade %PKGNAMES% -y &gt;"%programdata%\chocolatey\logs\wpkgchocoinstall.log"'  /> 
		<upgrade include="install" />
		<remove  cmd='%COMSPEC% /v /c set ChocolateyInstall=%programdata%\chocolatey&amp;&amp; %programdata%\chocolatey\choco uninstall %PKGNAMES% -y &gt;"%programdata%\chocolatey\logs\wpkgchocoinstall.log"'/>
		Useful to pipe chocolatey output to log file: e.g. &gt;"%programdata%\chocolatey\logs\wpkgchocoinstall.log"
		See also C:\ProgramData\chocolatey\logs\chocolatey.log