pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / by-name / im / immich / update.sh
bloba1a5e2e0585c32cbda8f41a7972e303dff18166c
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq prefetch-npm-deps nix-prefetch-github coreutils
4 set -euo pipefail
5 cd "$(dirname "${BASH_SOURCE[0]}")"
7 old_version=$(jq -r ".version" sources.json || echo -n "0.0.1")
8 version=$(curl -s "https://api.github.com/repos/immich-app/immich/releases/latest" | jq -r ".tag_name")
9 version="${version#v}"
11 echo "Updating to $version"
13 if [[ "$old_version" == "$version" ]]; then
14 echo "Already up to date!"
15 exit 0
18 echo "Fetching src"
19 src_hash=$(nix-prefetch-github immich-app immich --rev "v${version}" | jq -r .hash)
20 upstream_src="https://raw.githubusercontent.com/immich-app/immich/v$version"
22 sources_tmp="$(mktemp)"
23 cat <<EOF > "$sources_tmp"
25 "version": "$version",
26 "hash": "$src_hash",
27 "components": {}
29 EOF
31 lock=$(mktemp)
32 for 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"
41 done
43 rm "$lock"
44 mv "$sources_tmp" sources.json