summary refs log tree commit diff
path: root/pkgs/applications/emulators/yuzu/update.sh
blob: 270164902c115c127ceb688f9e7e9aab97166c79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p nix nix-prefetch-git coreutils curl jq gnused

set -e

# Will be replaced with the actual branch when running this from passthru.updateScript
BRANCH="@branch@"

if [[ ! "$(basename $PWD)" = "yuzu" ]]; then
    echo "error: Script must be ran from yuzu's directory!"
    exit 1
fi

getLocalVersion() {
    pushd ../../../.. >/dev/null
    nix eval --raw -f default.nix "$1".version
    popd >/dev/null
}

getLocalHash() {
    pushd ../../../.. >/dev/null
    nix eval --raw -f default.nix "$1".src.drvAttrs.outputHash
    popd >/dev/null
}

updateCompatList() {
    NEW_COMPAT_LIST="$(curl -s "https://api.yuzu-emu.org/gamedb")"

    if [[ "$(cat ./compatibility-list.json)" = "${NEW_COMPAT_LIST}" ]]; then
        echo "Compatibility list is already up to date!"
    else
        local TODAY="$(date +"%Y-%m-%d")"

        echo "Compatibility list: updated to $TODAY"
        echo "${NEW_COMPAT_LIST}" > ./compatibility-list.json

        sed -i -e "s/last updated .*/last updated $TODAY./" ./default.nix
    fi
}

updateMainline() {
    OLD_MAINLINE_VERSION="$(getLocalVersion "yuzu-mainline")"
    OLD_MAINLINE_HASH="$(getLocalHash "yuzu-mainline")"

    NEW_MAINLINE_VERSION="$(curl -s ${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
        "https://api.github.com/repos/yuzu-emu/yuzu-mainline/releases?per_page=1" | jq -r '.[0].name' | cut -d" " -f2)"

    if [[ "${OLD_MAINLINE_VERSION}" = "${NEW_MAINLINE_VERSION}" ]]; then
        echo "yuzu-mainline is already up to date!"

        [ "$KEEP_GOING" ] && return || exit
    else
        echo "yuzu-mainline: ${OLD_MAINLINE_VERSION} -> ${NEW_MAINLINE_VERSION}"
    fi

    echo "  Fetching source code..."

    NEW_MAINLINE_HASH="$(nix-prefetch-git --quiet --fetch-submodules --rev "mainline-0-${NEW_MAINLINE_VERSION}" "https://github.com/yuzu-emu/yuzu-mainline" | jq -r '.sha256')"

    echo "  Succesfully fetched. hash: ${NEW_MAINLINE_HASH}"

    sed -i "s/${OLD_MAINLINE_VERSION}/${NEW_MAINLINE_VERSION}/" ./default.nix
    sed -i "s/${OLD_MAINLINE_HASH}/${NEW_MAINLINE_HASH}/" ./default.nix
}

updateEarlyAccess() {
    OLD_EA_VERSION="$(getLocalVersion "yuzu-ea")"
    OLD_EA_HASH="$(getLocalHash "yuzu-ea")"

    NEW_EA_VERSION="$(curl -s ${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
        "https://api.github.com/repos/pineappleEA/pineapple-src/releases?per_page=1" | jq -r '.[0].name' | cut -d"-" -f2 | cut -d" " -f1)"

    if [[ "${OLD_EA_VERSION}" = "${NEW_EA_VERSION}" ]]; then
        echo "yuzu-ea is already up to date!"

        [ "$KEEP_GOING" ] && return || exit
    else
        echo "yuzu-ea: ${OLD_EA_VERSION} -> ${NEW_EA_VERSION}"
    fi

    echo "  Fetching source code..."

    NEW_EA_HASH="$(nix-prefetch-git --quiet --fetch-submodules --rev "EA-${NEW_EA_VERSION}" "https://github.com/pineappleEA/pineapple-src" | jq -r '.sha256')"

    echo "  Succesfully fetched. hash: ${NEW_EA_HASH}"

    sed -i "s/${OLD_EA_VERSION}/${NEW_EA_VERSION}/" ./default.nix
    sed -i "s/${OLD_EA_HASH}/${NEW_EA_HASH}/" ./default.nix
}

if [[ "$BRANCH" = "mainline" ]]; then
    updateMainline
    updateCompatList
elif [[ "$BRANCH" = "early-access" ]]; then
    updateEarlyAccess
    updateCompatList
else
    KEEP_GOING=1
    updateMainline
    updateEarlyAccess
    updateCompatList
fi