@@ -191,29 +191,6 @@ verbose() {
191191# --- End of ./lib/colors.sh ---
192192
193193
194- # --- Sourced from file: ./lib/map.sh ---
195-
196- # map_put map_name key value
197- map_put() {
198- alias "${1}$2"="$3"
199- }
200-
201- # map_get map_name key
202- # @return value
203- map_get() {
204- alias "${1}$2" | awk -F"'" '{ print $2; }'
205- }
206-
207- # map_keys map_name
208- # @return map keys
209- map_keys() {
210- alias -p | grep $1 | cut -d'=' -f1 | awk -F"$1" '{print $2; }'
211- }
212-
213- # --- End of ./lib/map.sh ---
214-
215-
216-
217194# Setup variables
218195verbose="false"
219196if [ "$verbose" = "true" ]; then
@@ -295,161 +272,69 @@ verbose "$assets"
295272assetCount="$(echo "$assets" | wc -l | sed -E 's/^[[:space:]]*//')"
296273info "Found $assetCount assets in '$tagName' - searching for one that fits your system..."
297274
298- # Get architecture of host
299- arch="$(uname -m)"
300- # Convert arch to lowercase
301- arch="$(echo "$arch" | tr '[:upper:]' '[:lower:]')"
302- verbose "Host architecture: $arch"
303-
304- # Set aliases for architectures
305- amd64=("amd64" "x86_64" "x86-64" "x64")
306- amd32=("386" "i386" "i686" "x86")
307- arm=("arm" "armv7" "armv6" "armv8" "armv8l" "armv7l" "armv6l" "armv8l" "armv7l" "armv6l")
308-
309- currentArchAliases=()
310- # Set the right aliases for current host system
311- if [ "$arch" == "x86_64" ]; then
312- currentArchAliases=("${amd64[@]}")
313- elif [ "$arch" == "i386" ] || [ "$arch" == "i686" ]; then
314- currentArchAliases=("${amd32[@]}")
315- # Else if starts with "arm"
316- elif [[ "$arch" =~ ^arm ]]; then
317- currentArchAliases=("${arm[@]}")
275+ # Detect operating system and normalize it to the GoReleaser naming
276+ os="$(uname -s | tr '[:upper:]' '[:lower:]')"
277+ case "$os" in
278+ linux*) os="linux" ;;
279+ darwin*) os="darwin" ;;
280+ mingw* | msys* | cygwin*) os="windows" ;;
281+ *) error "Unsupported operating system: $os" ;;
282+ esac
283+ verbose "Detected OS: $os"
284+
285+ # Detect architecture and normalize it to the GoReleaser naming
286+ arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
287+ case "$arch" in
288+ x86_64 | amd64 | x64) arch="amd64" ;;
289+ aarch64 | arm64) arch="arm64" ;; # Raspberry Pi 3/4/5 on a 64-bit OS
290+ armv7* | armv7l) arch="armv7" ;; # Raspberry Pi 2/3 on 32-bit Pi OS
291+ armv6* | armv6l) arch="armv6" ;; # Raspberry Pi 1 / Zero
292+ arm) arch="armv7" ;; # bare "arm": assume armv7
293+ *) error "Unsupported architecture: $arch" ;;
294+ esac
295+ verbose "Detected architecture: $arch"
296+
297+ # Build the expected asset suffix. This MUST stay in sync with the
298+ # name_template in the project's .goreleaser.yaml, e.g.:
299+ # runal_0.10.0_linux_arm64.tar.gz
300+ # runal_0.10.0_linux_armv7.tar.gz
301+ # runal_0.10.0_windows_amd64.zip
302+ if [ "$os" == "windows" ]; then
303+ assetSuffix="_${os}_${arch}.zip"
318304else
319- error "Unsupported architecture: $arch"
320- fi
321- verbose "Current architecture aliases: ${currentArchAliases[*]}"
322-
323- # Get operating system of host
324- os="$(uname -s)"
325- # Convert os to lowercase
326- os="$(echo "$os" | tr '[:upper:]' '[:lower:]')"
327- verbose "Host operating system: $os"
328-
329- # Set aliases for operating systems
330- linux=("linux")
331- darwin=("darwin" "macos" "osx")
332-
333- currentOsAliases=()
334- # If current os is linux, add linux aliases to the curentOsAliases array
335- if [ "${os}" == "linux" ]; then
336- currentOsAliases+=("${linux[@]}")
337- elif [ "${os}" == "darwin" ]; then
338- currentOsAliases+=("${darwin[@]}")
305+ assetSuffix="_${os}_${arch}.tar.gz"
339306fi
340- verbose "Current operating system aliases: ${currentOsAliases[*]}"
341-
342- # Create map of assets and a score
343- for asset in $assets; do
344- score=0
345-
346- # Get file name from asset path
347- fileName="$(echo "$asset" | awk -F'/' '{ print $NF; }')"
348- # Set filename to lowercase
349- fileName="$(echo "$fileName" | tr '[:upper:]' '[:lower:]')"
350-
351- # Set score to one, if the file name contains the current os
352- for osAlias in "${currentOsAliases[@]}"; do
353- if [[ "${fileName}" == *"$osAlias"* ]]; then
354- score=10
355- break
356- fi
357- done
358-
359- # Add two to the score for every alias that matches the current architecture
360- for archAlias in "${currentArchAliases[@]}"; do
361- if [[ "${fileName}" == *"$archAlias"* ]]; then
362- verbose "Adding one to score for asset $fileName because it matches architecture $archAlias"
363- score=$((score + 2))
364- fi
365- done
366-
367- # Add one to the score if the file name contains .tar or .tar.gz or .tar.bz2
368- if [[ "$fileName" == *".tar" ]] || [[ "$fileName" == *".tar.gz" ]] || [[ "$fileName" == *".tar.bz2" ]]; then
369- verbose "Adding one to score for asset $fileName because it is a .tar or .tar.gz or .tar.bz2 file"
370- score=$((score + 1))
371- fi
372-
373- # Add two to the score if the file name contains the repo name
374- if [[ "$fileName" == *"$repo"* ]]; then
375- verbose "Adding two to score for asset $fileName because it contains the repo name"
376- score=$((score + 2))
377- fi
378-
379- # Add one to the score if the file name is exactly the repo name
380- if [[ "$fileName" == "$repo" ]]; then
381- verbose "Adding one to score for asset $fileName because it is exactly the repo name"
382- score=$((score + 1))
383- fi
307+ verbose "Looking for an asset ending in: ${assetSuffix}"
384308
385- # Initialize asset with score
386- map_put assets "$fileName" "$score"
387- done
388-
389- # Get map entry with highest score
390- verbose "Finding asset with highest score"
391- maxScore=0
392- maxKey=""
393- for asset in $(map_keys assets); do
394- score="$(map_get assets "$asset")"
395- if [ $score -gt $maxScore ]; then
396- maxScore=$score
397- maxKey=$asset
398- fi
399- verbose "Asset: $asset, score: $score"
400- done
401-
402- assetName="$maxKey"
403-
404- # Check if asset name is still empty
405- if [ -z "$assetName" ]; then
406- error "Could not find any assets that fit your system"
309+ # Find the matching asset URL (anchored to the end of the file name)
310+ assetURL="$(echo "$assets" | grep -i "${assetSuffix}\$" | head -n 1)"
311+ if [ -z "$assetURL" ]; then
312+ error "Could not find a release asset for ${os}/${arch} (looked for *${assetSuffix})"
407313fi
314+ assetName="$(echo "$assetURL" | awk -F'/' '{ print $NF; }')"
408315
409- # Get asset URL from release assets
410- assetURL="$(echo "$assets" | grep -i "$assetName")"
411-
412- info "Found asset with highest match score: $assetName"
316+ info "Found asset for your system (${os}/${arch}): $assetName"
413317
414318info "Downloading asset..."
415319# Download asset
416- downloadAssetArgs=$ curlOpts
320+ downloadAssetArgs=("${ curlOpts[@]}")
417321downloadAssetArgs+=(-L "$assetURL" -o "$tmpDir/$assetName")
418322verbose "${downloadAssetArgs[@]}"
419323curl "${downloadAssetArgs[@]}"
420324
421- # Unpack asset if it is compressed
422- if [[ "$assetName" == *".tar" ]]; then
423- verbose "Unpacking .tar asset to $tmpDir"
424- tar -xf "$tmpDir/$assetName" -C "$tmpDir"
425- verbose "Removing packed asset ($tmpDir/$assetName)"
426- rm "$tmpDir/$assetName"
427- elif [[ "$assetName" == *".tar.gz" ]]; then
325+ # Unpack asset (GoReleaser produces .tar.gz for linux/macOS, .zip for windows)
326+ if [[ "$assetName" == *".tar.gz" ]]; then
428327 verbose "Unpacking .tar.gz asset to $tmpDir"
429328 tar -xzf "$tmpDir/$assetName" -C "$tmpDir"
430329 verbose "Removing packed asset ($tmpDir/$assetName)"
431330 rm "$tmpDir/$assetName"
432- elif [[ "$assetName" == *".gz" ]]; then
433- verbose "Unpacking .gz asset to $tmpDir/$repo"
434- gunzip -c "$tmpDir/$assetName" >"$tmpDir/$repo"
435- verbose "Removing packed asset ($tmpDir/$assetName)"
436- rm "$tmpDir/$assetName"
437- verbose "Setting asset name to $repo, because it is a .gz file"
438- assetName="$repo"
439- verbose "Marking asset as executable"
440- chmod +x "$tmpDir/$repo"
441- elif [[ "$assetName" == *".tar.bz2" ]]; then
442- verbose "Unpacking .tar.bz2 asset to $tmpDir"
443- tar -xjf "$tmpDir/$assetName" -C "$tmpDir"
444- verbose "Removing packed asset"
445- rm "$tmpDir/$assetName"
446331elif [[ "$assetName" == *".zip" ]]; then
447- verbose "Unpacking .zip asset to $tmpDir/$repo "
332+ verbose "Unpacking .zip asset to $tmpDir"
448333 unzip "$tmpDir/$assetName" -d "$tmpDir" >/dev/null 2>&1
449334 verbose "Removing packed asset ($tmpDir/$assetName)"
450335 rm "$tmpDir/$assetName"
451336else
452- verbose "Asset is not a tar or zip file. Skipping unpacking. "
337+ error "Unexpected asset format: $assetName "
453338fi
454339
455340# If it was unpacked to a single directory, move the files to the root of the tmpDir
0 commit comments