btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / os / osu-lazer-bin / update.sh
blob0b06950762b5193f32f7fba9b01dbf9b42f04cba
1 #!/usr/bin/env nix-shell
2 #!nix-shell -I nixpkgs=./. -i bash -p unzip curl jq common-updater-scripts
3 set -eo pipefail
4 cd "$(dirname "${BASH_SOURCE[0]}")"
6 bin_file="$(realpath ./package.nix)"
8 new_version="$(curl -s "https://api.github.com/repos/ppy/osu/releases?per_page=1" | jq -r '.[0].name')"
9 old_version="$(sed -nE 's/\s*version = "(.*)".*/\1/p' ./package.nix)"
10 if [[ "$new_version" == "$old_version" ]]; then
11 echo "Already up to date."
12 exit 0
15 cd ../../../..
17 echo "Updating osu-lazer-bin from $old_version to $new_version..."
18 sed -Ei.bak '/ *version = "/s/".+"/"'"$new_version"'"/' "$bin_file"
19 rm "$bin_file.bak"
21 for pair in \
22 'aarch64-darwin osu.app.Apple.Silicon.zip' \
23 'x86_64-darwin osu.app.Intel.zip' \
24 'x86_64-linux osu.AppImage'; do
25 set -- $pair
26 echo "Prefetching binary for $1..."
27 prefetch_output=$(nix --extra-experimental-features nix-command store prefetch-file --json --hash-type sha256 "https://github.com/ppy/osu/releases/download/$new_version/$2")
28 if [[ "$1" == *"darwin"* ]]; then
29 store_path=$(jq -r '.storePath' <<<"$prefetch_output")
30 tmpdir=$(mktemp -d)
31 unzip -q "$store_path" -d "$tmpdir"
32 hash=$(nix --extra-experimental-features nix-command hash path "$tmpdir")
33 rm -r "$tmpdir"
34 else
35 hash=$(jq -r '.hash' <<<"$prefetch_output")
37 echo "$1 ($2): hash = $hash"
38 sed -Ei.bak '/ *'"$1"' = /{N;N; s@("sha256-)[^;"]+@"'"$hash"'@}' "$bin_file"
39 rm "$bin_file.bak"
40 done