Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / applications / emulators / citra / update.sh
blobe76121dac6ee4d63e811e0556c610957cb2170a4
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p nix nix-prefetch-git coreutils curl jq gnused
4 set -euo pipefail
6 # Will be replaced with the actual branch when running this from passthru.updateScript
7 BRANCH="@branch@"
9 if [[ ! "$(basename $PWD)" = "citra" ]]; then
10 echo "error: Script must be ran from citra's directory!"
11 exit 1
14 getLocalVersion() {
15 pushd ../../../.. >/dev/null
16 nix eval --raw -f default.nix "$1".version
17 popd >/dev/null
20 getLocalHash() {
21 pushd ../../../.. >/dev/null
22 nix eval --raw -f default.nix "$1".src.drvAttrs.outputHash
23 popd >/dev/null
26 updateNightly() {
27 OLD_NIGHTLY_VERSION="$(getLocalVersion "citra-nightly")"
28 OLD_NIGHTLY_HASH="$(getLocalHash "citra-nightly")"
30 NEW_NIGHTLY_VERSION="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
31 "https://api.github.com/repos/citra-emu/citra-nightly/releases?per_page=1" | jq -r '.[0].name' | cut -d"-" -f2 | cut -d" " -f2)"
33 if [[ "${OLD_NIGHTLY_VERSION}" = "${NEW_NIGHTLY_VERSION}" ]]; then
34 echo "citra-nightly is already up to date!"
36 [ "$KEEP_GOING" ] && return || exit
37 else
38 echo "citra-nightly: ${OLD_NIGHTLY_VERSION} -> ${NEW_NIGHTLY_VERSION}"
41 echo " Fetching source code..."
43 NEW_NIGHTLY_HASH="$(nix-prefetch-git --quiet --fetch-submodules --rev "nightly-${NEW_NIGHTLY_VERSION}" "https://github.com/citra-emu/citra-nightly" | jq -r '.sha256')"
45 echo " Successfully fetched. hash: ${NEW_NIGHTLY_HASH}"
47 sed -i "s|${OLD_NIGHTLY_VERSION}|${NEW_NIGHTLY_VERSION}|" ./default.nix
48 sed -i "s|${OLD_NIGHTLY_HASH}|${NEW_NIGHTLY_HASH}|" ./default.nix
51 updateCanary() {
52 OLD_CANARY_VERSION="$(getLocalVersion "citra-canary")"
53 OLD_CANARY_HASH="$(getLocalHash "citra-canary")"
55 NEW_CANARY_VERSION="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
56 "https://api.github.com/repos/citra-emu/citra-canary/releases?per_page=1" | jq -r '.[0].name' | cut -d"-" -f2 | cut -d" " -f1)"
58 if [[ "${OLD_CANARY_VERSION}" = "${NEW_CANARY_VERSION}" ]]; then
59 echo "citra-canary is already up to date!"
61 [ "$KEEP_GOING" ] && return || exit
62 else
63 echo "citra-canary: ${OLD_CANARY_VERSION} -> ${NEW_CANARY_VERSION}"
66 echo " Fetching source code..."
68 NEW_CANARY_HASH="$(nix-prefetch-git --quiet --fetch-submodules --rev "canary-${NEW_CANARY_VERSION}" "https://github.com/citra-emu/citra-canary" | jq -r '.sha256')"
70 echo " Successfully fetched. hash: ${NEW_CANARY_HASH}"
72 sed -i "s|${OLD_CANARY_VERSION}|${NEW_CANARY_VERSION}|" ./default.nix
73 sed -i "s|${OLD_CANARY_HASH}|${NEW_CANARY_HASH}|" ./default.nix
76 if [[ "$BRANCH" = "nightly" ]]; then
77 updateNightly
78 elif [[ "$BRANCH" = "early-access" ]]; then
79 updateCanary
80 else
81 KEEP_GOING=1
82 updateNightly
83 updateCanary