From d167d728f53c4dd245755886f0e8cd9a7398b039 Mon Sep 17 00:00:00 2001 From: Jonas8272 Date: Fri, 20 Nov 2026 19:14:59 +0000 Subject: [PATCH] should fare better against renames --- scripts/update-mornye.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/scripts/update-mornye.sh b/scripts/update-mornye.sh index aba614f..06040b1 100644 --- a/scripts/update-mornye.sh +++ b/scripts/update-mornye.sh @@ -14,27 +14,32 @@ if [ "$ver" = "$cur" ]; then fi base="https://github.com/$REPO/releases/download/$tag" -sums=$(curl -fsSL "$base/SHA256SUMS.txt") +sums=$(curl -fsSL "$base/SHA256SUMS.txt" | tr -d '\r') -hash_of() { - echo "$sums" | awk -v f="$1" '{n=$2; sub(/^\*/,"",n); if (n==f) print $1}' +# Print " " for the one file matching the pattern, else fail. +find_asset() { + local m + m=$(echo "$sums" | awk '{n=$2; sub(/^\*/,"",n); print $1, n}' | grep -E "$1" || true) + if [ "$(echo "$m" | grep -c .)" -ne 1 ]; then + echo "expected exactly one match for /$1/ in SHA256SUMS.txt for $tag, got:" >&2 + echo "$m" >&2 + exit 1 + fi + echo "$m" } -x64=$(hash_of "Mornye-$tag-windows-x64-portable.zip") -arm=$(hash_of "Mornye-$tag-windows-arm64-portable.zip") - -if [ -z "$x64" ] || [ -z "$arm" ]; then - echo "hash not found in SHA256SUMS.txt for $tag" >&2 - exit 1 -fi +x64=$(find_asset 'windows-x64-portable.*\.zip$') +arm=$(find_asset 'windows-arm64-portable.*\.zip$') +x64_hash=${x64%% *}; x64_name=${x64#* } +arm_hash=${arm%% *}; arm_name=${arm#* } jq --indent 4 \ - --arg v "$ver" --arg x "$x64" --arg a "$arm" \ - --arg ux "$base/Mornye-$tag-windows-x64-portable.zip" \ - --arg ua "$base/Mornye-$tag-windows-arm64-portable.zip" \ + --arg v "$ver" \ + --arg xh "$x64_hash" --arg xu "$base/$x64_name" \ + --arg ah "$arm_hash" --arg au "$base/$arm_name" \ '.version=$v - | .architecture["64bit"].url=$ux | .architecture["64bit"].hash=$x - | .architecture.arm64.url=$ua | .architecture.arm64.hash=$a' \ + | .architecture["64bit"].url=$xu | .architecture["64bit"].hash=$xh + | .architecture.arm64.url=$au | .architecture.arm64.hash=$ah' \ "$M" > "$M.tmp" && mv "$M.tmp" "$M" echo "updated $cur -> $ver" \ No newline at end of file