#!/bin/sh # SPDX-License-Identifier: CC0-1.0 # Copyright (C) 2023 Wojtek Kosior set -eu cd "$(dirname "$0")" WORKDIR=/tmp/guix-koszko-update-hashes-workdir mkdir -p $WORKDIR FILES_AND_URLS="$(grep -E 'url "https://git.koszko.org' gnu/packages/*.scm)" while [ x != "x$FILES_AND_URLS" ] do : LINE="$(printf '%s' "$FILES_AND_URLS" | head -1)" FILES_AND_URLS="$(printf '%s' "$FILES_AND_URLS" | tail -n +2)" FILENAME="$(printf '%s' "$LINE" | awk -F : '{print $1}')" REPO="$(printf '%s' "$LINE" | sed 's|.*git.koszko.org/\([^/"]*\).*|\1|')" REPODIR=$WORKDIR/$REPO rm -rf $REPODIR git clone http://localhost:8098/$REPO $REPODIR CONTENT_HASH=$(guix hash \ --hash=sha256 \ --serializer=nar \ --format=nix-base32 \ --exclude-vcs \ $REPODIR) HEAD=$(awk '/^ref: /{print $2;}' $REPODIR/.git/HEAD) COMMIT_HASH=$(cat $REPODIR/.git/$HEAD) export REPO export CONTENT_HASH export COMMIT_HASH gawk -F '"' \ 'BEGIN {inside_right_package = 0;} {if (inside_right_package) { printed = 1; if (match($0, /"[0-9a-z]{52}"/)) print(gensub(/[0-9a-z]{52}/, ENVIRON["CONTENT_HASH"], 1)); else if (match($0, /"[0-9a-z]{40}"/)) print(gensub(/[0-9a-z]{40}/, ENVIRON["COMMIT_HASH"], 1)); else print $0; } else { print $0; } if (index($0, "git.koszko.org/" ENVIRON["REPO"])) inside_right_package = 1; } /\(license/ {inside_right_package = 0;}' \ $FILENAME > $WORKDIR/modified-file.scm mv $WORKDIR/modified-file.scm $FILENAME done rm -rf $WORKDIR