From f867bcdb21c4f6cd583bfda2c18e4fca6577fde0 Mon Sep 17 00:00:00 2001 From: Ali Riza KESKIN Date: Sat, 20 Jun 2026 13:24:59 +0300 Subject: [PATCH] add update sha256sums script --- update-sums.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 update-sums.sh diff --git a/update-sums.sh b/update-sums.sh new file mode 100755 index 00000000..e8b4e047 --- /dev/null +++ b/update-sums.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +set -euo pipefail + +DOWNLOAD_DIR="/tmp/ymp-downloads/" + +mkdir -p "$DOWNLOAD_DIR" + +cd "$(dirname "$0")" + +update_ympbuild() { + local f="$1" + local pkg ver name sum_var url hash + local -a source_urls checksums + + pkg="$(basename "$(dirname "$f")")" + ver="$( sed -n "/^version=/{ s/^version='//; s/'.*//; p; q }" "$f")" + name="$( sed -n "/^name=/{ s/^name='//; s/'.*//; p; q }" "$f")" + [ -z "$ver" ] && { echo " skip $pkg (no version)"; return; } + [ -z "$name" ] && name="$pkg" + sum_var="$([[ -f "$f" ]] && grep -q "^md5sums=" "$f" && echo "md5sums" || echo "sha256sums")" + + # Get all source URLs by sourcing the ympbuild with bash -c + # Bash naturally expands all variables ($version, ${name}, etc.) + source_urls=() + while IFS= read -r -d '' url; do + source_urls+=("$url") + done < <(bash -c "source '$f' &>/dev/null; printf '%s\0' \"\${source[@]}\"" 2>/dev/null || true) + + [ ${#source_urls[@]} -eq 0 ] && { echo " skip $pkg (no source URLs)"; return; } + + checksums=() + for url in "${source_urls[@]}"; do + # Skip local files (no protocol scheme) + if [[ "$url" != *"://"* ]]; then + checksums+=("SKIP") + continue + fi + + filename="${url##*/}" + local dest="$DOWNLOAD_DIR/$filename" + + if [ ! -f "$dest" ]; then + echo " DL $filename" + curl --progress-bar \ + -fsSL -o "$dest" "$url" || { + echo " FAIL $pkg (download $url)" + checksums+=("SKIP") + continue + } + else + echo " CACHE $filename" + fi + + if [ "$sum_var" = "md5sums" ]; then + hash="$(md5sum "$dest" | cut -d' ' -f1)" + else + hash="$(sha256sum "$dest" | cut -d' ' -f1)" + fi + checksums+=("$hash") + done + + # Build new checksum array string + local new_sums="(" + for h in "${checksums[@]}"; do + new_sums+=" '$h'" + done + new_sums+=" )" + + # Replace old checksum block in the file + if grep -qE "^${sum_var}=\([^)]*\)" "$f"; then + # Single-line format: sha256sums=('hash1' 'hash2' ...) + sed -i "s|^${sum_var}=.*|${sum_var}=${new_sums}|" "$f" + else + # Multi-line format: replaces from ^sha256sums=( to the closing ) + sed -i "/^${sum_var}=/,/^)/c\\${sum_var}=${new_sums}" "$f" + fi + echo " OK $pkg ${#checksums[@]} checksums updated" +} + +find "$1" -type f -iname 'ympbuild' | while read ympbuild ; do + update_ympbuild "$ympbuild" +done