librewolf: 132.0.1 -> 132.0.1-1 (#355483)
[NixPkgs.git] / pkgs / by-name / wa / warp-terminal / update.sh
blob2ea6f06b9e18a3864e201584cab42ce2e21aa64e
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p cacert curl jq nix moreutils --pure
3 #shellcheck shell=bash
4 set -eu -o pipefail
6 cd "$(dirname "$0")"
7 nixpkgs=../../../../.
9 err() {
10 echo "$*" >&2
11 exit 1
14 json_get() {
15 jq -r "$1" < "./versions.json"
18 json_set() {
19 jq --arg x "$2" "$1 = \$x" < "./versions.json" | sponge "./versions.json"
22 resolve_url() {
23 local pkg sfx url
24 local -i i max_redirects
25 case "$1" in
26 darwin)
27 pkg=macos
28 sfx=dmg
30 linux_x86_64)
31 pkg=pacman
32 sfx=pkg.tar.zst
34 linux_aarch64)
35 pkg=pacman_arm64
36 sfx=pkg.tar.zst
39 err "Unexpected download type: $1"
41 esac
42 url="https://app.warp.dev/download?package=${pkg}"
43 ((max_redirects = 15))
44 for ((i = 0; i < max_redirects; i++)); do
45 url=$(curl -s -o /dev/null -w '%{redirect_url}' "${url}")
46 [[ ${url} != *.${sfx} ]] || break
47 done
48 ((i < max_redirects)) || { err "too many redirects"; }
49 echo "${url}"
52 get_version() {
53 echo "$1" | grep -oP -m 1 '(?<=/v)[\d.\w]+(?=/)'
56 # nix-prefect-url seems to be uncompressing the archive then taking the hash
57 # so just get the hash from fetchurl
58 sri_get() {
59 local ouput sri
60 output=$(nix-build --expr \
61 "with import $nixpkgs {};
62 fetchurl {
63 url = \"$1\";
64 }" 2>&1 || true)
65 sri=$(echo "$output" | awk '/^\s+got:\s+/{ print $2 }')
66 [[ -z "$sri" ]] && err "$output"
67 echo "$sri"
71 for sys in darwin linux_x86_64 linux_aarch64; do
72 echo ${sys}
73 url=$(resolve_url ${sys})
74 version=$(get_version "${url}")
75 if [[ ${version} != "$(json_get ".${sys}.version")" ]]; then
76 sri=$(sri_get "${url}")
77 json_set ".${sys}.version" "${version}"
78 json_set ".${sys}.hash" "${sri}"
80 done