From 67015516a99843b1c56d933a21ef5af1471217bf Mon Sep 17 00:00:00 2001 From: Moraxyc Date: Thu, 5 Dec 2024 16:10:16 +0800 Subject: [PATCH] alist: add updateScript --- pkgs/by-name/al/alist/package.nix | 5 ++++ pkgs/by-name/al/alist/update.nix | 43 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 pkgs/by-name/al/alist/update.nix diff --git a/pkgs/by-name/al/alist/package.nix b/pkgs/by-name/al/alist/package.nix index e2ba073fa636..997aa5522795 100644 --- a/pkgs/by-name/al/alist/package.nix +++ b/pkgs/by-name/al/alist/package.nix @@ -7,6 +7,7 @@ stdenv, installShellFiles, versionCheckHook, + callPackage, }: buildGoModule rec { pname = "alist"; @@ -88,6 +89,10 @@ buildGoModule rec { versionCheckHook ]; + passthru = { + updateScript = lib.getExe (callPackage ./update.nix { }); + }; + meta = { description = "File list/WebDAV program that supports multiple storages"; homepage = "https://github.com/alist-org/alist"; diff --git a/pkgs/by-name/al/alist/update.nix b/pkgs/by-name/al/alist/update.nix new file mode 100644 index 000000000000..e32f0c3e6c8d --- /dev/null +++ b/pkgs/by-name/al/alist/update.nix @@ -0,0 +1,43 @@ +{ + writeShellApplication, + nix, + nix-update, + curl, + jq, + common-updater-scripts, +}: + +writeShellApplication { + name = "update-alist"; + runtimeInputs = [ + curl + jq + nix + common-updater-scripts + nix-update + ]; + + text = '' + # get old info + oldVersion=$(nix-instantiate --eval --strict -A "alist.version" | jq -e -r) + + get_latest_release() { + local repo=$1 + curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \ + -s "https://api.github.com/repos/AlistGo/$repo/releases/latest" | jq -r ".tag_name" + } + + version=$(get_latest_release "alist") + version="''${version#v}" + webVersion=$(get_latest_release "alist-web") + + if [[ "$oldVersion" == "$version" ]]; then + echo "Already up to date!" + exit 0 + fi + + update-source-version alist "$webVersion" --source-key=web --version-key=webVersion + + nix-update alist --version="$version" + ''; +}