From 0f575181eef0ea7f675a37a513db6c34eb85cc17 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:27:09 +0200 Subject: [PATCH] nix: bring back local release pin to update.py Revert "nix: remove unused code from update.py" This reverts commit 48dfd73c9194e32b0cfbea9590c72d58fce8aefa. nix: update local release pin function in update.py --- contrib/package/nix/copyparty/update.py | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/contrib/package/nix/copyparty/update.py b/contrib/package/nix/copyparty/update.py index 4bdfb3e7..90542d2e 100755 --- a/contrib/package/nix/copyparty/update.py +++ b/contrib/package/nix/copyparty/update.py @@ -2,18 +2,23 @@ # Update the Nix package pin # -# Usage: ./update.sh +# Usage: ./update.sh [PATH] +# When the [PATH] is not set, it will fetch the latest release from the repo. +# With [PATH] set, it will hash the given file and generate the URL, +# base on the version contained within the file import base64 import json import hashlib import sys +import tarfile from pathlib import Path OUTPUT_FILE = Path("pin.json") TARGET_ASSET = lambda version: f"copyparty-{version}.tar.gz" HASH_TYPE = "sha256" LATEST_RELEASE_URL = "https://api.github.com/repos/9001/copyparty/releases/latest" +DOWNLOAD_URL = lambda version: f"https://github.com/9001/copyparty/releases/download/v{version}/{TARGET_ASSET(version)}" def get_formatted_hash(binary): @@ -24,6 +29,16 @@ def get_formatted_hash(binary): return f"{HASH_TYPE}-{encoded_hash}" +def version_from_tar_gz(path): + with tarfile.open(path) as tarball: + release_name = tarball.getmembers()[0].name + prefix = "copyparty-" + + if release_name.startswith(prefix): + return release_name.replace(prefix, "") + raise ValueError("version not found in provided file") + + def remote_release_pin(): import requests @@ -38,8 +53,21 @@ def remote_release_pin(): return result +def local_release_pin(path): + version = version_from_tar_gz(path) + download_url = DOWNLOAD_URL(version) + formatted_hash = get_formatted_hash(path.read_bytes()) + + result = {"url": download_url, "version": version, "hash": formatted_hash} + return result + + def main(): - result = remote_release_pin() + if len(sys.argv) > 1: + asset_path = Path(sys.argv[1]) + result = local_release_pin(asset_path) + else: + result = remote_release_pin() print(result) json_result = json.dumps(result, indent=4)