From e32f34f05d8431b2dd82874f4c86d69904768d1b Mon Sep 17 00:00:00 2001 From: Folfy Blue Date: Mon, 5 Feb 2024 14:24:29 +0100 Subject: [PATCH] fix: Manjaro updater sometimes having different checksum hashing algorithms --- modules/updaters/Manjaro.py | 42 ++++++++++++++++++++++++++----------- setup.py | 2 +- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/modules/updaters/Manjaro.py b/modules/updaters/Manjaro.py index 2702600..0f317e7 100644 --- a/modules/updaters/Manjaro.py +++ b/modules/updaters/Manjaro.py @@ -6,11 +6,16 @@ from modules.exceptions import VersionNotFoundError from modules.updaters.GenericUpdater import GenericUpdater -from modules.utils import parse_hash, sha512_hash_check +from modules.utils import ( + md5_hash_check, + parse_hash, + sha512_hash_check, + sha256_hash_check, +) DOMAIN = "https://gitlab.manjaro.org" DOWNLOAD_PAGE_URL = f"{DOMAIN}/web/iso-info/-/raw/master/file-info.json" -FILE_NAME = "manjaro-[[EDITION]]-[[VER]]-linux61.iso" +FILE_NAME = "manjaro-[[EDITION]]-[[VER]]-linux.iso" class Manjaro(GenericUpdater): @@ -50,16 +55,29 @@ def _get_download_link(self) -> str: return self.file_info_json["releases"][self.edition]["image"] def check_integrity(self) -> bool: - sha512_url = self.file_info_json["releases"][self.edition]["checksum"] - - sha512_sums = requests.get(sha512_url).text - - sha512_sum = parse_hash(sha512_sums, [], 0) - - return sha512_hash_check( - self._get_complete_normalized_file_path(absolute=True), - sha512_sum, - ) + checksum_url = self.file_info_json["releases"][self.edition]["checksum"] + + checksums = requests.get(checksum_url).text + + checksum = parse_hash(checksums, [], 0) + + if checksum_url.endswith(".sha512"): + return sha512_hash_check( + self._get_complete_normalized_file_path(absolute=True), + checksum, + ) + elif checksum_url.endswith(".sha256"): + return sha256_hash_check( + self._get_complete_normalized_file_path(absolute=True), + checksum, + ) + elif checksum_url.endswith(".md5"): + return md5_hash_check( + self._get_complete_normalized_file_path(absolute=True), + checksum, + ) + else: + raise ValueError("Unknown checksum type") @cache def _get_latest_version(self) -> list[str]: diff --git a/setup.py b/setup.py index ca9ed03..6944a3d 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="sisou", # Required - version="1.1.1", # Required + version="1.1.2", # Required description="A powerful tool to conveniently update all of your ISO files!", # Optional long_description=long_description, # Optional long_description_content_type="text/markdown", # Optional