|
| 1 | +$ErrorActionPreference = 'Stop' |
| 2 | + |
| 3 | +$toolsDir = Split-Path -Parent $MyInvocation.MyCommand.Definition |
| 4 | +$packageName = $env:ChocolateyPackageName |
| 5 | +$packageVersion = $env:ChocolateyPackageVersion |
| 6 | + |
| 7 | +$url64 = "https://github.com/dropbox/dbxcli/releases/download/v$packageVersion/dbxcli_${packageVersion}_windows_amd64.zip" |
| 8 | +$checksum64 = "__WINDOWS_AMD64_SHA256__" |
| 9 | + |
| 10 | +function Install-DbxcliExe { |
| 11 | + $rootExePath = Join-Path $toolsDir 'dbxcli.exe' |
| 12 | + if (Test-Path -LiteralPath $rootExePath) { |
| 13 | + return |
| 14 | + } |
| 15 | + |
| 16 | + $archiveExePath = Join-Path $toolsDir "dbxcli_${packageVersion}_windows_amd64\dbxcli.exe" |
| 17 | + if (!(Test-Path -LiteralPath $archiveExePath)) { |
| 18 | + throw "Could not find dbxcli.exe after extracting the release archive" |
| 19 | + } |
| 20 | + |
| 21 | + Copy-Item -LiteralPath $archiveExePath -Destination $rootExePath -Force |
| 22 | +} |
| 23 | + |
| 24 | +function Get-Sha256Checksum($path) { |
| 25 | + $sha256 = [System.Security.Cryptography.SHA256]::Create() |
| 26 | + $stream = [System.IO.File]::OpenRead($path) |
| 27 | + |
| 28 | + try { |
| 29 | + return [System.BitConverter]::ToString($sha256.ComputeHash($stream)).Replace('-', '').ToLowerInvariant() |
| 30 | + } |
| 31 | + finally { |
| 32 | + $stream.Dispose() |
| 33 | + $sha256.Dispose() |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +if ($env:DBXCLI_CHOCOLATEY_URL64) { |
| 38 | + $url64 = $env:DBXCLI_CHOCOLATEY_URL64 |
| 39 | +} |
| 40 | + |
| 41 | +if ($env:DBXCLI_CHOCOLATEY_CHECKSUM64) { |
| 42 | + $checksum64 = $env:DBXCLI_CHOCOLATEY_CHECKSUM64 |
| 43 | +} |
| 44 | + |
| 45 | +if ($checksum64 -eq "__WINDOWS_AMD64_SHA256__") { |
| 46 | + throw "dbxcli Chocolatey package checksum was not set for version $packageVersion" |
| 47 | +} |
| 48 | + |
| 49 | +$isRemoteUrl = $url64 -match '^https?://' |
| 50 | + |
| 51 | +if (!$isRemoteUrl) { |
| 52 | + if (!(Test-Path -LiteralPath $url64)) { |
| 53 | + throw "Local dbxcli archive not found: $url64" |
| 54 | + } |
| 55 | + |
| 56 | + $actualChecksum = Get-Sha256Checksum $url64 |
| 57 | + if ($actualChecksum -ne $checksum64.ToLowerInvariant()) { |
| 58 | + throw "Checksum mismatch for $url64. Expected $checksum64, got $actualChecksum" |
| 59 | + } |
| 60 | + |
| 61 | + Get-ChocolateyUnzip -FileFullPath $url64 -Destination $toolsDir |
| 62 | + Install-DbxcliExe |
| 63 | + return |
| 64 | +} |
| 65 | + |
| 66 | +$packageArgs = @{ |
| 67 | + packageName = $packageName |
| 68 | + unzipLocation = $toolsDir |
| 69 | + url64bit = $url64 |
| 70 | + checksum64 = $checksum64 |
| 71 | + checksumType64 = 'sha256' |
| 72 | +} |
| 73 | + |
| 74 | +Install-ChocolateyZipPackage @packageArgs |
| 75 | +Install-DbxcliExe |
0 commit comments