From 991faf28877da3a6a702d4e850604e9326a34834 Mon Sep 17 00:00:00 2001 From: CoderKang Date: Thu, 18 Sep 2025 11:51:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20magisk.py=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E4=B8=BB=E6=9C=BA=E6=9E=B6=E6=9E=84=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E9=80=BB=E8=BE=91=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20x86=5F64=EF=BC=8C=E5=B9=B6=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- magisk.py | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/magisk.py b/magisk.py index 9c37b94..36cec48 100644 --- a/magisk.py +++ b/magisk.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import argparse import hashlib import os import platform @@ -37,16 +36,10 @@ def get_host_arch(): "armv8l": ("arm", 32) } if machine in mapping: - # if mapping[machine] == "x86_64": - # with open("/proc/cpuinfo") as f: - # if "sse4_2" not in f.read(): - # print("x86_64 CPU does not support SSE4.2, falling back to x86...") - # return ("x86", 32) return mapping[machine] - # 如果不在映射中,默认返回 arm64(适用于 Android 构建) print(f"Warning: platform.machine '{machine}' architecture not recognized, defaulting to arm64") - return ("arm64", 64) + return ("x86_64", 64) def run_command(cmd): @@ -67,7 +60,7 @@ class Magisk: self.extract_to = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp") self.copy_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "magisk") self.magisk_dir = os.path.join(self.copy_dir, "system", "etc", "init", "magisk") - self.machine = get_host_arch() # 返回 (arch, bits) 元组 + self.machine = get_host_arch() def download(self): """下载 Magisk APK""" @@ -151,7 +144,7 @@ class Magisk: print("==> Magisk installation completed!") - def cleanup(self, keep_downloads=False): + def cleanup(self): """清理临时文件和目录""" print("==> Cleaning up temporary files...") @@ -160,14 +153,12 @@ class Magisk: shutil.rmtree(self.extract_to, ignore_errors=True) print(f"==> Removed temporary extraction directory: {self.extract_to}") - # 可选择性清理下载目录 - if not keep_downloads and os.path.exists(self.download_loc): + # 清理下载目录 + if os.path.exists(self.download_loc): shutil.rmtree(self.download_loc, ignore_errors=True) print(f"==> Removed download directory: {self.download_loc}") - elif keep_downloads: - print(f"==> Keeping download directory: {self.download_loc}") - def run(self, cleanup_after=True, keep_downloads=True): + def run(self): """执行完整的构建流程""" try: self.download() @@ -178,34 +169,19 @@ class Magisk: print(f"Error: {e}") success = False finally: - # 无论成功还是失败都清理临时文件 - if cleanup_after: - self.cleanup(keep_downloads=keep_downloads) + self.cleanup() return success def main(): """主函数""" - parser = argparse.ArgumentParser(description='Magisk vendor package builder') - parser.add_argument('--no-cleanup', action='store_true', - help='不清理临时文件和下载文件') - parser.add_argument('--remove-downloads', action='store_true', - help='同时删除下载的文件') - - args = parser.parse_args() - - # 根据参数确定清理行为 - cleanup_after = not args.no_cleanup - keep_downloads = not args.remove_downloads - magisk = Magisk() - success = magisk.run(cleanup_after=cleanup_after, keep_downloads=keep_downloads) + success = magisk.run() if success: print("==> Magisk vendor package created successfully!") - if cleanup_after: - print("==> Temporary files cleaned up") + print("==> Temporary files cleaned up") else: print("==> Failed to create Magisk vendor package!") exit(1)