HOPStudio commited on
Commit
594dbe4
·
verified ·
1 Parent(s): 8d8a162

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +124 -5
main.py CHANGED
@@ -171,19 +171,138 @@ remotePort = 8188
171
 
172
 
173
  def install_frp():
174
- frp_tar_path = os.path.join(REPO_PATH, "frp_0.61.0_linux_amd64.tar.gz")
175
- frp_install_path = os.path.join(REPO_PATH, "frp_0.61.0_linux_amd64")
 
 
 
 
 
 
 
 
176
 
177
  frp_download_urls = [
178
- "https://github.com/fatedier/frp/releases/download/v0.61.0/frp_0.61.0_linux_amd64.tar.gz",
179
- "https://gh.llkk.cc/https://github.com/fatedier/frp/releases/download/v0.61.0/frp_0.61.0_linux_amd64.tar.gz",
180
- "https://gh-proxy.com/https://github.com/fatedier/frp/releases/download/v0.61.0/frp_0.61.0_linux_amd64.tar.gz"
181
  ]
182
 
183
  if os.path.exists(frp_install_path):
184
  print(f"frp 已安装: {frp_install_path}")
185
  return True
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  def is_valid_tar_gz(path):
188
  if not os.path.exists(path):
189
  return False
 
171
 
172
 
173
  def install_frp():
174
+ FRP_VERSION = "0.69.0"
175
+
176
+ frp_tar_name = f"frp_{FRP_VERSION}_linux_amd64.tar.gz"
177
+
178
+ frp_tar_path = os.path.join(REPO_PATH, frp_tar_name)
179
+
180
+ frp_install_path = os.path.join(
181
+ REPO_PATH,
182
+ f"frp_{FRP_VERSION}_linux_amd64"
183
+ )
184
 
185
  frp_download_urls = [
186
+ f"https://github.com/fatedier/frp/releases/download/v{FRP_VERSION}/{frp_tar_name}",
187
+ f"https://gh.llkk.cc/https://github.com/fatedier/frp/releases/download/v{FRP_VERSION}/{frp_tar_name}",
188
+ f"https://gh-proxy.com/https://github.com/fatedier/frp/releases/download/v{FRP_VERSION}/{frp_tar_name}"
189
  ]
190
 
191
  if os.path.exists(frp_install_path):
192
  print(f"frp 已安装: {frp_install_path}")
193
  return True
194
 
195
+ def is_valid_tar_gz(path):
196
+ if not os.path.exists(path):
197
+ return False
198
+
199
+ try:
200
+ result = subprocess.run(
201
+ ["tar", "-tzf", path],
202
+ stdout=subprocess.PIPE,
203
+ stderr=subprocess.PIPE,
204
+ text=True
205
+ )
206
+
207
+ return result.returncode == 0
208
+
209
+ except Exception:
210
+ return False
211
+
212
+ # =========================
213
+ # 删除损坏文件
214
+ # =========================
215
+ if os.path.exists(frp_tar_path):
216
+ if not is_valid_tar_gz(frp_tar_path):
217
+ print("检测到损坏的 frp 压缩包,正在删除...")
218
+ os.remove(frp_tar_path)
219
+
220
+ # =========================
221
+ # 下载 frp
222
+ # =========================
223
+ if not os.path.exists(frp_tar_path):
224
+ print("开始下载 frp...")
225
+
226
+ download_success = False
227
+
228
+ for url in frp_download_urls:
229
+ try:
230
+ print(f"尝试下载: {url}")
231
+
232
+ result = subprocess.run(
233
+ [
234
+ "wget",
235
+ "--no-check-certificate",
236
+ "-O",
237
+ frp_tar_path,
238
+ url
239
+ ],
240
+ stdout=subprocess.PIPE,
241
+ stderr=subprocess.PIPE,
242
+ text=True
243
+ )
244
+
245
+ if result.returncode == 0 and is_valid_tar_gz(frp_tar_path):
246
+ print("frp 下载成功。")
247
+ download_success = True
248
+ break
249
+
250
+ print("下载失败或文件损坏,尝试下一个下载源。")
251
+
252
+ if os.path.exists(frp_tar_path):
253
+ os.remove(frp_tar_path)
254
+
255
+ except Exception as e:
256
+ print(f"下载异常: {e}")
257
+
258
+ if not download_success:
259
+ print("frp 下载失败。")
260
+ return False
261
+
262
+ # =========================
263
+ # 解压 frp
264
+ # =========================
265
+ try:
266
+ print(f"正在解压 frp 到 {REPO_PATH}...")
267
+
268
+ subprocess.run(
269
+ [
270
+ "tar",
271
+ "-xzf",
272
+ frp_tar_path,
273
+ "-C",
274
+ REPO_PATH
275
+ ],
276
+ check=True
277
+ )
278
+
279
+ frpc_path = os.path.join(
280
+ frp_install_path,
281
+ "frpc"
282
+ )
283
+
284
+ frps_path = os.path.join(
285
+ frp_install_path,
286
+ "frps"
287
+ )
288
+
289
+ subprocess.run(
290
+ ["chmod", "+x", frpc_path],
291
+ check=False
292
+ )
293
+
294
+ subprocess.run(
295
+ ["chmod", "+x", frps_path],
296
+ check=False
297
+ )
298
+
299
+ print("frp 安装成功!")
300
+ return True
301
+
302
+ except subprocess.CalledProcessError as e:
303
+ print(f"解压 frp 时出错: {e}")
304
+ return False
305
+
306
  def is_valid_tar_gz(path):
307
  if not os.path.exists(path):
308
  return False