56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Alpine glibc 纯离线自动安装工具
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
def run_cmd(cmd):
|
|
try:
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=30)
|
|
return result.returncode == 0
|
|
except:
|
|
return False
|
|
|
|
def main():
|
|
# 检查权限
|
|
if os.geteuid() != 0:
|
|
print("[✗] 需要 root 权限")
|
|
sys.exit(1)
|
|
|
|
# 检查是否已安装
|
|
if os.path.exists("/usr/glibc-compat/lib/libc.so.6"):
|
|
print("[✓] glibc 已安装")
|
|
sys.exit(0)
|
|
|
|
# 检查本地文件
|
|
apk_file = "./glibc-2.35-r1.apk"
|
|
if not os.path.exists(apk_file):
|
|
print(f"[✗] 找不到 {apk_file}")
|
|
sys.exit(1)
|
|
|
|
print("[*] 开始离线安装...")
|
|
|
|
# 创建密钥目录
|
|
os.makedirs("/etc/apk/keys", exist_ok=True)
|
|
|
|
# 纯离线安装命令(按优先级排序)
|
|
commands = [
|
|
f"apk add --allow-untrusted --no-network {apk_file}",
|
|
f"apk add --allow-untrusted --force-non-repository {apk_file}",
|
|
f"apk add --allow-untrusted {apk_file}"
|
|
]
|
|
|
|
# 依次尝试安装
|
|
for cmd in commands:
|
|
if run_cmd(cmd):
|
|
print("[✓] glibc 安装成功")
|
|
sys.exit(0)
|
|
|
|
print("[✗] 安装失败")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|