@@ -4,10 +4,20 @@ function global:Set-Checksums($k, $url) {
44 $global :CHECKSUMS [$k ] = if ($global :CHECKSUMS [$k ]) { $global :CHECKSUMS [$k ] } else { [System.Text.Encoding ]::UTF8.GetString( (Invoke-WebRequest $url ).Content ) -split " `n " }
55}
66function global :Get-ChecksumsFile ($k , $keyword ) {
7- $global :CHECKSUMS [$k ] | ? { $_ -match $keyword } | % { $_ -split " \s" } | Select-Object - Last 1 | % { $_.TrimStart (' *' ) }
7+ $file = $global :CHECKSUMS [$k ] | ? { $_ -match $keyword } | % { $_ -split " \s" } | Select-Object - Last 1 | % { $_.TrimStart (' *' ) }
8+ if ($file ) {
9+ $file
10+ }else {
11+ " No file among $k checksums matching regex: $keyword " | Write-Warning
12+ }
813}
914function global :Get-ChecksumsSha ($k , $keyword ) {
10- $global :CHECKSUMS [$k ] | ? { $_ -match $keyword } | % { $_ -split " \s" } | Select-Object - First 1
15+ $sha = $global :CHECKSUMS [$k ] | ? { $_ -match $keyword } | % { $_ -split " \s" } | Select-Object - First 1
16+ if ($sha ) {
17+ $sha
18+ }else {
19+ " No sha among $k checksums matching regex: $keyword " | Write-Warning
20+ }
1121}
1222
1323# Global functions
@@ -18,64 +28,70 @@ function global:Generate-DownloadBinary ($o) {
1828 $checksumsUrl = " $releaseUrl /$ ( $o [' checksums' ] ) "
1929 Set-Checksums $o [' binary' ] $checksumsUrl
2030
21- $binaryUpper = $ o [' binary' ].ToUpper()
31+ $shellVariable = " $ ( $ o [' binary' ].ToUpper() -replace ' [^A-Za-z0-9_] ' , ' _ ' ) _VERSION "
2232@"
2333# Install $ ( $o [' binary' ] )
2434RUN set -eux; \
25- export $ ( $binaryUpper ) _VERSION=" $ ( $o [' version' ] ) " ; \
35+ $shellVariable = $ ( $o [' version' ] ) ; \
2636 case "`$ ( uname -m )" in \
2737
2838"@
39+
40+ $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' }
2941 foreach ($a in ($o [' architectures' ] -split ' ,' ) ) {
3042 $split = $a -split ' /'
3143 $os = $split [0 ]
3244 $arch = $split [1 ]
3345 $archv = if ($split.Count -gt 2 ) { $split [2 ] } else { ' ' }
3446 switch ($a ) {
3547 " $os /386" {
36- $regex = " $os [-_](i?$arch |x86)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
3748 $hardware = ' x86'
49+ $regex = " $os [-_](i?$arch |x86(_64)?)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
3850 }
3951 " $os /amd64" {
40- $regex = " $os [-_]($arch |x86_64)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
4152 $hardware = ' x86_64'
53+ $regex = " $os [-_]($arch |x86(_64)?)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
4254 }
4355 " $os /arm/v6" {
44- $regex = " $os [-_]($arch |arm)[-_]?($archv )?$ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
4556 $hardware = ' armhf'
57+ $regex = " $os [-_]($arch |arm)[-_]?($archv )?$ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
4658 }
4759 " $os /arm/v7" {
48- $regex = " $os [-_]($arch |arm)[-_]?($archv )?$ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
4960 $hardware = ' armv7l'
61+ $regex = " $os [-_]($arch |arm)[-_]?($archv )?$ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
5062 }
5163 " $os /arm64" {
52- $regex = " $os [-_]($arch |aarch64)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
5364 $hardware = ' aarch64'
65+ $regex = " $os [-_]($arch |aarch64)[-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
5466 }
5567 " $os /ppc64le" {
56- $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
5768 $hardware = ' ppc64le'
69+ $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
5870 }
5971 " $os /riscv64" {
60- $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
6172 $hardware = ' riscv64'
73+ $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
6274 }
6375 " $os /s390x" {
64- $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
6576 $hardware = ' s390x'
77+ $regex = " $os [-_]$arch [-_]?$archv $ ( [regex ]::Escape($o [' archiveformat' ]) ) $"
6678 }
6779 default {
6880 throw " Unsupported architecture: $a "
6981 }
7082 }
7183
84+ $file = Get-ChecksumsFile $o [' binary' ] $regex
85+ if ($file ) {
86+ $sha = Get-ChecksumsSha $o [' binary' ] $regex
7287@"
73- '$hardware ') \
74- URL=$releaseUrl /$ ( Get-ChecksumsFile $o [ ' binary ' ] $regex ) ; \
75- SHA256=$ ( Get-ChecksumsSha $o [ ' binary ' ] $regex ) ; \
88+ '$hardware ') \
89+ URL=$releaseUrl /$file ; \
90+ SHA256=$sha ; \
7691 ;; \
7792
7893"@
94+ }
7995 }
8096
8197@"
@@ -119,14 +135,13 @@ RUN set -eux; \
119135 gzip -d "`$ FILE"; \
120136
121137"@
122- }else {
123- throw " Invalid 'archiveformat'. Supported formats: .tar.gz, .tgz, .bz2, .gz"
124138 }
125139
140+ $destination = if ($o.Contains (' destination' )) { $o [' destination' ] } else { " /usr/local/bin/$ ( $o [' binary' ] ) " }
126141@"
127- mv -v $ ( $o [' binary' ] ) /usr/local/bin/ $ ( $o [ ' binary ' ] ) ; \
128- chmod +x /usr/local/bin/ $ ( $o [ ' binary ' ] ) ; \
129- $ ( $o [' binary ' ] ) $ ( $o [ ' versionSubcommand ' ] ) ; \
142+ mv -v $ ( $o [' binary' ] ) $destination ; \
143+ chmod +x $destination ; \
144+ $ ( $o [' testCommand ' ] ) ; \
130145
131146"@
132147
@@ -192,7 +207,7 @@ foreach ($c in $VARIANT['_metadata']['components']) {
192207 )
193208 checksums = ' pingme_checksums.txt'
194209 architectures = $VARIANT [' _metadata' ][' platforms' ]
195- versionSubcommand = ' --version'
210+ testCommand = ' pingme --version'
196211 }
197212 }
198213
@@ -204,7 +219,7 @@ foreach ($c in $VARIANT['_metadata']['components']) {
204219 archiveformat = ' .bz2'
205220 checksums = ' SHA256SUMS'
206221 architectures = $VARIANT [' _metadata' ][' platforms' ]
207- versionSubcommand = ' version'
222+ testCommand = ' restic version'
208223 }
209224 }
210225}
0 commit comments