1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl gnugrep gnused jq yq-go
3
4set -x -eu -o pipefail
5
6cd $(dirname "${BASH_SOURCE[0]}")
7
8SPEC_VERSION=$(curl -s https://www.linode.com/docs/api/openapi.yaml | yq eval '.info.version' -)
9
10SPEC_SHA256=$(nix-prefetch-url --quiet https://raw.githubusercontent.com/linode/linode-api-docs/v${SPEC_VERSION}/openapi.yaml)
11
12VERSION=$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
13 -H "Accept: application/vnd.github.v3+json" \
14 "https://api.github.com/repos/linode/linode-cli/tags" \
15 | jq 'map(.name)' \
16 | grep '"' \
17 | sed 's/[ ",(^v)]//g' \
18 | grep -v -e rc -e list \
19 | cut -d '"' -f4 | sort -rV | head -n 1)
20
21SHA256=$(nix-prefetch-url --quiet --unpack https://github.com/linode/linode-cli/archive/refs/tags/v${VERSION}.tar.gz)
22
23setKV () {
24 sed -i "s|$1 = \".*\"|$1 = \"${2:-}\"|" ./default.nix
25}
26
27setKV specVersion ${SPEC_VERSION}
28setKV specHash ${SPEC_SHA256}
29setKV version ${VERSION}
30setKV hash ${SHA256}