Skip to content

Commit 87965bd

Browse files
kelvinBenkelvinBen
authored andcommitted
1. 统一cpu类型
2. 同步脚本目录下的json配置文件
1 parent 348c080 commit 87965bd

File tree

5 files changed

+60
-38
lines changed

5 files changed

+60
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## AutoRedTools
44

55
AutoRedTools是一款轻量级一站式自动下载/自动更新常用开源软件的工具,主要帮助安全从业者/安全开发人员快速进行环境搭建以及常用软件的更新,节约软件的更新或者安
6-
的时间,提升生产或工作效率
6+
装的时间,从而提升生产效率或工作效率
77

88
(注:本工具使用GitHub API能力,需要配置GitHub Token,未配置GitHub Token会被GitHub限制IP访问)
99

UPDATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
## V1.0.2
23

34
1. 修改输入参数支持类库

app.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, github_token, github_proxy, tools_path) -> None:
3030

3131
def start(self, out_path):
3232
self.__set_proxy__()
33+
tools_name = ""
3334
with open(file=self.tools_path, encoding="utf8") as open_file:
3435
content = open_file.read()
3536
try:
@@ -60,7 +61,7 @@ def start(self, out_path):
6061
raise(CustomException(error_msg))
6162
except KeyError as e:
6263
msg = re.sub(r'KeyError.*?:',"", str(e)).strip()
63-
error_msg = ("配置文件: %s 中未检索到Key: %s ,请参考配置样例文件后重新输入!!!") % (self.tools_path,msg)
64+
error_msg = ("%s, 配置文件: %s 中未检索到Key: %s ,请参考配置样例文件后重新输入!!!") % (tools_name,self.tools_path,msg)
6465
raise(CustomException(error_msg))
6566
except Exception as e:
6667
raise(e)
@@ -105,21 +106,25 @@ def download_code_or_binary(self, tools_out_path, tools_url, platforms, tools_ty
105106
except KeyError as e:
106107
# 如果是Java版本则下载所有Java版本的
107108
sys_platform = platforms["java"]
108-
except Exception as e:
109-
raise(e)
110-
111-
if type(sys_platform) == type("str"):
112-
# 如果是str类型则直接获取工具名称
113-
file_name = sys_platform
114-
else:
115-
cpu_type = get_cpu_type() # 获取CPU类型
116-
file_name = sys_platform[cpu_type]
117-
118-
if "www" in tools_url:
119-
api_url = tools_url.replace("www", "")
120-
api_url = tools_url.replace("github.com", "api.github.com/repos") + "/releases/latest"
121109

122110
try:
111+
if type(sys_platform) == type("str"):
112+
# 如果是str类型则直接获取工具名称
113+
file_name = sys_platform
114+
else:
115+
cpu_type = get_cpu_type().lower() # 获取CPU类型
116+
if cpu_type == "x86" or cpu_type=="i386" or cpu_type=="ia32":
117+
cpu_type = "i386"
118+
if cpu_type=="x86_64" or cpu_type=="x64" or cpu_type=="amd64":
119+
cpu_type = "amd64"
120+
if cpu_type=="arm" or cpu_type=="arm64":
121+
cpu_type = "arm64"
122+
file_name = sys_platform[cpu_type]
123+
124+
if "www" in tools_url:
125+
api_url = tools_url.replace("www", "")
126+
api_url = tools_url.replace("github.com", "api.github.com/repos") + "/releases/latest"
127+
123128
resp = self.__requsets__(api_url)
124129
repos_json_obj = resp.json()
125130
tools_vesion = str(repos_json_obj["tag_name"])
@@ -144,7 +149,7 @@ def download_code_or_binary(self, tools_out_path, tools_url, platforms, tools_ty
144149
# 无发布版本忽略
145150
return
146151
except AttributeError as e:
147-
errmsg= ("访问地址 %s 地址异常,请检查网络或者使用-p参数配置代理后重试!!!" % api_url)
152+
errmsg= ("访问地址 %s 地址异常,请检查网络或者使用-p参数配置代理后重试或者使用-t参数追加github token!!!" % api_url)
148153
raise(CustomException(errmsg))
149154
except Exception as e:
150155
raise(e)
@@ -255,7 +260,16 @@ def init():
255260
if not os.path.exists(tools_path):
256261
script_tools = os.path.join(os.path.dirname(__file__), "tools.json")
257262
shutil.copyfile(script_tools, tools_path)
258-
263+
else:
264+
# 文件存在将最新的tools.json文件替换,并备份旧的配置文件
265+
script_tools = os.path.join(os.path.dirname(__file__), "tools.json")
266+
tools_mtime = os.path.getmtime(tools_path)
267+
script_tools_mtime = os.path.getmtime(script_tools)
268+
if script_tools_mtime > tools_mtime:
269+
old_script_tools = os.path.join(doc_dir, "tools.json_" + str(tools_mtime))
270+
shutil.move(tools_path, old_script_tools) # 备份旧的tools.json文件
271+
shutil.copyfile(script_tools, tools_path) # 替换为新的tools.json文件
272+
259273
# 获取全局配置文件信息
260274
config_dict = None
261275
with open(config_path, "r" ,encoding="utf-8") as config_file:

tools.json

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@
6060
"type": "binary",
6161
"platform": {
6262
"win32": {
63-
"i386": "xray_windows_386.exe",
64-
"x86_64": "xray_windows_amd64"
63+
"x86": "xray_windows_386.exe",
64+
"amd64": "xray_windows_amd64"
6565
},
6666
"darwin": {
67-
"x86_64": "xray_darwin_amd64",
67+
"x86": "xray_darwin_amd64",
68+
"amd64": "xray_darwin_amd64",
6869
"arm64": "xray_darwin_arm64"
6970
},
7071
"linux": {
71-
"i386": "xray_linux_386",
72-
"x86_64": "xray_linux_amd64",
72+
"x86": "xray_linux_386",
73+
"amd64": "xray_linux_amd64",
7374
"arm64": "xray_linux_arm64"
7475
}
7576
}
@@ -94,11 +95,13 @@
9495
"platform": {
9596
"win32": "win",
9697
"darwin": {
97-
"x86_64": "macos.tar.gz",
98+
"x86": "macos.tar.gz",
99+
"amd64": "macos.tar.gz",
98100
"arm64": "macos_arm64"
99101
},
100102
"linux": {
101-
"x86_64": "linux.tar.gz",
103+
"x86": "linux.tar.gz",
104+
"amd64": "linux.tar.gz",
102105
"arm64": "linux_arm64"
103106
}
104107
}
@@ -118,15 +121,16 @@
118121
"type": "binary",
119122
"platform": {
120123
"win32": {
121-
"i386": "windows_386",
122-
"x86_64": "windows_amd64"
124+
"x86": "windows_386",
125+
"amd64": "windows_amd64"
123126
},
124127
"darwin": {
125-
"x86_64": "darwin_amd64",
128+
"x86": "darwin_amd64",
129+
"amd64": "darwin_amd64",
126130
"arm64": "darwin_arm64"
127131
},
128132
"linux": {
129-
"x86_64": "Ladon64.lnx",
133+
"amd64": "Ladon64.lnx",
130134
"arm": "linux_arm",
131135
"arm64": "linux_arm64"
132136
}
@@ -138,15 +142,16 @@
138142
"type": "binary",
139143
"platform": {
140144
"win32": {
141-
"i386": "Ladon.exe",
142-
"x86_64": "Ladon64.exe"
145+
"x86": "Ladon.exe",
146+
"amd64": "Ladon64.exe"
143147
},
144148
"darwin": {
145-
"x86_64": "Ladon.mac",
149+
"x86": "Ladon.mac",
150+
"amd64": "Ladon.mac",
146151
"arm64": "Ladon64.arm"
147152
},
148153
"linux": {
149-
"x86_64": "Ladon64.lnx",
154+
"amd64": "Ladon64.lnx",
150155
"arm64": "Ladon64.arm"
151156
}
152157
}
@@ -221,16 +226,18 @@
221226
"type": "binary",
222227
"platform": {
223228
"win32": {
224-
"i386": "win32-ia32",
225-
"x86_64": "win32-x64"
229+
"x86": "win32-ia32",
230+
"amd64": "win32-x64",
231+
"arm64": "win32-x64"
226232
},
227233
"darwin": {
228-
"x86_64": "darwin-x64",
234+
"x86": "darwin-x64",
235+
"amd64": "darwin-x64",
229236
"arm64": "darwin-x64"
230237
},
231238
"linux": {
232-
"i386": "linux-ia32",
233-
"x86_64": "linux-x64",
239+
"x86": "linux-ia32",
240+
"amd64": "linux-x64",
234241
"arm": "linux-ia32",
235242
"arm64": "linux-arm64"
236243
}

utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def get_cpu_type():
1414
if "Apple" in cpu_type:
1515
return "arm64"
1616
else:
17-
return "x86_64"
17+
return "amd64"
1818
else:
1919
return platform.machine()

0 commit comments

Comments
 (0)