Fix Kitsune Magisk download when HuskyDG CDN is unavailable
Made-with: Cursor
This commit is contained in:
@@ -7,11 +7,20 @@ from stuff.general import General
|
|||||||
from tools.helper import bcolors, download_file, host, print_color, run, get_download_dir
|
from tools.helper import bcolors, download_file, host, print_color, run, get_download_dir
|
||||||
|
|
||||||
class Magisk(General):
|
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()
|
machine = host()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.download_loc = get_download_dir()
|
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.dl_file_name = os.path.join(self.download_loc, "magisk.apk")
|
||||||
self.release_meta_file = os.path.join(self.download_loc, "magisk.version")
|
self.release_meta_file = os.path.join(self.download_loc, "magisk.version")
|
||||||
self.extract_to = os.path.join(self.download_loc, "magisk_unpack")
|
self.extract_to = os.path.join(self.download_loc, "magisk_unpack")
|
||||||
@@ -154,27 +163,38 @@ on property:init.svc.zygote=stopped
|
|||||||
return False
|
return False
|
||||||
return True
|
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):
|
def _download_remote_archive(self):
|
||||||
temp_path = self.dl_file_name + ".tmp"
|
temp_path = self.dl_file_name + ".tmp"
|
||||||
try:
|
last_error = None
|
||||||
if os.path.isfile(temp_path):
|
print_color(
|
||||||
os.remove(temp_path)
|
"Trying online download for Kitsune Mask {} ...".format(self.release_version),
|
||||||
print_color(
|
bcolors.GREEN,
|
||||||
"Trying online download for Kitsune Mask {} ...".format(self.release_version),
|
)
|
||||||
bcolors.GREEN,
|
for candidate_url in self._magisk_download_candidates():
|
||||||
)
|
try:
|
||||||
download_file(self.dl_link, temp_path)
|
if os.path.isfile(temp_path):
|
||||||
self._validate_archive(temp_path)
|
os.remove(temp_path)
|
||||||
os.replace(temp_path, self.dl_file_name)
|
print_color(" from {} ...".format(candidate_url), bcolors.GREEN)
|
||||||
self._write_version()
|
download_file(candidate_url, temp_path, timeout=120)
|
||||||
except Exception:
|
self._validate_archive(temp_path)
|
||||||
if os.path.isfile(temp_path):
|
os.replace(temp_path, self.dl_file_name)
|
||||||
os.remove(temp_path)
|
self._write_version()
|
||||||
raise
|
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):
|
def resolve_release(self):
|
||||||
print_color("Resolving Kitsune Mask stable release ...", bcolors.GREEN)
|
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()
|
response.raise_for_status()
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
magisk_info = payload["magisk"]
|
magisk_info = payload["magisk"]
|
||||||
|
|||||||
Reference in New Issue
Block a user