1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq nix-prefetch common-updater-scripts nix coreutils
3 # shellcheck shell=bash
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/typesense/typesense/releases/latest" | jq
-r ".tag_name")
11 if [[ "$old_version" == "$version" ]]; then
12 echo "Already up to date!"
16 declare -A platforms
=(
17 [aarch64-linux
]="linux-arm64"
18 [aarch64-darwin
]="darwin-arm64"
19 [x86_64-darwin
]="darwin-amd64"
20 [x86_64-linux
]="linux-amd64"
23 sources_tmp
="$(mktemp)"
24 cat <<EOF > "$sources_tmp"
26 "version": "$version",
31 for platform
in "${!platforms[@]}"; do
32 arch
="${platforms[$platform]}"
33 url
="https://dl.typesense.org/releases/${version}/typesense-server-${version}-${arch}.tar.gz"
34 sha256hash
="$(nix-prefetch-url --type sha256 "$url")"
35 hash="$(nix hash to-sri --type sha256 "$sha256hash")"
36 echo "$(jq --arg arch "$arch" \
37 --arg platform "$platform" \
39 '.platforms += {($platform): {arch: $arch, hash: $hash}}' \
40 "$sources_tmp")" > "$sources_tmp"
43 cp "$sources_tmp" sources.json