-
-
Save mwallner/62cb9258a73105e68ff3aa2f0073b734 to your computer and use it in GitHub Desktop.
Relatively untested extension to jankily add ARM support to the packaging functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-OSArchitectureType { | |
| param( | |
| [ValidateSet('CISC', 'RISC')] | |
| $Compare | |
| ) | |
| $ArchType = if ($env:PROCESSOR_ARCHITECTURE.StartsWith('ARM')) { | |
| 'RISC' | |
| } else { | |
| 'CISC' | |
| } | |
| if ($Compare) { | |
| $ArchType -eq $Compare | |
| } else { | |
| $ArchType | |
| } | |
| } | |
| function ShimArmFunctionality { | |
| [CmdletBinding()] | |
| param( | |
| [string]$urlArm, | |
| [alias("urlArm64")][string]$urlArm64bit, | |
| [string]$checksumArm, | |
| [string]$checksumArm64, | |
| [string]$checksumTypeArm, | |
| [string]$checksumTypeArm64 | |
| ) | |
| DynamicParam { | |
| $paramDict = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() | |
| [System.Management.Automation.CommandMetaData]::new((Get-Command (Get-PSCallStack)[0].InvocationInfo.InvocationName -Module chocolateyInstaller)).Parameters.GetEnumerator().ForEach{ | |
| $paramObject = [System.Management.Automation.RuntimeDefinedParameter]::new( | |
| $_.Value.Name, | |
| $_.Value.ParameterType, | |
| $_.Value.Attributes | |
| ) | |
| $paramDict.Add($_.Key, $paramObject) | |
| } | |
| return $paramDict | |
| } | |
| end { | |
| $EventualProxiedArguments = $PSBoundParameters | |
| if (Get-OSArchitectureType -Compare 'RISC') { | |
| switch ($($PSBoundParameters.Keys)) { | |
| "urlArm" {$EventualProxiedArguments.url = $urlArm} | |
| "urlArm64" {$EventualProxiedArguments.url64bit = $urlArm64} | |
| "checksumArm" {$EventualProxiedArguments.checksum = $checksumArm} | |
| "checksumArm64" {$EventualProxiedArguments.checksum64 = $checksumArm64} | |
| "checksumTypeArm" {$EventualProxiedArguments.checksumType = $checksumTypeArm} | |
| "checksumTypeArm64" {$EventualProxiedArguments.checksumType64 = $checksumTypeArm64} | |
| default {Write-Verbose "Nothing found for $_"} | |
| } | |
| } | |
| # Remove any of the non-proxied parameters from the eventual call | |
| $PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator().Where{ | |
| -not $_.Value.IsDynamic -and | |
| $_.Key -notin [System.Management.Automation.PSCmdlet]::CommonParameters | |
| }.ForEach{ | |
| Write-Verbose "Removing '$($_.Key)' from the passed parameters" | |
| $null = $EventualProxiedArguments.Remove($_.Key) | |
| } | |
| # $EventualProxiedArguments | ConvertTo-Json | Write-Output | Write-Debug | |
| & $($MyInvocation.InvocationName) @EventualProxiedArguments | |
| } | |
| } | |
| # if (-not (Get-Module chocolateyInstaller)) { | |
| # Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1 | |
| # } | |
| Get-Command -Module chocolateyInstaller -ParameterName Url64 <#,File64#> | ForEach-Object { | |
| if ($_.Parameters.Keys -notcontains 'UrlArm') { | |
| Set-Alias -Scope Global -Name $_.Name -Value ShimArmFunctionality | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment