summaryrefslogtreecommitdiff
path: root/koszko-update-hashes.sh
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2023-12-12 17:27:58 +0100
committerWojtek Kosior <koszko@koszko.org>2023-12-12 18:29:22 +0100
commit14d9bab290b1356c856631ebcbb460fffeecb943 (patch)
tree38f9f13ade5ad4761affc69a49d9ddd8f231e783 /koszko-update-hashes.sh
downloadguix-14d9bab290b1356c856631ebcbb460fffeecb943.tar.gz
guix-14d9bab290b1356c856631ebcbb460fffeecb943.zip
Initial commit.
Diffstat (limited to 'koszko-update-hashes.sh')
-rwxr-xr-xkoszko-update-hashes.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/koszko-update-hashes.sh b/koszko-update-hashes.sh
new file mode 100755
index 0000000000..6bdcd0c5cf
--- /dev/null
+++ b/koszko-update-hashes.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+# SPDX-License-Identifier: CC0-1.0
+# Copyright (C) 2023 Wojtek Kosior <koszko@koszko.org>
+
+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