From 3342c13bffda2759da56236a6d9c3f343234d083 Mon Sep 17 00:00:00 2001 From: Matteo Pacini Date: Mon, 5 Aug 2024 23:13:49 +0100 Subject: [PATCH] pcsx2-bin: updated updateScript --- pkgs/by-name/pc/pcsx2-bin/package.nix | 3 +- pkgs/by-name/pc/pcsx2-bin/update.sh | 43 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 pkgs/by-name/pc/pcsx2-bin/update.sh diff --git a/pkgs/by-name/pc/pcsx2-bin/package.nix b/pkgs/by-name/pc/pcsx2-bin/package.nix index db8ddcb957db..cb38ebac1c76 100644 --- a/pkgs/by-name/pc/pcsx2-bin/package.nix +++ b/pkgs/by-name/pc/pcsx2-bin/package.nix @@ -3,7 +3,6 @@ stdenvNoCC, fetchurl, makeWrapper, - nix-update-script, }: stdenvNoCC.mkDerivation (finalAttrs: { @@ -31,7 +30,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { ''; passthru = { - updateScript = nix-update-script { }; + updateScript = ./update.sh; }; meta = { diff --git a/pkgs/by-name/pc/pcsx2-bin/update.sh b/pkgs/by-name/pc/pcsx2-bin/update.sh new file mode 100755 index 000000000000..872899694278 --- /dev/null +++ b/pkgs/by-name/pc/pcsx2-bin/update.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq gnused + +set -euo pipefail + +ROOT="$(dirname "$(readlink -f "$0")")" +if [[ ! "$(basename "$ROOT")" == "pcsx2-bin" || ! -f "$ROOT/package.nix" ]]; then + echo "error: Not in the pcsx2-bin folder" >&2 + exit 1 +fi + +PACKAGE_NIX="$ROOT/package.nix" + +# Grab latest (pre)release version +PCSX2_LATEST_VER="$(curl --fail -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} "https://api.github.com/repos/PCSX2/pcsx2/releases" | jq -r '.[0].tag_name' | sed 's/^v//')" +PCSX2_CURRENT_VER="$(grep -oP 'version = "\K[^"]+' "$PACKAGE_NIX")" + +if [[ "$PCSX2_LATEST_VER" == "$PCSX2_CURRENT_VER" ]]; then + echo "pcsx2-bin is up-to-date" + exit 0 +fi + +get_hash() { + # $1: URL + nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "$1")" +} + +replace_hash_in_file() { + # $1: file + # $2: new hash + sed -i "s#hash = \".*\"#hash = \"$2\"#g" "$1" +} + +replace_version_in_file() { + # $1: file + # $2: new version + sed -i "s#version = \".*\";#version = \"$2\";#g" "$1" +} + +PCSX2_DARWIN_HASH="$(get_hash "https://github.com/PCSX2/pcsx2/releases/download/v${PCSX2_LATEST_VER}/pcsx2-v${PCSX2_LATEST_VER}-macos-Qt.tar.xz")" + +replace_hash_in_file "$PACKAGE_NIX" "$PCSX2_DARWIN_HASH" +replace_version_in_file "$PACKAGE_NIX" "$PCSX2_LATEST_VER"