File size: 6,704 Bytes
199c9f1
 
 
 
 
 
 
 
 
 
bad97bf
c0b5253
 
 
 
448b0dc
 
a44c49e
 
 
 
 
 
 
 
 
8229ac1
02318b6
a44c49e
 
 
 
9c62b8a
bad97bf
 
 
 
 
 
 
 
 
 
 
c0b5253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f452e41
c0b5253
 
 
 
 
 
 
5d13632
 
 
 
 
 
 
 
 
c0b5253
415c006
407f3fd
 
c0b5253
5d13632
c0b5253
 
3245f8f
c0b5253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3245f8f
c0b5253
 
 
 
 
 
 
3245f8f
c0b5253
 
 
 
 
 
 
3245f8f
c0b5253
 
 
 
 
 
 
bad97bf
 
 
 
 
 
 
 
ffe88fb
bad97bf
 
 
 
 
 
 
ffe88fb
bad97bf
ffe88fb
bad97bf
 
ffe88fb
bad97bf
 
 
 
 
 
 
ffe88fb
bad97bf
ffe88fb
bad97bf
c0b5253
bad97bf
 
c0b5253
 
 
 
 
bad97bf
c0b5253
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# SD 插件路径 /tmp/code/sd/stable-diffusion-webui/extensions
# SD embeddings路径 /tmp/code/sd/stable-diffusion-webui/embeddings
# SD VAE路径 /tmp/code/sd/stable-diffusion-webui/models/VAE
# SD Lora路径 /tmp/code/sd/stable-diffusion-webui/models/Lora
# SD 模型路径 /tmp/code/sd/stable-diffusion-webui/models/Stable-diffusion

#comfyui 模型、VAE、Lora由SD文件路径共享

# comfyui 插件路径 /tmp/code/sd/ComfyUI/custom_nodes

print('--------------远程执行---------------------')
 
import os
import subprocess



