Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env nix-shell 2#!nix-shell --packages curl 3#!nix-shell --packages jq 4#!nix-shell --packages parallel 5#!nix-shell -i bash 6 7# Exit immediately if a command exits with a non-zero status. 8# Exit when a producer fails in a pipe 9# Treat undefined variable references as errors 10set -e -o pipefail -u 11 12# Check if working directory is (probably) right 13test "./update" = $0 || { 14 echo "The working directory ought to be the same is the update script location. Please invoke as ./update" 1>&2 15 exit 1 16} 17 18# Create temporary directory with automatic cleanup 19readonly MY_TMP="$(mktemp -d)" 20cleanup () { 21 rm -rf "$MY_TMP" 22} 23trap cleanup EXIT 24 25# stdout: file containing release info and a convenient placeholder 26# for the sha256 attribute 27getRelease () { 28 local owner="$1" 29 local repo="$2" 30 local out="$MY_TMP/$owner--$repo-release" 31 curl -fSs https://api.github.com/repos/"$owner"/"$repo"/releases/latest \ 32 | jq '{ version: .name, url: .tarball_url, sha256: "__SHA256__" }' \ 33 > "$out" 34 echo "$out" 35} 36 37# 'getters' for the release info file 38 39# stdout: unquoted tarball url 40releaseUrl () { 41 local file="$1" 42 jq -r '.url' <"$file" 43} 44 45# stdout: unquoted version 46releaseVersion () { 47 local file="$1" 48 jq -r '.version' <"$file" 49} 50 51# Fetch release tarball and compute hash 52# stdout: base32 sha256 to be used in fetchurl 53getReleaseHash () { 54 local file="$1" 55 local name="$2" 56 nix-prefetch-url "$(releaseUrl "$file")" --name "$name-$(releaseVersion "$file").tar.gz" 57} 58 59# Write a release info file to release-info/$owner-$repo.json 60updateRelease () { 61 local owner="$1" 62 local repo="$2" 63 local r="$(getRelease "$owner" "$repo")" 64 local hash="$(getReleaseHash "$r" "$repo")" 65 sed \ 66 -e s/__SHA256__/"$hash"/\ 67 <"$r" \ 68 >"release-info/$owner-$repo.json" 69} 70 71updateRelease LanguageMachines frogdata 72updateRelease LanguageMachines frog 73updateRelease LanguageMachines libfolia 74updateRelease LanguageMachines mbt 75updateRelease LanguageMachines ticcutils 76updateRelease LanguageMachines timbl 77updateRelease LanguageMachines timblserver 78updateRelease LanguageMachines ucto 79updateRelease LanguageMachines uctodata