Update main.py
Browse files
main.py
CHANGED
|
@@ -171,23 +171,66 @@ remotePort = 8188
|
|
| 171 |
|
| 172 |
|
| 173 |
def install_frp():
|
| 174 |
-
frp_tar_path = os.path.join(
|
| 175 |
-
|
| 176 |
-
"frp_0.61.0_linux_amd64.tar.gz"
|
| 177 |
-
)
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
"frp_0.61.0_linux_amd64"
|
| 182 |
-
|
|
|
|
| 183 |
|
| 184 |
if os.path.exists(frp_install_path):
|
| 185 |
print(f"frp 已安装: {frp_install_path}")
|
| 186 |
return True
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
try:
|
| 193 |
print(f"正在解压 frp 安装包到 {REPO_PATH}...")
|
|
@@ -197,14 +240,18 @@ def install_frp():
|
|
| 197 |
check=True
|
| 198 |
)
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
print("frp 安装成功!")
|
| 201 |
return True
|
| 202 |
|
| 203 |
except subprocess.CalledProcessError as e:
|
| 204 |
print(f"解压 frp 时出错: {e}")
|
| 205 |
return False
|
| 206 |
-
|
| 207 |
-
|
| 208 |
def start_jupyterlab_process():
|
| 209 |
jupyter_script = os.path.join(REPO_PATH, "start_jupyterlab.py")
|
| 210 |
|
|
|
|
| 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
|
| 190 |
+
|
| 191 |
+
try:
|
| 192 |
+
result = subprocess.run(
|
| 193 |
+
["tar", "-tzf", path],
|
| 194 |
+
stdout=subprocess.PIPE,
|
| 195 |
+
stderr=subprocess.PIPE,
|
| 196 |
+
text=True
|
| 197 |
+
)
|
| 198 |
+
return result.returncode == 0
|
| 199 |
+
except Exception:
|
| 200 |
+
return False
|
| 201 |
+
|
| 202 |
+
if not is_valid_tar_gz(frp_tar_path):
|
| 203 |
+
print("frp 压缩包不存在或不是有效 gzip 文件,正在重新下载...")
|
| 204 |
+
|
| 205 |
+
if os.path.exists(frp_tar_path):
|
| 206 |
+
os.remove(frp_tar_path)
|
| 207 |
+
|
| 208 |
+
download_success = False
|
| 209 |
+
|
| 210 |
+
for url in frp_download_urls:
|
| 211 |
+
try:
|
| 212 |
+
print(f"尝试下载: {url}")
|
| 213 |
+
|
| 214 |
+
result = subprocess.run(
|
| 215 |
+
["wget", "-O", frp_tar_path, url],
|
| 216 |
+
stdout=subprocess.PIPE,
|
| 217 |
+
stderr=subprocess.PIPE,
|
| 218 |
+
text=True
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
if result.returncode == 0 and is_valid_tar_gz(frp_tar_path):
|
| 222 |
+
print("frp 下载成功。")
|
| 223 |
+
download_success = True
|
| 224 |
+
break
|
| 225 |
+
|
| 226 |
+
print("下载失败或文件无效,尝试下一个地址。")
|
| 227 |
+
|
| 228 |
+
except Exception as e:
|
| 229 |
+
print(f"下载出错: {e}")
|
| 230 |
+
|
| 231 |
+
if not download_success:
|
| 232 |
+
print("frp 下载失败,请检查网络。")
|
| 233 |
+
return False
|
| 234 |
|
| 235 |
try:
|
| 236 |
print(f"正在解压 frp 安装包到 {REPO_PATH}...")
|
|
|
|
| 240 |
check=True
|
| 241 |
)
|
| 242 |
|
| 243 |
+
frpc_path = os.path.join(frp_install_path, "frpc")
|
| 244 |
+
|
| 245 |
+
if os.path.exists(frpc_path):
|
| 246 |
+
subprocess.run(["chmod", "+x", frpc_path], check=False)
|
| 247 |
+
|
| 248 |
print("frp 安装成功!")
|
| 249 |
return True
|
| 250 |
|
| 251 |
except subprocess.CalledProcessError as e:
|
| 252 |
print(f"解压 frp 时出错: {e}")
|
| 253 |
return False
|
| 254 |
+
|
|
|
|
| 255 |
def start_jupyterlab_process():
|
| 256 |
jupyter_script = os.path.join(REPO_PATH, "start_jupyterlab.py")
|
| 257 |
|