Fix Kitsune Magisk download when HuskyDG CDN is unavailable

Made-with: Cursor
This commit is contained in:
eric
2026-04-04 14:31:28 -05:00
parent 97fe83cd3a
commit 2024daf22e

View File

@@ -7,11 +7,20 @@ from stuff.general import General
from tools.helper import bcolors, download_file, host, print_color, run, get_download_dir
class Magisk(General):
stable_json = "https://raw.githubusercontent.com/os-fork/HuskyDG-magisk-files/main/stable.json"
_default_stable_json = (
"https://raw.githubusercontent.com/os-fork/HuskyDG-magisk-files/main/stable.json"
)
# HuskyDG/download was removed from GitHub; stable.json still points there.
_kitsune_26_4_mirror_apk = (
"https://raw.githubusercontent.com/Scratch2033Alt/KitsuneMagisk/main/26.4-kitsune.apk"
)
machine = host()
def __init__(self):
self.download_loc = get_download_dir()
self.stable_json_url = (
os.environ.get("REDROID_MAGISK_STABLE_JSON", "").strip() or self._default_stable_json
)
self.dl_file_name = os.path.join(self.download_loc, "magisk.apk")
self.release_meta_file = os.path.join(self.download_loc, "magisk.version")
self.extract_to = os.path.join(self.download_loc, "magisk_unpack")
@@ -154,27 +163,38 @@ on property:init.svc.zygote=stopped
return False
return True
def _magisk_download_candidates(self):
primary = self.dl_link
if "HuskyDG/download" in primary and str(self.release_version).startswith("26.4"):
return [self._kitsune_26_4_mirror_apk, primary]
return [primary]
def _download_remote_archive(self):
temp_path = self.dl_file_name + ".tmp"
try:
if os.path.isfile(temp_path):
os.remove(temp_path)
print_color(
"Trying online download for Kitsune Mask {} ...".format(self.release_version),
bcolors.GREEN,
)
download_file(self.dl_link, temp_path)
self._validate_archive(temp_path)
os.replace(temp_path, self.dl_file_name)
self._write_version()
except Exception:
if os.path.isfile(temp_path):
os.remove(temp_path)
raise
last_error = None
print_color(
"Trying online download for Kitsune Mask {} ...".format(self.release_version),
bcolors.GREEN,
)
for candidate_url in self._magisk_download_candidates():
try:
if os.path.isfile(temp_path):
os.remove(temp_path)
print_color(" from {} ...".format(candidate_url), bcolors.GREEN)
download_file(candidate_url, temp_path, timeout=120)
self._validate_archive(temp_path)
os.replace(temp_path, self.dl_file_name)
self._write_version()
return
except Exception as exc:
last_error = exc
if os.path.isfile(temp_path):
os.remove(temp_path)
raise last_error
def resolve_release(self):
print_color("Resolving Kitsune Mask stable release ...", bcolors.GREEN)
response = requests.get(self.stable_json, timeout=30)
response = requests.get(self.stable_json_url, timeout=30)
response.raise_for_status()
payload = response.json()
magisk_info = payload["magisk"]