Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 62 lines 2.2 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils ripgrep 3 4set -euo pipefail 5cd "$(dirname "${BASH_SOURCE[0]}")" 6 7old_version=$(jq -r ".version" sources.json || echo -n "0.0.1") 8version=$(curl -s "https://api.github.com/repos/immich-app/immich/releases/latest" | jq -r ".tag_name") 9version="${version#v}" 10 11echo "Updating to $version" 12 13if [[ "$old_version" == "$version" ]]; then 14 echo "Already up to date!" 15 exit 0 16fi 17 18echo "Fetching src" 19src_hash=$(nix-prefetch-github immich-app immich --rev "v${version}" | jq -r .hash) 20upstream_src="https://raw.githubusercontent.com/immich-app/immich/v$version" 21 22sources_tmp="$(mktemp)" 23cat <<EOF > "$sources_tmp" 24{ 25 "version": "$version", 26 "hash": "$src_hash", 27 "components": {} 28} 29EOF 30 31lock=$(mktemp) 32for npm_component in cli server web "open-api/typescript-sdk"; do 33 echo "fetching $npm_component" 34 curl -s -o "$lock" "$upstream_src/$npm_component/package-lock.json" 35 hash=$(prefetch-npm-deps "$lock") 36 echo "$(jq --arg npm_component "$npm_component" \ 37 --arg hash "$hash" \ 38 --arg version "$(jq -r '.version' <"$lock")" \ 39 '.components += {($npm_component): {npmDepsHash: $hash, version: $version}}' \ 40 "$sources_tmp")" > "$sources_tmp" 41done 42rm "$lock" 43 44url="http://download.geonames.org/export/dump" 45curl -s "http://web.archive.org/save/$url/cities500.zip" 46curl -s "http://web.archive.org/save/$url/admin1CodesASCII.txt" 47curl -s "http://web.archive.org/save/$url/admin1Codes.txt" 48timestamp=$(curl -s \ 49 "http://archive.org/wayback/available?url=$url/cities500.zip" \ 50 | jq -r ".archived_snapshots.closest.timestamp") 51echo "$(jq --arg timestamp "$timestamp" --arg hash "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" \ 52 '.components += {geonames: {timestamp: $timestamp, hash: $hash}}' \ 53 "$sources_tmp")" > "$sources_tmp" 54 55cp "$sources_tmp" sources.json 56set +o pipefail 57output="$(nix-build ../../../.. -A immich.geodata 2>&1 || true)" 58set -o pipefail 59hash=$(echo "$output" | rg 'got:\s+(sha256-.*)$' -or '$1') 60echo "$(jq --arg hash "$hash" '.components.geonames.hash = $hash' "$sources_tmp")" > "$sources_tmp" 61 62mv "$sources_tmp" sources.json