about summary refs log tree commit diff
path: root/pkgs/servers/search/typesense/update.sh
blob: c6d733181cd399b5882a82de6ac3c39021e5804b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq nix-prefetch common-updater-scripts nix coreutils
# shellcheck shell=bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"

old_version=$(jq -r ".version" sources.json || echo -n "0.0.1")
version=$(curl -s "https://api.github.com/repos/typesense/typesense/releases/latest" | jq -r ".tag_name")
version="${version#v}"

if [[ "$old_version" == "$version" ]]; then
    echo "Already up to date!"
    exit 0
fi

declare -A platforms=(
    [aarch64-linux]="linux-arm64"
    [x86_64-darwin]="darwin-amd64"
    [x86_64-linux]="linux-amd64"
)

sources_tmp="$(mktemp)"
cat <<EOF > "$sources_tmp"
{
  "version": "$version",
  "platforms": {}
}
EOF

for platform in "${!platforms[@]}"; do
    arch="${platforms[$platform]}"
    url="https://dl.typesense.org/releases/${version}/typesense-server-${version}-${arch}.tar.gz"
    sha256hash="$(nix-prefetch-url --type sha256 "$url")"
    hash="$(nix hash to-sri --type sha256 "$sha256hash")"
    echo "$(jq --arg arch "$arch" \
      --arg platform "$platform" \
      --arg hash "$hash" \
      '.platforms += {($platform): {arch: $arch, hash: $hash}}' \
      "$sources_tmp")" > "$sources_tmp"
done

cp "$sources_tmp" sources.json