File size: 13,056 Bytes
366fd1c 8325859 366fd1c |
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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
#!/bin/bash
set -uo pipefail
set +H
export PIP_NO_CACHE_DIR=1
export PIP_DISABLE_PIP_VERSION_CHECK=1
export GIT_TERMINAL_PROMPT=0
source /venv/main/bin/activate
COMFYUI_DIR="${WORKSPACE:-/workspace}/ComfyUI"
if [ -f "/venv/main/bin/python" ]; then
PYTHON_BIN="/venv/main/bin/python"
PIP_BIN="/venv/main/bin/pip"
else
PYTHON_BIN="python3"
PIP_BIN="pip3"
fi
APT_PACKAGES=(
"aria2"
)
PIP_PACKAGES=(
)
NODES=(
"https://github.com/ltdrdata/ComfyUI-Impact-Pack.git"
"https://github.com/ltdrdata/ComfyUI-Impact-Subpack.git"
"https://github.com/cubiq/ComfyUI_IPAdapter_plus.git"
"https://github.com/ka-puna/comfyui-yanc.git"
)
CHECKPOINT_MODELS=(
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/models/checkpoints/waiNSFWIllustrious_v150.safetensors"
)
CLIP_VISION_MODELS=(
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/models/clip_vision/CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors"
)
IPADAPTER_MODELS=(
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/models/ipadapter/ip-adapter-plus-face_sdxl_vit-h.safetensors"
)
ESRGAN_MODELS=(
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/models/upscale_models/RealESRGAN_x4plus_anime_6B.pth"
)
WORKFLOWS=(
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/Single_Posture_ko.json"
)
log_info() { echo "--> $1"; }
log_warn() { echo " β οΈ $1"; }
log_error() { echo " β $1"; }
log_success() { echo " β
$1"; }
log_step() { echo ""; echo "=== [Step $1] $2 ==="; }
package_installed() {
$PYTHON_BIN -c "import $1" 2>/dev/null && return 0 || return 1
}
filter_requirements() {
local req_file="$1"
local tmp_file="${req_file}.filtered"
> "$tmp_file"
while IFS= read -r line; do
[[ -z "$line" || "$line" =~ ^# ]] && continue
local pkg_name
pkg_name=$(echo "$line" | sed 's/[<>=!].*//' | xargs)
if [[ -z "$pkg_name" ]]; then continue; fi
local module_name="${pkg_name//-/_}"
if package_installed "$module_name"; then
log_info "μ€μΉλ ν¨ν€μ§ 건λλ°κΈ°: $pkg_name"
else
echo "$line" >> "$tmp_file"
fi
done < "$req_file"
if [ -s "$tmp_file" ]; then
mv "$tmp_file" "$req_file"
return 0
else
rm -f "$tmp_file"
log_info "λͺ¨λ ν¨ν€μ§κ° μ΄λ―Έ μ€μΉλμμ΅λλ€"
return 1
fi
}
provisioning_has_valid_hf_token() {
[[ -n "${HF_TOKEN:-}" ]] || return 1
local response
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://huggingface.co/api/whoami-v2" -H "Authorization: Bearer $HF_TOKEN" -H "Content-Type: application/json")
[ "$response" -eq 200 ]
}
provisioning_has_valid_civitai_token() {
[[ -n "${CIVITAI_TOKEN:-}" ]] || return 1
local response
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://civitai.com/api/v1/models?hidden=1&limit=1" -H "Authorization: Bearer $CIVITAI_TOKEN" -H "Content-Type: application/json")
[ "$response" -eq 200 ]
}
install_node() {
local repo_url="$1"
local repo_name
repo_name=$(basename "$repo_url" .git)
local install_path="${COMFYUI_DIR}/custom_nodes/${repo_name}"
if [ -d "$install_path" ]; then
if [[ "${AUTO_UPDATE:-true}" != "false" ]]; then
log_info "λ
Έλ μ
λ°μ΄νΈ: $repo_name"
(cd "$install_path" && git pull -q 2>&1 | grep -v "Already up to date" || true)
else
log_info "'$repo_name'μ΄(κ°) μ΄λ―Έ μ‘΄μ¬ν©λλ€. 건λλλλ€"
return
fi
else
log_info "λ
Έλ 볡μ : $repo_name"
git clone --depth 1 --single-branch "$repo_url" "$install_path" -q 2>&1 || true
fi
if [ -f "$install_path/requirements.txt" ]; then
log_info "$repo_nameμ μ’
μμ± μ²λ¦¬ μ€..."
sed -i -e '/^torch/d' -e '/^sam2/d' "$install_path/requirements.txt" 2>/dev/null || true
if filter_requirements "$install_path/requirements.txt"; then
log_info "$repo_nameμ μλ‘μ΄ μ’
μμ± μ€μΉ μ€..."
$PIP_BIN install -q --no-cache-dir -r "$install_path/requirements.txt" 2>&1 | grep -v "Requirement already satisfied" || log_warn "μΌλΆ μ’
μμ± μ€μΉ μ€ν¨"
fi
fi
if [ -f "$install_path/install.py" ]; then
log_info "$repo_nameμ μ€μΉ μ€ν¬λ¦½νΈ μ€ν μ€..."
$PYTHON_BIN "$install_path/install.py" 2>&1 || log_warn "μ€μΉ μ€ν¬λ¦½νΈ μ€ν μ€ν¨"
fi
}
download_file() {
local dest_path="$1"
local url="$2"
local filename
filename=$(basename "$dest_path")
local tmp_path="${dest_path}.tmp"
mkdir -p "$(dirname "$dest_path")"
if [ -s "$dest_path" ]; then
log_info "νμΌ '$filename'μ΄(κ°) μ΄λ―Έ μ‘΄μ¬νκ³ μμ ν©λλ€. λ€μ΄λ‘λλ₯Ό 건λλλλ€"
return 0
fi
log_info "λ€μ΄λ‘λ: $filename"
local max_retries=3
local attempt=0
local auth_header=""
local success=1
if [[ "$url" =~ huggingface\.co ]] && provisioning_has_valid_hf_token; then
auth_header="Authorization: Bearer $HF_TOKEN"
log_info "HuggingFace ν ν° μ¬μ©"
elif [[ "$url" =~ civitai\.com ]] && provisioning_has_valid_civitai_token; then
auth_header="Authorization: Bearer $CIVITAI_TOKEN"
log_info "CivitAI ν ν° μ¬μ©"
fi
while [ "$attempt" -lt "$max_retries" ]; do
attempt=$((attempt + 1))
[ "$attempt" -gt 1 ] && sleep 10
if command -v aria2c >/dev/null 2>&1; then
log_info "aria2c (3 μ€λ λ)λ‘ λ€μ΄λ‘λ: $filename (μλ $attempt/$max_retries)"
local aria_opts=(--console-log-level=error -c -x 3 -s 3 -k 1M --max-connection-per-server=3 --max-tries=3 --retry-wait=5 --timeout=180 --file-allocation=falloc --auto-file-renaming=false -d "$(dirname "$dest_path")" -o "${filename}.tmp")
[[ -n "$auth_header" ]] && aria_opts+=(--header="$auth_header")
aria2c "${aria_opts[@]}" "$url"
if [ $? -eq 0 ]; then success=0; break; fi
else
log_info "wgetμΌλ‘ λ€μ΄λ‘λ: $filename (μλ $attempt/$max_retries)"
local wget_opts=(-O "$tmp_path" -c --timeout=60 --tries=3 --content-disposition --show-progress)
[[ -n "$auth_header" ]] && wget_opts+=(--header="$auth_header")
wget "${wget_opts[@]}" "$url"
if [ $? -eq 0 ]; then success=0; break; fi
fi
done
if [ "$success" -eq 0 ] && [ -s "$tmp_path" ]; then
mv "$tmp_path" "$dest_path"
log_success "λ€μ΄λ‘λ μλ£: $filename"
return 0
else
log_error "λ€μ΄λ‘λ μ€ν¨: $filename"
rm -f "$tmp_path"
return 1
fi
}
download_to_directory() {
local dest_dir="$1"; shift; local urls=("$@")
if [ ${#urls[@]} -eq 0 ]; then return 0; fi
mkdir -p "$dest_dir"
log_info "${#urls[@]}κ°μ νμΌμ $dest_dir(μΌ)λ‘ λ€μ΄λ‘λ μ€"
local MAX_PARALLEL=3
for url in "${urls[@]}"; do
while [ $(jobs -r | wc -l) -ge $MAX_PARALLEL ]; do sleep 1; done
local filename
filename=$(basename "$url" | sed 's/?.*//')
download_file "${dest_dir}/${filename}" "$url" &
done
wait
}
verify_and_retry_downloads() {
local dest_dir="$1"; shift; local urls=("$@")
if [ ${#urls[@]} -eq 0 ]; then return 0; fi
log_info "$dest_dirμ νμΌ νμΈ μ€..."
local missing_files=()
for url in "${urls[@]}"; do
local filename
filename=$(basename "$url" | sed 's/?.*//')
local dest_path="${dest_dir}/${filename}"
if [ ! -s "$dest_path" ]; then
log_warn "νμΌ λλ½ λλ λΆμμ : $filename"
missing_files+=("$url")
fi
done
if [ ${#missing_files[@]} -gt 0 ]; then
log_warn "${#missing_files[@]}κ°μ λλ½/λΆμμ ν νμΌ λ°κ²¬, μ¬λ€μ΄λ‘λ μ€..."
download_to_directory "$dest_dir" "${missing_files[@]}"
else
log_success "λͺ¨λ νμΌμ΄ μ‘΄μ¬νκ³ μμ ν κ²μΌλ‘ νμΈλμμ΅λλ€"
fi
}
provisioning_print_header() {
echo ""; echo "##############################################"
echo "# #"
echo "# νλ‘λΉμ λ 컨ν
μ΄λ #"
echo "# #"
echo "# μκ°μ΄ μ’ κ±Έλ¦΄ μ μμ΅λλ€ #"
echo "# #"
echo "##############################################"; echo ""
}
provisioning_print_end() {
echo ""; echo "##############################################"
echo "# #"
echo "# νλ‘λΉμ λ μλ£! #"
echo "# #"
echo "# Total time: $((END_TIME - START_TIME)) seconds #"
echo "# #"
echo "##############################################"; echo ""
}
provisioning_step1_install_core_deps() {
log_step "1" "μμ€ν
λ° ComfyUI ν΅μ¬ μ’
μμ± μ€μΉ"
if [ ${#APT_PACKAGES[@]} -gt 0 ]; then
log_info "${#APT_PACKAGES[@]}κ°μ μμ€ν
ν¨ν€μ§ μ€μΉ μ€λΉ μ€..."
local packages_to_install=()
for pkg in "${APT_PACKAGES[@]}"; do
if ! dpkg -s "$pkg" >/dev/null 2>&1; then
packages_to_install+=("$pkg")
else
log_success "$pkgμ΄(κ°) μ΄λ―Έ μ€μΉλμ΄ μμ΅λλ€. 건λλλλ€"
fi
done
if [ ${#packages_to_install[@]} -gt 0 ]; then
log_info "μ€μΉ μ€: ${packages_to_install[*]}"
apt-get update -qq && apt-get install -y -qq "${packages_to_install[@]}" && log_success "μμ€ν
ν¨ν€μ§ μ€μΉ μλ£" || log_warn "μΌλΆ μμ€ν
ν¨ν€μ§ μ€μΉ μ€ν¨"
fi
fi
local comfyui_req_file="${COMFYUI_DIR}/requirements.txt"
if [ -f "$comfyui_req_file" ]; then
log_info "ComfyUI ν΅μ¬ μ’
μμ± μ²λ¦¬ μ€: $comfyui_req_file"
if filter_requirements "$comfyui_req_file"; then
log_info "ComfyUIμ μλ‘μ΄ μ’
μμ± μ€μΉ μ€..."
$PIP_BIN install -q --no-cache-dir -r "$comfyui_req_file" 2>&1 | grep -v "Requirement already satisfied" || log_warn "ComfyUI μΌλΆ ν΅μ¬ μ’
μμ± μ€μΉ μ€ν¨"
fi
else
log_warn "ComfyUIμ ν΅μ¬ requirements.txt νμΌμ μ°Ύμ μ μμ΅λλ€!"
fi
}
provisioning_step2_nodes() {
log_step "2" "λ
Έλ λ° μΆκ° ν¨ν€μ§ μ€μΉ"
if [ ${#NODES[@]} -gt 0 ]; then
cd "${COMFYUI_DIR}/custom_nodes" || exit 1
log_info "${#NODES[@]}κ°μ λ
Έλλ₯Ό λ³λ ¬ μ€μΉ μ€..."
local MAX_PARALLEL=2
for node in "${NODES[@]}"; do
while [ $(jobs -r | wc -l) -ge $MAX_PARALLEL ]; do sleep 1; done
install_node "$node" &
done
wait
log_success "λ
Έλ μ€μΉ μλ£"
cd "${COMFYUI_DIR}" || exit 1
fi
}
provisioning_step3_downloads() {
log_step "3" "λͺ¨λΈ λ° μν¬νλ‘μ° νμΌ λ€μ΄λ‘λ"
download_to_directory "${COMFYUI_DIR}/models/checkpoints" "${CHECKPOINT_MODELS[@]}"
download_to_directory "${COMFYUI_DIR}/models/clip_vision" "${CLIP_VISION_MODELS[@]}"
download_to_directory "${COMFYUI_DIR}/models/ipadapter" "${IPADAPTER_MODELS[@]}"
download_to_directory "${COMFYUI_DIR}/models/upscale_models" "${ESRGAN_MODELS[@]}"
if [ ${#WORKFLOWS[@]} -gt 0 ]; then
log_info "μν¬νλ‘μ° νμΌ λ€μ΄λ‘λ μ€..."
download_to_directory "${COMFYUI_DIR}/user/default/workflows" "${WORKFLOWS[@]}"
fi
}
if [ -f "/workspace/.provision_complete" ]; then
log_success "νκ²½μ΄ κ΅¬μ±λμμ΅λλ€. λ°λ³΅ μ€νμ 건λλλλ€"
log_info "μ¬κ΅¬μ±νλ €λ©΄ /workspace/.provision_completeλ₯Ό μμ νμμμ€"
exit 0
fi
if [[ -f /.noprovisioning ]]; then
log_warn "/.noprovisioning νμΌ κ°μ§λ¨, ꡬμ±μ 건λλλλ€"
exit 0
fi
START_TIME=$(date +%s)
provisioning_print_header
cd "${COMFYUI_DIR}" || exit 1
provisioning_step1_install_core_deps
provisioning_step2_nodes &
NODE_PID=$!
provisioning_step3_downloads
wait $NODE_PID
log_step "4" "λ€μ΄λ‘λ λ¬΄κ²°μ± νμΈ"
verify_and_retry_downloads "${COMFYUI_DIR}/models/checkpoints" "${CHECKPOINT_MODELS[@]}"
verify_and_retry_downloads "${COMFYUI_DIR}/models/clip_vision" "${CLIP_VISION_MODELS[@]}"
verify_and_retry_downloads "${COMFYUI_DIR}/models/ipadapter" "${IPADAPTER_MODELS[@]}"
verify_and_retry_downloads "${COMFYUI_DIR}/models/upscale_models" "${ESRGAN_MODELS[@]}"
verify_and_retry_downloads "${COMFYUI_DIR}/user/default/workflows" "${WORKFLOWS[@]}"
log_step "5" "κ΅¬μ± μλ£"
touch "/workspace/.provision_complete"
log_success "κ΅¬μ± λ§μ»€ νμΌμ΄ μμ±λμμ΅λλ€"
END_TIME=$(date +%s)
provisioning_print_end
log_success "λͺ¨λ κ΅¬μ± λ¨κ³κ° μλ£λμμ΅λλ€!"
exit 0 |