Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Last active February 26, 2024 02:17
Show Gist options
  • Save steviecoaster/0df4e760c004dfa6bfb0a52c959f3583 to your computer and use it in GitHub Desktop.
Save steviecoaster/0df4e760c004dfa6bfb0a52c959f3583 to your computer and use it in GitHub Desktop.
ConvertFrom-WinGetManifest - A function to create a chocolateyInstall.ps1 file from a WinGet manifest
function ConvertFrom-WinGetManifest {
<#
.SYNOPSIS
Generates a Chocolatey install script for a WinGet manifest
.DESCRIPTION
Generate a Chocolatey package from a WinGet manifest, even though it'll probably already be on the CCR.
.PARAMETER WinGetManifestRawUrl
The Github raw url of the WinGet YAML manifest
.EXAMPLE
ConvertFrom-WinGetManifest -WingGetManifestRawUrl 'https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/g/Google/Chrome/122.0.6261.70/Google.Chrome.installer.yaml'
.NOTES
General notes
#>
#Requires -Modules powershell-yaml
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]
$WinGetManifestRawUrl
)
process {
$yaml = (Invoke-WebRequest $WinGetManifest -UseBasicParsing).Content
$obj = $yaml | ConvertFrom-Yaml
$packageid = $Obj.PackageIdentifier
$installers = ($obj).installers | Where-Object Scope -eq 'Machine'
$data = [pscustomobject]@{
PackageId = $packageid
Installerx86 = ($installers | Where-Object Architecture -EQ 'x86').InstallerUrl
Installerx64 = ($installers | Where-Object Architecture -eq 'x64').InstallerUrl
Checksum = ($installers | Where-Object Architecture -eq 'x86').InstallerSha256
Checksum64 = ($installers | Where-Object Architecture -eq 'x64').InstallerSha256
}
$chocolateyInstall = @'
$packageName= '[[packageid]]'
$toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"
$url = '[[url]]'
$url64 = '[[url64]]'
$packageArgs = @{
packageName = $packageName
fileType = 'msi'
url = $url
url64bit = $url64
silentArgs = "/qn /norestart"
validExitCodes= @(0, 3010, 1641)
softwareName = 'Bob*'
checksum = '[[checksum]]'
checksumType = 'sha256'
checksum64 = '[[checksum64]]'
checksumType64= 'sha256'
}
Install-ChocolateyPackage @packageArgs
'@
($chocolateyInstall).Replace('[[packageid]]',$data.PackageId).Replace('[[url]]',$data.Installerx86).Replace('[[url64]]',$data.Installerx64).Replace('[[checksum]]',$data.Checksum).Replace('[[checksum64]]',$data.Checksum64)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment