Search code examples
packagechocolatey

Trying to create custom installation package through chocolatey


I am new to scripting. I was trying to create a chocolatey package that would automatically do a custom(not typical) install. For example with MariaDB installations, I would like to specify which parts of the server to install and the username and password for the database. I was trying to practice on Libreoffice where the package chooses Custom install and intalls only libre Writer. But the following script does the default installations what am I missing here? thanks.

chocolateinstall.ps1

e$ErrorActionPreference = 'Stop'; # stop on all errors
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$fileLocation = ".\LibreOffice_7.2.7_Win_x64.msi"
$pp= Get-PackageParameters 
if (!$pp['SetupType']){$pp['SetupType']='Custom'}
if (!$pp['InstallOption']){$pp['InstallOption']='LibreWriter'}
$packageArgs = @{
    packageName   = $env:ChocolateyPackageName
    unzipLocation = $toolsDir
    fileType      = 'msi' 
file         = $fileLocation
    
    softwareName  = 'libre*'
checksum      = '...'
    checksumType  = 'sha256'
silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0
    validExitCodes= @(0, 3010, 1641)
}
Install-ChocolateyPackage @packageArgs

Solution

  • This is a pretty huge question, to one extent, and quite easy in another!

    Short answer:

    Your example above doesn't pass any of the package arguments you're crafting (e.g. $pp['InstallOption']) to the actual installer. They're being stored in the variable ($pp) and never used.

    The values you want to use should be passed in to Install-ChocolateyPackage using the silentArgs parameter.

    However, I don't think the arguments you have there are going to work, even if you pass them in (though I may be mistaken).

    Longer answer:

    MSIs don't just accept random arguments.

    Accepted arguments vary hugely by installer, and by software, and there's no guarantee you can do what you want silently from the commandline.

    You can use something like Orca to find out what arguments an MSI may support, or search for documentation (or other folk having done the work before), or create an MST file to apply.

    You could also use the Chocolatey for Business Package Builder, which scans the file and tries to identify useful arguments you can pass - though this requires a paid Business license for Chocolatey.