Skip to content

Commit

Permalink
Merge pull request #42 from theohbrothers/enhancement/bump-generate-d…
Browse files Browse the repository at this point in the history
…ownloadbinary-function-to-0.1.0

Enhancement: Bump `Generate-DownloadBinary` function to 0.1.0
  • Loading branch information
leojonathanoh authored Dec 1, 2023
2 parents 44a6d28 + 22852fc commit 799ce7b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 36 deletions.
65 changes: 47 additions & 18 deletions generate/functions/Generate-DownloadBinary.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
function global:Generate-DownloadBinary ($o) {
# Version 0.1.0
function Generate-DownloadBinary ($o) {
Set-StrictMode -Version Latest

Set-Checksums "$( $o['binary'] )-$( $o['version'] )" $o['checksumsUrl']

$checksumsKey = "$( $o['binary'] )-$( $o['version'] )"
$files = [ordered]@{}
if ($o['checksumsUrl']) {
Set-Checksums $checksumsKey $o['checksumsUrl']
}else {
$release = Invoke-RestMethod "https://api.github.com/repos/$( $o['repository'] )/releases/tags/$( $o['version'] )"
$releaseAssetsFiles = $release.assets | ? { $_.name -match [regex]::Escape($o['binary']) -and $_.name -notmatch '\.sha\d+$' }
foreach ($f in $releaseAssetsFiles ) {
$sha = & {
$shaF = $release.assets | ? { $_.name -eq "$( $f.name ).sha256" -or $_ -eq "$( $f.name ).sha512" }
$r = Invoke-WebRequest $shaF.browser_download_url
$c = if ($r.headers['Content-Type'] -eq 'text/plain') { $r.Content } else { [System.Text.Encoding]::UTF8.GetString($r.Content) }
$c = $c.Trim() -replace '^([a-fA-F0-9]+) .+', '$1' # The checksum is the first column
$c
}
$files[$f.name] = $sha
}
}
$shellVariable = "$( $o['binary'].ToUpper() -replace '[^A-Za-z0-9_]', '_' )_VERSION"
@"
# Install $( $o['binary'] )
Expand All @@ -15,53 +32,65 @@ RUN set -eux; \
$o['architectures'] = if ($o.Contains('architectures')) { $o['architectures'] } else { 'linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/riscv64,linux/s390x' }
foreach ($a in ($o['architectures'] -split ',') ) {
$split = $a -split '/'
$os = $split[0]
$arch = $split[1]
$archv = if ($split.Count -gt 2) { $split[2] } else { '' }
$os = $split[0] # E.g. 'linux'
$arch = $split[1] # E.g. 'amd64'
$archv = if ($split.Count -gt 2) { $split[2] } else { '' } # E.g. 'v6' or ''
switch ($a) {
"$os/386" {
$hardware = 'x86'
$regex = "$os[-_](i?$arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_](i?$arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|(i?$arch|x86(_64)?)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/amd64" {
$hardware = 'x86_64'
$regex = "$os[-_]($arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]($arch|x86(_64)?)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|($arch|x86(_64)?)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm/v6" {
$hardware = 'armhf'
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$|($arch|arm)[-_]?($archv)?.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm/v7" {
$hardware = 'armv7l'
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]($arch|arm)[-_]?($archv)?$( [regex]::Escape($o['archiveformat']) )$|($arch|arm)[-_]?($archv)?.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/arm64" {
$hardware = 'aarch64'
$regex = "$os[-_]($arch|aarch64)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]($arch|aarch64)[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|($arch|aarch64)[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/ppc64le" {
$hardware = 'ppc64le'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/riscv64" {
$hardware = 'riscv64'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
"$os/s390x" {
$hardware = 's390x'
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$"
$regex = "$os[-_]$arch[-_]?$archv$( [regex]::Escape($o['archiveformat']) )$|$arch[-_]?$archv.*?[-_]$os.*?$( [regex]::Escape($o['archiveformat']) )$"
}
default {
throw "Unsupported architecture: $a"
}
}

$file = Get-ChecksumsFile "$( $o['binary'] )-$( $o['version'] )" $regex
if ($file) {
$sha = Get-ChecksumsSha "$( $o['binary'] )-$( $o['version'] )" $regex
$file = $sha = $url = ''
if ($o['checksumsUrl']) {
$file = Get-ChecksumsFile $checksumsKey $regex
$sha = Get-ChecksumsSha $checksumsKey $regex
$url = Split-Path $o['checksumsUrl'] -Parent
} else {
$file = $files.Keys | ? { $_ -match $regex } | Select-Object -First 1
if ($file) {
$url = "https://github.com/$( $o['repository'] )/releases/download/$( $o['version'] )"
$sha = $files[$file]
}else {
throw "No file matched regex: $regex"
}
}
if ($file -and $sha) {
@"
'$hardware') \
URL=$( Split-Path $o['checksumsUrl'] -Parent )/$file; \
URL="$url/$file"; \
SHA256=$sha; \
;; \
Expand Down
8 changes: 4 additions & 4 deletions variants/1.4.4-pingme/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ RUN set -eux; \
PINGME_VERSION=v0.2.5; \
case "$( uname -m )" in \
'x86') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz"; \
SHA256=5a14e80693800284f11daf7d5ba71a7cbe78e18948579584f36069d7a2f31d4a; \
;; \
'x86_64') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz"; \
SHA256=93133b9c978d5a579526261255c2a7a9ca6dfc5ab42ef65e1de4fab15d8ac808; \
;; \
'armv7l') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_armv7.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_armv7.tar.gz"; \
SHA256=6f26a3926e6ed038ca132b4d1985cd2f6c0ccf037fbc78f710bdc2cc76b3fc5a; \
;; \
'aarch64') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_arm64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_arm64.tar.gz"; \
SHA256=496bb93402611d5710bc66b26f64f13fc0f888d0b3cc1f4d7960c7c631860dd3; \
;; \
*) \
Expand Down
16 changes: 8 additions & 8 deletions variants/1.4.4-restic-pingme/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ RUN set -eux; \
RESTIC_VERSION=v0.15.1; \
case "$( uname -m )" in \
'x86') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_386.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_386.bz2"; \
SHA256=50362f6c4c2d91cf0edc750c578b73605fdbb79443874110cc0a64913553f76b; \
;; \
'x86_64') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_amd64.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_amd64.bz2"; \
SHA256=3631e3c3833c84ba71f22ea3df20381676abc7476a7f6d14424d9abfada91414; \
;; \
'armv7l') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2"; \
SHA256=1a5c1d2a3b17aa381c318b3f3919f7cfc4cd430c3a2c3053ba055fb4ccf38c97; \
;; \
'aarch64') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm64.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm64.bz2"; \
SHA256=bf6e09743df6899a02f0647d899fb008932760ea872667287bbc47b42091a3b0; \
;; \
*) \
Expand All @@ -66,19 +66,19 @@ RUN set -eux; \
PINGME_VERSION=v0.2.5; \
case "$( uname -m )" in \
'x86') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz"; \
SHA256=5a14e80693800284f11daf7d5ba71a7cbe78e18948579584f36069d7a2f31d4a; \
;; \
'x86_64') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_x86_64.tar.gz"; \
SHA256=93133b9c978d5a579526261255c2a7a9ca6dfc5ab42ef65e1de4fab15d8ac808; \
;; \
'armv7l') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_armv7.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_armv7.tar.gz"; \
SHA256=6f26a3926e6ed038ca132b4d1985cd2f6c0ccf037fbc78f710bdc2cc76b3fc5a; \
;; \
'aarch64') \
URL=https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_arm64.tar.gz; \
URL="https://github.com/kha7iq/pingme/releases/download/v0.2.5/pingme_Linux_arm64.tar.gz"; \
SHA256=496bb93402611d5710bc66b26f64f13fc0f888d0b3cc1f4d7960c7c631860dd3; \
;; \
*) \
Expand Down
12 changes: 6 additions & 6 deletions variants/1.4.4-restic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ RUN set -eux; \
RESTIC_VERSION=v0.15.1; \
case "$( uname -m )" in \
'x86') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_386.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_386.bz2"; \
SHA256=50362f6c4c2d91cf0edc750c578b73605fdbb79443874110cc0a64913553f76b; \
;; \
'x86_64') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_amd64.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_amd64.bz2"; \
SHA256=3631e3c3833c84ba71f22ea3df20381676abc7476a7f6d14424d9abfada91414; \
;; \
'armhf') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2"; \
SHA256=1a5c1d2a3b17aa381c318b3f3919f7cfc4cd430c3a2c3053ba055fb4ccf38c97; \
;; \
'armv7l') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm.bz2"; \
SHA256=1a5c1d2a3b17aa381c318b3f3919f7cfc4cd430c3a2c3053ba055fb4ccf38c97; \
;; \
'aarch64') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm64.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_arm64.bz2"; \
SHA256=bf6e09743df6899a02f0647d899fb008932760ea872667287bbc47b42091a3b0; \
;; \
's390x') \
URL=https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_s390x.bz2; \
URL="https://github.com/restic/restic/releases/download/v0.15.1/restic_0.15.1_linux_s390x.bz2"; \
SHA256=1ed7632518a86fa468f5823d6da4826d1787845cc0969a46da110c98139a3db4; \
;; \
*) \
Expand Down

0 comments on commit 799ce7b

Please sign in to comment.