def install_aria2():
    try:
        # 检查 aria2c 是否已安装
        subprocess.run(['which', 'aria2c'], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        print("aria2c 已安装")
    except subprocess.CalledProcessError:
        # aria2c 未安装,尝试自动安装
        print("aria2c 未安装,正在尝试自动安装...")
        if 'ubuntu' in subprocess.check_output(['lsb_release', '-i']).decode().lower():
            os.system('apt install aria2 -y')
            print("aria2c 安装成功")
        else:
            print("无法自动检测您的操作系统,请手动安装 aria2。")
install_aria2()
print('--------------开始---------------------')

#SD插件下载
git_sd = [
    'https://slink.ltd/https://github.com/2575044704/stable-diffusion-webui-localization-zh_CN2.git', #汉化
    'https://slink.ltd/https://github.com/AlUlkesh/stable-diffusion-webui-images-browser', #图库浏览器
]
#comfyui插件下载
git_comfyui = [
    'https://slink.ltd/https://github.com/AIGODLIKE/AIGODLIKE-COMFYUI-TRANSLATION',#中文插件
    'https://slink.ltd/https://github.com/talesofai/comfyui-browser'#查看器
]

# 包含文件名和下载 URL 的列表,格式为 ['文件名:下载URL', ...]
#Lora下载

Lora_url = [
    
]
#embeddings下载
embeddings_url = [
    
]
#VAE下载
VAE_url = [
    
]
#模型下载
mode_url = [
    #'[动漫]noobaiXLNAIXL_epsilonPred075.safetensors:https://prod-vod.miyoushe.com/ogp5ANsBjwtHuQMzLhPtqM7ml8G5vnZpNjjZbH/noobaiXLNAIXL_epsilonPred10Version.safetensors'
]

def download_aria2(file_name, download_dir, url):
    download_path = os.path.join(download_dir, file_name)
    # 检查文件是否已存在
    if os.path.exists(download_path):
        print(f'文件 {file_name} 已存在, URL: {url}')
        return
    
    aria2_args = (
        f'aria2c --dir {download_dir} --out {file_name} '
        '--max-connection-per-server=10 --split=10 '
        '--min-split-size=1M --max-overall-download-limit=0 '
        '--max-download-limit=0 --continue=true {url}'
    )
    
    try:
        print(f'aria2c --dir {download_dir} --out {file_name} --max-connection-per-server=10 --split=10 --min-split-size=1M --max-overall-download-limit=0 --max-download-limit=0 --continue=true {url}')
        os.system(f'aria2c --dir {download_dir} --out {file_name} --max-connection-per-server=10 --split=10 --min-split-size=1M --max-overall-download-limit=0 --max-download-limit=0 --continue=true {url}')
        # os.system(aria2_args)
        print(f'已成功下载: {file_name}')
    except Exception as e:
        print(f'下载 {url} 失败: {e}')

def download_Lora(file_urls, download_dir='/tmp/code/sd/stable-diffusion-webui/models/Lora'):
    """
    下载文件到指定目录,并支持替换文件名。如果文件已存在,则不进行下载。
    
    参数:
    file_urls (list): 包含文件名和下载 URL 的列表,格式为 ['文件名:下载URL', ...]
    download_dir (str): 下载文件的目标目录
    """
    # 创建目标目录
    os.makedirs(download_dir, exist_ok=True)
    # 下载文件
    for file_url in file_urls:
        try:
            file_name, url = file_url.split(':', 1)
            download_aria2(file_name, download_dir, url)
        except ValueError:
            print(f'无效的文件 URL 格式: {file_url}')
def download_embeddings(file_urls, download_dir='/tmp/code/sd/stable-diffusion-webui/embeddings'):
    os.makedirs(download_dir, exist_ok=True)
    for file_url in file_urls:
        try:
            file_name, url = file_url.split(':', 1)
            download_aria2(file_name, download_dir, url)
        except ValueError:
            print(f'无效的文件 URL 格式: {file_url}')
def download_VAE(file_urls, download_dir='/tmp/code/sd/stable-diffusion-webui/models/VAE'):
    os.makedirs(download_dir, exist_ok=True)
    for file_url in file_urls:
        try:
            file_name, url = file_url.split(':', 1)
            download_aria2(file_name, download_dir, url)
        except ValueError:
            print(f'无效的文件 URL 格式: {file_url}')
def download_mode(file_urls, download_dir='/tmp/code/sd/stable-diffusion-webui/models/Stable-diffusion'):
    os.makedirs(download_dir, exist_ok=True)
    for file_url in file_urls:
        try:
            file_name, url = file_url.split(':', 1)
            download_aria2(file_name, download_dir, url)
        except ValueError:
            print(f'无效的文件 URL 格式: {file_url}')
def clone_repos_sd(repo_urls, clone_dir='/tmp/code/sd/stable-diffusion-webui/extensions'):
    """
    克隆 GitHub 仓库到指定目录
    参数:
    repo_urls (list): GitHub 仓库 URL 列表
    clone_dir (str): 克隆仓库的目标目录
    """
    # 创建目标目录
    os.makedirs(clone_dir, exist_ok=True, mode=0o755)
    for repo_url in repo_urls:
        try:
            repo_name = repo_url.rstrip('/').split('/')[-1]
            clone_path = os.path.join(clone_dir, repo_name)
            if os.path.exists(clone_path):
                print(f'仓库 {repo_name} 已存在, URL: {repo_url}')
                continue
            os.system(f'git clone {repo_url} {clone_path}')
            print(f'已成功克隆仓库: {repo_name}')
        except Exception as e:
            print(f'克隆 {repo_url} 失败: {e}')
def clone_repos_comfyui(repo_urls, clone_dir='/tmp/code/sd/ComfyUI/custom_nodes'):
    os.makedirs(clone_dir, exist_ok=True, mode=0o755)
    for repo_url in repo_urls:
        try:
            repo_name = repo_url.rstrip('/').split('/')[-1]
            clone_path = os.path.join(clone_dir, repo_name)
            if os.path.exists(clone_path):
                print(f'仓库 {repo_name} 已存在, URL: {repo_url}')
                continue
            os.system(f'git clone {repo_url} {clone_path}')
            print(f'已成功克隆仓库: {repo_name}')
        except Exception as e:
            print(f'克隆 {repo_url} 失败: {e}')

clone_repos_sd(git_sd)
clone_repos_comfyui(git_comfyui)
download_Lora(Lora_url)
download_embeddings(embeddings_url)
download_VAE(VAE_url)
download_mode(mode_url)