fix: 更新 magisk.py 文件,重构主机架构获取逻辑,添加命令行参数支持,确保构建过程的灵活性和可配置性。同时更新 magisk.rc 文件,添加 /sbin 目录的创建。
This commit is contained in:
58
magisk.py
58
magisk.py
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -24,24 +24,6 @@ def download_file(url, file_path):
|
||||
urllib.request.urlretrieve(url, file_path)
|
||||
|
||||
|
||||
def get_host_arch():
|
||||
"""获取主机架构信息"""
|
||||
machine = platform.machine()
|
||||
|
||||
mapping = {
|
||||
"i686": ("x86", 32),
|
||||
"x86_64": ("x86_64", 64),
|
||||
"aarch64": ("arm64", 64),
|
||||
"armv7l": ("arm", 32),
|
||||
"armv8l": ("arm", 32)
|
||||
}
|
||||
if machine in mapping:
|
||||
return mapping[machine]
|
||||
|
||||
print(f"Warning: platform.machine '{machine}' architecture not recognized, defaulting to arm64")
|
||||
return ("x86_64", 64)
|
||||
|
||||
|
||||
def run_command(cmd):
|
||||
"""运行命令"""
|
||||
try:
|
||||
@@ -52,14 +34,22 @@ def run_command(cmd):
|
||||
|
||||
|
||||
class Magisk:
|
||||
def __init__(self):
|
||||
def __init__(self, target_arch="arm64"):
|
||||
self.download_loc = os.path.join(os.path.dirname(os.path.abspath(__file__)), "downloads")
|
||||
self.dl_link = "https://github.com/topjohnwu/Magisk/releases/download/v30.2/Magisk-v30.2.apk"
|
||||
self.dl_file_name = os.path.join(self.download_loc, "magisk.apk")
|
||||
self.act_md5 = "2691c30ccf059af2536cb0af803c787c"
|
||||
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.machine = get_host_arch()
|
||||
self.target_arch = target_arch
|
||||
|
||||
# 架构映射
|
||||
self.arch_map = {
|
||||
"x86": "x86",
|
||||
"x86_64": "x86_64",
|
||||
"arm": "armeabi-v7a",
|
||||
"arm64": "arm64-v8a"
|
||||
}
|
||||
|
||||
def download(self):
|
||||
"""下载 Magisk APK"""
|
||||
@@ -107,16 +97,8 @@ class Magisk:
|
||||
shutil.rmtree(self.copy_dir)
|
||||
os.makedirs(self.copy_dir, exist_ok=True)
|
||||
|
||||
# 架构映射
|
||||
arch_map = {
|
||||
"x86": "x86",
|
||||
"x86_64": "x86_64",
|
||||
"arm": "armeabi-v7a",
|
||||
"arm64": "arm64-v8a"
|
||||
}
|
||||
|
||||
# 复制主要架构的库文件
|
||||
lib_dir = os.path.join(self.extract_to, "lib", arch_map[self.machine[0]])
|
||||
lib_dir = os.path.join(self.extract_to, "lib", self.arch_map[self.target_arch])
|
||||
if os.path.exists(lib_dir):
|
||||
for parent, dirnames, filenames in os.walk(lib_dir):
|
||||
for filename in filenames:
|
||||
@@ -174,7 +156,21 @@ class Magisk:
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
magisk = Magisk()
|
||||
parser = argparse.ArgumentParser(description='Magisk vendor package builder')
|
||||
|
||||
parser.add_argument('--arch',
|
||||
choices=['x86', 'x86_64', 'arm', 'arm64'],
|
||||
default='arm64',
|
||||
help='指定目标架构 (默认: arm64)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print(f"==> Using target architecture: {args.arch}")
|
||||
|
||||
# 创建 Magisk 实例
|
||||
magisk = Magisk(target_arch=args.arch)
|
||||
|
||||
# 执行构建
|
||||
success = magisk.run()
|
||||
|
||||
if success:
|
||||
|
||||
Reference in New Issue
Block a user