1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p wget yarn2nix-moretea.yarn2nix nix-prefetch-git jq
3
4set -euo pipefail
5
6dirname="$(dirname "$0")"
7
8latest_release=$(curl --silent https://api.github.com/repos/gotify/server/releases/latest)
9version=$(jq -r '.tag_name' <<<"$latest_release")
10echo got version $version
11echo \""${version#v}"\" > "$dirname/version.nix"
12printf '%s\n' $(nix-prefetch-git --quiet --rev ${version} https://github.com/gotify/server | jq .sha256) > $dirname/source-sha.nix
13tput setaf 1
14echo zeroing vendorSha256 in $dirname/vendor-sha.nix
15tput sgr0
16printf '"%s"\n' "0000000000000000000000000000000000000000000000000000" > $dirname/vendor-sha.nix
17
18GOTIFY_WEB_SRC="https://raw.githubusercontent.com/gotify/server/$version"
19
20curl --silent "$GOTIFY_WEB_SRC/ui/package.json" -o $dirname/package.json
21echo downloaded package.json
22curl --silent "$GOTIFY_WEB_SRC/ui/yarn.lock" -o $dirname/yarn.lock
23echo downloaded yarndeps.nix
24echo running yarn2nix
25yarn2nix --lockfile=$dirname/yarn.lock > $dirname/yarndeps.nix
26rm $dirname/yarn.lock
27echo removed yarn.lock
28
29echo running nix-build for ui
30nix-build -A gotify-server.ui
31echo running nix-build for gotify itself in order to get vendorSha256
32set +e
33vendorSha256="$(nix-build -A gotify-server 2>&1 | grep "got:" | cut -d':' -f2)"
34set -e
35printf '"%s"\n' "$vendorSha256" > $dirname/vendor-sha.nix
36tput setaf 2
37echo got vendorSha256 of: $vendorSha256
38tput sgr0
39echo running nix-build -A gotify-server which should build gotify-server normally
40nix-build -A gotify-server