Update image_Studio.sh
Browse files- image_Studio.sh +672 -341
image_Studio.sh
CHANGED
|
@@ -1,393 +1,724 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
-
#
|
| 3 |
-
#
|
| 4 |
-
# - Ambiente isolado em venv (sem poluir Python do sistema)
|
| 5 |
-
# - Torch/Torchvision/Torchaudio sempre compatíveis (um único passo)
|
| 6 |
-
# - Estado persistente com retomada de steps, downloads e nodes
|
| 7 |
-
# - Downloads com retry/timeout e suporte Mega/HF/HTTP(s)
|
| 8 |
-
# - Layout e variáveis fáceis de editar (manifesto inline)
|
| 9 |
|
| 10 |
-
set -
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
COMFY_PORT=${COMFY_PORT:-"8818"}
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
MODELS_DIR="$COMFY_DIR/models"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
STATE_DIR
|
| 29 |
-
STATE_FILE="$STATE_DIR/
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
mkdir -p "$STATE_DIR"
|
| 33 |
-
: > "$DONE_DL" 2>/dev/null || true
|
| 34 |
-
: > "$DONE_NODE" 2>/dev/null || true
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
https://civitai.com/api/download/models/1268294?type=Model&format=SafeTensor|loras|
|
| 55 |
-
https://civitai.com/api/download/models/1715330?type=Model&format=SafeTensor|loras|
|
| 56 |
-
https://civitai.com/api/download/models/1499397?type=Model&format=SafeTensor|loras|
|
| 57 |
-
https://civitai.com/api/download/models/1779002?type=Model&format=SafeTensor|loras|
|
| 58 |
-
https://civitai.com/api/download/models/1114313?type=Model&format=SafeTensor|loras|
|
| 59 |
-
https://civitai.com/api/download/models/1780244?type=Model&format=SafeTensor|loras|
|
| 60 |
-
mega://https://mega.nz/file/gIRTFQSQ#no6Ay3JLE9LVRi7ib9O-Jc0CW7XmG046kCgpCzDg1tY|loras|
|
| 61 |
-
https://huggingface.co/Kim2091/AnimeSharp/resolve/main/4x-AnimeSharp.pth|upscale_models|4x-AnimeSharp.pth
|
| 62 |
-
https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth
|
| 63 |
-
https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth
|
| 64 |
-
https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2.pth|upscale_models|4x-UltraSharpV2.pth
|
| 65 |
-
https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_Lite.pth|upscale_models|4x-UltraSharpV2_Lite.pth
|
| 66 |
-
https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_fp32_op17.onnx|upscale_models|4x-UltraSharpV2_fp32_op17.onnx
|
| 67 |
-
https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt
|
| 68 |
-
EOF
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
https://github.com/adbrasi/randomsizito
|
| 84 |
-
https://github.com/adbrasi/importex
|
| 85 |
-
https://github.com/adbrasi/storitadifusita
|
| 86 |
-
https://github.com/adbrasi/attentionPPM
|
| 87 |
-
https://github.com/ClownsharkBatwing/RES4LYF
|
| 88 |
-
https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes
|
| 89 |
-
https://github.com/sipherxyz/comfyui-art-venture
|
| 90 |
-
https://github.com/pamparamm/sd-perturbed-attention
|
| 91 |
-
https://github.com/KoreTeknology/ComfyUI-Universal-Styler
|
| 92 |
-
https://github.com/WASasquatch/was-node-suite-comfyui
|
| 93 |
-
https://github.com/chflame163/ComfyUI_LayerStyle
|
| 94 |
-
https://github.com/ltdrdata/ComfyUI-Impact-Pack
|
| 95 |
-
https://github.com/pythongosssss/ComfyUI-Custom-Scripts
|
| 96 |
-
https://github.com/rgthree/rgthree-comfy
|
| 97 |
-
https://github.com/ssitu/ComfyUI_UltimateSDUpscale
|
| 98 |
-
https://github.com/adbrasi/Importador
|
| 99 |
-
https://github.com/adbrasi/GetFirstTag
|
| 100 |
-
https://github.com/adbrasi/comfydodi
|
| 101 |
-
https://github.com/omar92/ComfyUI-QualityOfLifeSuit_Omar92
|
| 102 |
-
https://github.com/Cezarsaint/blacklisto
|
| 103 |
-
https://github.com/TinyTerra/ComfyUI_tinyterraNodes
|
| 104 |
-
https://github.com/ltdrdata/ComfyUI-Impact-Subpack
|
| 105 |
-
https://github.com/Cezarsaint/rand0micoUploaderLoven
|
| 106 |
-
https://github.com/adbrasi/pixivmosaic
|
| 107 |
-
https://github.com/adbrasi/futfilter
|
| 108 |
-
https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit
|
| 109 |
-
https://github.com/shiimizu/ComfyUI_smZNodes
|
| 110 |
-
https://github.com/CoreyCorza/ComfyUI-CRZnodes
|
| 111 |
-
)
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
was_done(){ local f="$1"; shift; local key="$*"; grep -Fxq "$key" "$f" 2>/dev/null; }
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
log_step "[1/7] Instalando dependências do SO (git, curl, wget, aria2, megatools, python3-venv)…"
|
| 123 |
-
export DEBIAN_FRONTEND=noninteractive
|
| 124 |
-
apt-get update -qq
|
| 125 |
-
apt-get install -y -qq git curl wget aria2 megatools python3 python3-venv ca-certificates
|
| 126 |
-
log_ok "Dependências do SO OK"
|
| 127 |
-
save_state 1
|
| 128 |
}
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
if [[ ! -x "$PYTHON" ]]; then
|
| 134 |
-
mkdir -p "$COMFY_DIR"
|
| 135 |
-
python3 -m venv "$VENV_DIR"
|
| 136 |
-
fi
|
| 137 |
-
"$PIP" install -q --upgrade pip wheel setuptools
|
| 138 |
-
# Login opcional no HF
|
| 139 |
-
if [[ -n "$HF_TOKEN" ]]; then
|
| 140 |
-
"$PYTHON" -m pip install -q huggingface_hub[cli,hf_transfer]
|
| 141 |
-
"$VENV_DIR/bin/hf" auth login --token "$HF_TOKEN" || log_warn "HF auth falhou (seguindo sem login)"
|
| 142 |
-
fi
|
| 143 |
-
log_ok "Venv OK"
|
| 144 |
-
save_state 2
|
| 145 |
}
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
local use_nightly=0
|
| 152 |
-
if echo "$gpu_name" | grep -Eqi "5090|5080|blackwell"; then use_nightly=1; fi
|
| 153 |
|
| 154 |
-
|
| 155 |
-
log_warn "
|
| 156 |
-
"$
|
| 157 |
-
|
| 158 |
-
torch torchvision torchaudio
|
| 159 |
-
else
|
| 160 |
-
log_info "GPU: ${gpu_name:-Não detectada}. Usando *estável cu128*."
|
| 161 |
-
"$PIP" install -q \
|
| 162 |
-
--index-url https://download.pytorch.org/whl/cu128 \
|
| 163 |
-
torch torchvision torchaudio
|
| 164 |
-
fi
|
| 165 |
-
log_ok "Torch stack OK"
|
| 166 |
-
save_state 3
|
| 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 |
fi
|
| 200 |
-
fi
|
| 201 |
-
printf '%s' "$url"
|
| 202 |
}
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
else
|
| 214 |
-
aria2c "${args[@]}" --dir="$dir" "$final_url" && return 0
|
| 215 |
fi
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
else
|
| 222 |
-
|
|
|
|
|
|
|
| 223 |
fi
|
| 224 |
-
fi
|
| 225 |
-
# curl fallback
|
| 226 |
-
local cargs=("-L" "--retry" "$RETRIES" "--connect-timeout" "$CONNECT_TIMEOUT" "--max-time" "$DL_TIMEOUT" "-C" "-")
|
| 227 |
-
if [[ -n "$name" ]]; then
|
| 228 |
-
curl -sS "${cargs[@]}" -o "$dir/$name" "$final_url" && return 0
|
| 229 |
-
else
|
| 230 |
-
# tentar extrair nome do header
|
| 231 |
-
local detected=$(curl -sI -L "$final_url" | sed -n 's/.*filename="\([^"]\+\)".*/\1/p' | tr -d '\r' | head -1)
|
| 232 |
-
[[ -z "$detected" ]] && detected="download_$(date +%s)"
|
| 233 |
-
curl -sS "${cargs[@]}" -o "$dir/$detected" "$final_url" && return 0
|
| 234 |
-
fi
|
| 235 |
-
return 1
|
| 236 |
}
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
if [[ -n "$name" ]]; then
|
| 246 |
-
# renomeia para nome fixo, mantendo o arquivo único baixado
|
| 247 |
-
local got=$(find "$dir" -maxdepth 1 -type f -printf '%f\n' | tail -n 1)
|
| 248 |
-
[[ -n "$got" ]] && mv -f "$dir/$got" "$dir/$name"
|
| 249 |
fi
|
| 250 |
-
return 0
|
| 251 |
-
fi
|
| 252 |
-
return 1
|
| 253 |
}
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
if [[ -n "$name" ]]; then
|
| 265 |
-
local got=$(find "$dir" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.onnx" -o -name "*.bin" \) | head -1)
|
| 266 |
-
[[ -n "$got" ]] && mv -f "$got" "$dir/$name"
|
| 267 |
fi
|
| 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 |
else
|
| 300 |
-
|
| 301 |
fi
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
save_state 5
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
# ====== Custom Nodes ======
|
| 308 |
-
clone_or_update(){ # url dest
|
| 309 |
-
local url="$1"; local dest="$2"; local key="node:$url"
|
| 310 |
-
if was_done "$DONE_NODE" "$key" && [[ -d "$dest" ]]; then log_ok "Node OK: $(basename "$dest")"; return 0; fi
|
| 311 |
-
if [[ -d "$dest/.git" ]]; then
|
| 312 |
-
git -C "$dest" pull --ff-only || log_warn "pull falhou: $(basename "$dest")"
|
| 313 |
-
else
|
| 314 |
-
git clone --depth 1 "$url" "$dest" || { log_warn "clone falhou: $url"; return 0; }
|
| 315 |
-
fi
|
| 316 |
-
# requirements do node (best-effort)
|
| 317 |
-
if [[ -f "$dest/requirements.txt" ]]; then
|
| 318 |
-
"$PIP" install -q -r "$dest/requirements.txt" || log_warn "pip req falhou em $(basename "$dest")"
|
| 319 |
-
fi
|
| 320 |
-
mark_done "$DONE_NODE" "$key"
|
| 321 |
}
|
| 322 |
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
}
|
| 337 |
|
| 338 |
-
# ====== Verificação final & execução ======
|
| 339 |
-
final_check(){
|
| 340 |
-
log_step "[7/7] Verificação final…"
|
| 341 |
-
[[ -f "$COMFY_DIR/main.py" ]] && log_ok "ComfyUI presente" || { log_err "ComfyUI ausente"; exit 1; }
|
| 342 |
-
# contagens
|
| 343 |
-
for d in checkpoints loras vae vae_approx text_encoders clip_vision upscale_models ultralytics; do
|
| 344 |
-
local p="$MODELS_DIR/$d"; [[ -d "$p" ]] || continue
|
| 345 |
-
local c=$(find "$p" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.ckpt" -o -name "*.onnx" \) 2>/dev/null | wc -l || echo 0)
|
| 346 |
-
(( c > 0 )) && log_ok "$d: $c arquivo(s)"
|
| 347 |
-
done
|
| 348 |
-
local gpu="$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo "Não detectada")"
|
| 349 |
-
log_info "GPU: $gpu"
|
| 350 |
-
save_state 7
|
| 351 |
-
}
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
}
|
| 358 |
|
| 359 |
-
#
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
echo "Opções:"
|
| 382 |
echo " 1) Iniciar ComfyUI agora"
|
| 383 |
-
echo " 2)
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
esac
|
| 390 |
-
fi
|
| 391 |
}
|
| 392 |
|
| 393 |
-
|
|
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
+
# setup_comfyui_custom_v2.sh
|
| 3 |
+
# Script otimizado com suporte para RTX 5090, estado persistente e downloads do Mega
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
set -euo pipefail
|
| 6 |
|
| 7 |
+
# Detectar se está rodando via pipe (não-interativo)
|
| 8 |
+
if [ ! -t 0 ] || [ ! -t 1 ]; then
|
| 9 |
+
INTERACTIVE=false
|
| 10 |
+
else
|
| 11 |
+
INTERACTIVE=true
|
| 12 |
+
fi
|
|
|
|
| 13 |
|
| 14 |
+
# -----------------------------
|
| 15 |
+
# Cores para output
|
| 16 |
+
# -----------------------------
|
| 17 |
+
RED='\033[0;31m'
|
| 18 |
+
GREEN='\033[0;32m'
|
| 19 |
+
YELLOW='\033[1;33m'
|
| 20 |
+
BLUE='\033[0;34m'
|
| 21 |
+
CYAN='\033[0;36m'
|
| 22 |
+
NC='\033[0m'
|
| 23 |
|
| 24 |
+
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
| 25 |
+
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
| 26 |
+
log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
|
| 27 |
+
log_error() { echo -e "${RED}[✗]${NC} $1"; }
|
| 28 |
+
log_progress() { echo -e "${CYAN}[→]${NC} $1"; }
|
| 29 |
+
|
| 30 |
+
# -----------------------------
|
| 31 |
+
# Configuração
|
| 32 |
+
# -----------------------------
|
| 33 |
+
COMFY_DIR="/root/comfy/ComfyUI"
|
| 34 |
MODELS_DIR="$COMFY_DIR/models"
|
| 35 |
+
COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
|
| 36 |
+
COMFY_PORT="${COMFY_PORT:-8818}"
|
| 37 |
+
CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
|
| 38 |
+
HF_TOKEN="${HF_TOKEN:-}"
|
| 39 |
|
| 40 |
+
# Diretório para salvar estado
|
| 41 |
+
STATE_DIR="/root/.comfyui_setup_state"
|
| 42 |
+
STATE_FILE="$STATE_DIR/installation_state.txt"
|
| 43 |
+
COMPLETED_DOWNLOADS="$STATE_DIR/completed_downloads.txt"
|
| 44 |
+
COMPLETED_NODES="$STATE_DIR/completed_nodes.txt"
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Configurações de performance
|
| 47 |
+
export MAX_JOBS=32
|
| 48 |
+
export NVCC_APPEND_FLAGS="--threads 8"
|
| 49 |
+
export UV_SYSTEM_PYTHON=1
|
| 50 |
+
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
|
| 51 |
+
export HF_HUB_ENABLE_HF_TRANSFER=1
|
| 52 |
+
export HF_TRANSFER_CONCURRENCY=16
|
| 53 |
+
export EXT_PARALLEL=4
|
| 54 |
|
| 55 |
+
# -----------------------------
|
| 56 |
+
# Sistema de Estado Persistente
|
| 57 |
+
# -----------------------------
|
| 58 |
+
init_state() {
|
| 59 |
+
mkdir -p "$STATE_DIR"
|
| 60 |
+
touch "$STATE_FILE" "$COMPLETED_DOWNLOADS" "$COMPLETED_NODES"
|
| 61 |
+
}
|
| 62 |
|
| 63 |
+
save_state() {
|
| 64 |
+
local step="$1"
|
| 65 |
+
echo "$step" > "$STATE_FILE"
|
| 66 |
+
log_info "Estado salvo: $step"
|
| 67 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
get_state() {
|
| 70 |
+
if [ -f "$STATE_FILE" ]; then
|
| 71 |
+
local state=$(cat "$STATE_FILE" 2>/dev/null)
|
| 72 |
+
# Verificar se é um número válido
|
| 73 |
+
if [[ "$state" =~ ^[0-9]+$ ]]; then
|
| 74 |
+
echo "$state"
|
| 75 |
+
else
|
| 76 |
+
echo "0"
|
| 77 |
+
fi
|
| 78 |
+
else
|
| 79 |
+
echo "0"
|
| 80 |
+
fi
|
| 81 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
mark_download_complete() {
|
| 84 |
+
local url="$1"
|
| 85 |
+
echo "$url" >> "$COMPLETED_DOWNLOADS"
|
| 86 |
+
}
|
|
|
|
| 87 |
|
| 88 |
+
is_download_complete() {
|
| 89 |
+
local url="$1"
|
| 90 |
+
grep -Fxq "$url" "$COMPLETED_DOWNLOADS" 2>/dev/null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
+
mark_node_complete() {
|
| 94 |
+
local node="$1"
|
| 95 |
+
echo "$node" >> "$COMPLETED_NODES"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
+
is_node_complete() {
|
| 99 |
+
local node="$1"
|
| 100 |
+
grep -Fxq "$node" "$COMPLETED_NODES" 2>/dev/null
|
| 101 |
+
}
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
reset_state() {
|
| 104 |
+
log_warn "Resetando estado da instalação..."
|
| 105 |
+
rm -rf "$STATE_DIR"
|
| 106 |
+
init_state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
|
| 109 |
+
# -----------------------------
|
| 110 |
+
# Lista de downloads (ATUALIZADA - sem ControlNet)
|
| 111 |
+
# -----------------------------
|
| 112 |
+
readonly DOWNLOAD_FILES=(
|
| 113 |
+
# Checkpoint mantido
|
| 114 |
+
"https://civitai.com/api/download/models/2122278?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|raehoshiIllustXL_v60.safetensors"
|
| 115 |
+
|
| 116 |
+
# LoRAs from Civitai
|
| 117 |
+
"https://civitai.com/api/download/models/1268294?type=Model&format=SafeTensor|loras|"
|
| 118 |
+
"https://civitai.com/api/download/models/1715330?type=Model&format=SafeTensor|loras|"
|
| 119 |
+
"https://civitai.com/api/download/models/1499397?type=Model&format=SafeTensor|loras|"
|
| 120 |
+
"https://civitai.com/api/download/models/1779002?type=Model&format=SafeTensor|loras|"
|
| 121 |
+
"https://civitai.com/api/download/models/1114313?type=Model&format=SafeTensor|loras|"
|
| 122 |
+
"https://civitai.com/api/download/models/1780244?type=Model&format=SafeTensor|loras|"
|
| 123 |
+
|
| 124 |
+
# LoRA from Mega (nome automático pelo megadl)
|
| 125 |
+
"mega://https://mega.nz/file/gIRTFQSQ#no6Ay3JLE9LVRi7ib9O-Jc0CW7XmG046kCgpCzDg1tY|loras|"
|
| 126 |
+
|
| 127 |
+
# Upscale models - Coleção completa
|
| 128 |
+
"https://huggingface.co/Kim2091/AnimeSharp/resolve/main/4x-AnimeSharp.pth|upscale_models|4x-AnimeSharp.pth"
|
| 129 |
+
"https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth"
|
| 130 |
+
"https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth"
|
| 131 |
+
"https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2.pth|upscale_models|4x-UltraSharpV2.pth"
|
| 132 |
+
"https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_Lite.pth|upscale_models|4x-UltraSharpV2_Lite.pth"
|
| 133 |
+
"https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_fp32_op17.onnx|upscale_models|4x-UltraSharpV2_fp32_op17.onnx"
|
| 134 |
+
|
| 135 |
+
# Ultralytics model
|
| 136 |
+
"https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt"
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
# Custom nodes para instalar (ATUALIZADA com novos nodes)
|
| 140 |
+
readonly CUSTOM_NODES=(
|
| 141 |
+
"https://github.com/adbrasi/huggpackreator"
|
| 142 |
+
"https://github.com/adbrasi/packreator_processor"
|
| 143 |
+
"https://github.com/adbrasi/Packreator_manager"
|
| 144 |
+
"https://github.com/adbrasi/cezarsave34"
|
| 145 |
+
"https://github.com/adbrasi/pageonetor"
|
| 146 |
+
"https://github.com/adbrasi/pakreatorio"
|
| 147 |
+
"https://github.com/adbrasi/WaterMark_bumbumzin"
|
| 148 |
+
"https://github.com/adbrasi/marcadaguita"
|
| 149 |
+
"https://github.com/adbrasi/randomico"
|
| 150 |
+
"https://github.com/adbrasi/groqrouter"
|
| 151 |
+
"https://github.com/adbrasi/find_charakito"
|
| 152 |
+
"https://github.com/adbrasi/randomsizito"
|
| 153 |
+
"https://github.com/adbrasi/importex"
|
| 154 |
+
"https://github.com/adbrasi/storitadifusita"
|
| 155 |
+
"https://github.com/adbrasi/attentionPPM"
|
| 156 |
+
"https://github.com/ClownsharkBatwing/RES4LYF"
|
| 157 |
+
"https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
|
| 158 |
+
"https://github.com/sipherxyz/comfyui-art-venture"
|
| 159 |
+
"https://github.com/pamparamm/sd-perturbed-attention"
|
| 160 |
+
"https://github.com/KoreTeknology/ComfyUI-Universal-Styler"
|
| 161 |
+
"https://github.com/WASasquatch/was-node-suite-comfyui"
|
| 162 |
+
"https://github.com/chflame163/ComfyUI_LayerStyle"
|
| 163 |
+
"https://github.com/ltdrdata/ComfyUI-Impact-Pack"
|
| 164 |
+
"https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
|
| 165 |
+
"https://github.com/rgthree/rgthree-comfy"
|
| 166 |
+
"https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
|
| 167 |
+
"https://github.com/adbrasi/Importador"
|
| 168 |
+
"https://github.com/adbrasi/GetFirstTag"
|
| 169 |
+
"https://github.com/adbrasi/comfydodi"
|
| 170 |
+
"https://github.com/omar92/ComfyUI-QualityOfLifeSuit_Omar92"
|
| 171 |
+
"https://github.com/Cezarsaint/blacklisto"
|
| 172 |
+
"https://github.com/TinyTerra/ComfyUI_tinyterraNodes"
|
| 173 |
+
"https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
|
| 174 |
+
"https://github.com/Cezarsaint/rand0micoUploaderLoven"
|
| 175 |
+
"https://github.com/adbrasi/pixivmosaic"
|
| 176 |
+
"https://github.com/adbrasi/futfilter"
|
| 177 |
+
"https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit"
|
| 178 |
+
"https://github.com/shiimizu/ComfyUI_smZNodes"
|
| 179 |
+
"https://github.com/CoreyCorza/ComfyUI-CRZnodes"
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Custom nodes que precisam de instalação especial via comfy-cli
|
| 183 |
+
readonly SPECIAL_NODES=(
|
| 184 |
+
"Civicomfy"
|
| 185 |
+
"ComfyUI-RMBG"
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
# -----------------------------
|
| 189 |
+
# Funções auxiliares
|
| 190 |
+
# -----------------------------
|
| 191 |
+
command_exists() {
|
| 192 |
+
command -v "$1" >/dev/null 2>&1
|
| 193 |
}
|
| 194 |
|
| 195 |
+
# Instalar megatools se necessário
|
| 196 |
+
install_megatools() {
|
| 197 |
+
if ! command_exists megadl; then
|
| 198 |
+
log_info "Instalando megatools para downloads do Mega..."
|
| 199 |
+
apt-get update -qq && apt-get install -y -qq megatools 2>/dev/null
|
| 200 |
+
if command_exists megadl; then
|
| 201 |
+
log_success "Megatools instalado com sucesso"
|
| 202 |
+
else
|
| 203 |
+
log_warn "Falha ao instalar megatools, downloads do Mega não estarão disponíveis"
|
| 204 |
+
fi
|
| 205 |
fi
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
|
| 208 |
+
# Download do Mega
|
| 209 |
+
download_mega() {
|
| 210 |
+
local url="$1"
|
| 211 |
+
local target_dir="$2"
|
| 212 |
+
local filename="$3"
|
| 213 |
+
|
| 214 |
+
if ! command_exists megadl; then
|
| 215 |
+
log_error "megatools não instalado"
|
| 216 |
+
return 1
|
|
|
|
|
|
|
| 217 |
fi
|
| 218 |
+
|
| 219 |
+
# Remover prefixo mega:// se houver
|
| 220 |
+
url="${url#mega://}"
|
| 221 |
+
|
| 222 |
+
log_info "Baixando do Mega para $target_dir"
|
| 223 |
+
|
| 224 |
+
# Usar megadl simples como você sempre usa
|
| 225 |
+
cd "$target_dir"
|
| 226 |
+
if megadl "$url"; then
|
| 227 |
+
# Se especificou nome, renomear
|
| 228 |
+
if [ -n "$filename" ]; then
|
| 229 |
+
# Encontrar o arquivo baixado (o mais recente)
|
| 230 |
+
local downloaded=$(ls -t | head -1)
|
| 231 |
+
if [ -n "$downloaded" ] && [ "$downloaded" != "$filename" ]; then
|
| 232 |
+
mv "$downloaded" "$filename"
|
| 233 |
+
fi
|
| 234 |
+
fi
|
| 235 |
+
log_success "Download do Mega concluído"
|
| 236 |
+
cd - >/dev/null
|
| 237 |
+
return 0
|
| 238 |
else
|
| 239 |
+
log_error "Falha no download do Mega"
|
| 240 |
+
cd - >/dev/null
|
| 241 |
+
return 1
|
| 242 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
}
|
| 244 |
|
| 245 |
+
# Adicionar token do Civitai se necessário
|
| 246 |
+
add_civitai_token() {
|
| 247 |
+
local url="$1"
|
| 248 |
+
if [[ "$url" == *"civitai.com/api/download"* ]] && [[ "$url" != *"token="* ]]; then
|
| 249 |
+
echo "${url}&token=${CIVITAI_TOKEN}"
|
| 250 |
+
else
|
| 251 |
+
echo "$url"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
fi
|
|
|
|
|
|
|
|
|
|
| 253 |
}
|
| 254 |
|
| 255 |
+
# Download HuggingFace usando hf com hf_transfer
|
| 256 |
+
download_hf() {
|
| 257 |
+
local repo="$1"
|
| 258 |
+
local file_path="$2"
|
| 259 |
+
local target_dir="$3"
|
| 260 |
+
local filename="$4"
|
| 261 |
+
|
| 262 |
+
if [ -z "$filename" ]; then
|
| 263 |
+
filename=$(basename "$file_path")
|
|
|
|
|
|
|
|
|
|
| 264 |
fi
|
| 265 |
+
|
| 266 |
+
local target_file="$target_dir/$filename"
|
| 267 |
+
|
| 268 |
+
if [ -f "$target_file" ] && [ $(stat -c%s "$target_file" 2>/dev/null || echo 0) -gt 1000000 ]; then
|
| 269 |
+
log_success "Arquivo já existe: $filename"
|
| 270 |
+
return 0
|
| 271 |
+
fi
|
| 272 |
+
|
| 273 |
+
log_info "Baixando de HF: $filename"
|
| 274 |
+
|
| 275 |
+
local temp_dir=$(mktemp -d)
|
| 276 |
+
local download_success=false
|
| 277 |
+
|
| 278 |
+
if command_exists hf; then
|
| 279 |
+
if HF_HUB_ENABLE_HF_TRANSFER=1 hf download "$repo" "$file_path" \
|
| 280 |
+
--local-dir "$temp_dir" \
|
| 281 |
+
--local-dir-use-symlinks False 2>/dev/null; then
|
| 282 |
+
download_success=true
|
| 283 |
+
fi
|
| 284 |
+
fi
|
| 285 |
+
|
| 286 |
+
if [ "$download_success" = false ] && command_exists huggingface-cli; then
|
| 287 |
+
log_warn "Tentando com huggingface-cli..."
|
| 288 |
+
if HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download "$repo" "$file_path" \
|
| 289 |
+
--local-dir "$temp_dir" \
|
| 290 |
+
--local-dir-use-symlinks False 2>/dev/null; then
|
| 291 |
+
download_success=true
|
| 292 |
+
fi
|
| 293 |
+
fi
|
| 294 |
+
|
| 295 |
+
if [ "$download_success" = true ]; then
|
| 296 |
+
local downloaded_file=$(find "$temp_dir" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.bin" -o -name "*.onnx" \) 2>/dev/null | head -1)
|
| 297 |
+
|
| 298 |
+
if [ -n "$downloaded_file" ]; then
|
| 299 |
+
mv "$downloaded_file" "$target_file"
|
| 300 |
+
rm -rf "$temp_dir"
|
| 301 |
+
log_success "Download concluído: $filename"
|
| 302 |
+
return 0
|
| 303 |
+
fi
|
| 304 |
+
fi
|
| 305 |
+
|
| 306 |
+
rm -rf "$temp_dir"
|
| 307 |
+
log_error "Falha ao baixar: $filename"
|
| 308 |
+
return 1
|
| 309 |
}
|
| 310 |
|
| 311 |
+
# Download genérico com aria2c, wget ou curl
|
| 312 |
+
download_file() {
|
| 313 |
+
local url="$1"
|
| 314 |
+
local target_dir="$2"
|
| 315 |
+
local filename="$3"
|
| 316 |
+
|
| 317 |
+
url=$(add_civitai_token "$url")
|
| 318 |
+
|
| 319 |
+
if [ -n "$filename" ] && [ -f "$target_dir/$filename" ] && [ $(stat -c%s "$target_dir/$filename" 2>/dev/null || echo 0) -gt 1000000 ]; then
|
| 320 |
+
log_success "Arquivo já existe: $filename"
|
| 321 |
+
return 0
|
| 322 |
+
fi
|
| 323 |
+
|
| 324 |
+
log_info "Baixando: ${filename:-$(basename "$url" | cut -d'?' -f1)}"
|
| 325 |
+
|
| 326 |
+
if command_exists aria2c; then
|
| 327 |
+
local aria_opts="-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10"
|
| 328 |
+
if [ -n "$filename" ]; then
|
| 329 |
+
aria2c $aria_opts --dir="$target_dir" --out="$filename" "$url" && return 0
|
| 330 |
+
else
|
| 331 |
+
aria2c $aria_opts --dir="$target_dir" "$url" && return 0
|
| 332 |
+
fi
|
| 333 |
+
fi
|
| 334 |
+
|
| 335 |
+
if command_exists wget; then
|
| 336 |
+
if [ -n "$filename" ]; then
|
| 337 |
+
wget -q --show-progress -c -O "$target_dir/$filename" "$url" && return 0
|
| 338 |
+
else
|
| 339 |
+
wget -q --show-progress -c --content-disposition -P "$target_dir" "$url" && return 0
|
| 340 |
+
fi
|
| 341 |
+
fi
|
| 342 |
+
|
| 343 |
+
if command_exists curl; then
|
| 344 |
+
if [ -n "$filename" ]; then
|
| 345 |
+
curl -L -# -C - -o "$target_dir/$filename" "$url" && return 0
|
| 346 |
+
else
|
| 347 |
+
local headers=$(curl -sI -L "$url")
|
| 348 |
+
local detected_name=$(echo "$headers" | grep -i "content-disposition" | sed -n 's/.*filename="\([^"]*\)".*/\1/p' | tr -d '\r')
|
| 349 |
+
if [ -z "$detected_name" ]; then
|
| 350 |
+
detected_name="downloaded_$(date +%s).safetensors"
|
| 351 |
+
fi
|
| 352 |
+
curl -L -# -C - -o "$target_dir/$detected_name" "$url" && return 0
|
| 353 |
+
fi
|
| 354 |
+
fi
|
| 355 |
+
|
| 356 |
+
log_error "Falha ao baixar: $url"
|
| 357 |
+
return 1
|
| 358 |
}
|
| 359 |
|
| 360 |
+
# Processar lista de downloads
|
| 361 |
+
process_downloads() {
|
| 362 |
+
local total=${#DOWNLOAD_FILES[@]}
|
| 363 |
+
local current=0
|
| 364 |
+
local failed_count=0
|
| 365 |
+
|
| 366 |
+
log_info "Total de downloads: $total"
|
| 367 |
+
|
| 368 |
+
for entry in "${DOWNLOAD_FILES[@]}"; do
|
| 369 |
+
((current++))
|
| 370 |
+
|
| 371 |
+
# Verificar se já foi baixado
|
| 372 |
+
if is_download_complete "$entry"; then
|
| 373 |
+
log_success "[$current/$total] Já baixado, pulando..."
|
| 374 |
+
continue
|
| 375 |
+
fi
|
| 376 |
+
|
| 377 |
+
IFS='|' read -r url type filename <<< "$entry"
|
| 378 |
+
|
| 379 |
+
# Limpar espaços
|
| 380 |
+
url=$(echo "$url" | xargs)
|
| 381 |
+
type=$(echo "$type" | xargs)
|
| 382 |
+
filename=$(echo "$filename" | xargs)
|
| 383 |
+
|
| 384 |
+
# Determinar diretório de destino
|
| 385 |
+
local target_dir="$MODELS_DIR"
|
| 386 |
+
case "$type" in
|
| 387 |
+
checkpoints) target_dir="$MODELS_DIR/checkpoints" ;;
|
| 388 |
+
diffusion_models) target_dir="$MODELS_DIR/diffusion_models" ;;
|
| 389 |
+
loras) target_dir="$MODELS_DIR/loras" ;;
|
| 390 |
+
vae) target_dir="$MODELS_DIR/vae" ;;
|
| 391 |
+
vae_approx) target_dir="$MODELS_DIR/vae_approx" ;;
|
| 392 |
+
text_encoders) target_dir="$MODELS_DIR/text_encoders" ;;
|
| 393 |
+
clip_vision) target_dir="$MODELS_DIR/clip_vision" ;;
|
| 394 |
+
upscale_models) target_dir="$MODELS_DIR/upscale_models" ;;
|
| 395 |
+
ultralytics/bbox) target_dir="$MODELS_DIR/ultralytics/bbox" ;;
|
| 396 |
+
*) target_dir="$MODELS_DIR/$type" ;;
|
| 397 |
+
esac
|
| 398 |
+
|
| 399 |
+
mkdir -p "$target_dir"
|
| 400 |
+
|
| 401 |
+
# Executar download apropriado
|
| 402 |
+
local download_result=1
|
| 403 |
+
|
| 404 |
+
if [[ "$url" == mega://* ]]; then
|
| 405 |
+
log_info "[$current/$total] Download do Mega..."
|
| 406 |
+
download_mega "$url" "$target_dir" "$filename" && download_result=0
|
| 407 |
+
elif [[ "$url" == hf://* ]]; then
|
| 408 |
+
log_info "[$current/$total] Download HuggingFace..."
|
| 409 |
+
url="${url#hf://}"
|
| 410 |
+
local repo=$(echo "$url" | cut -d'/' -f1-2)
|
| 411 |
+
local file_path=$(echo "$url" | cut -d'/' -f3-)
|
| 412 |
+
download_hf "$repo" "$file_path" "$target_dir" "$filename" && download_result=0
|
| 413 |
+
else
|
| 414 |
+
log_info "[$current/$total] Download HTTP..."
|
| 415 |
+
download_file "$url" "$target_dir" "$filename" && download_result=0
|
| 416 |
+
fi
|
| 417 |
+
|
| 418 |
+
if [ $download_result -eq 0 ]; then
|
| 419 |
+
mark_download_complete "$entry"
|
| 420 |
+
else
|
| 421 |
+
((failed_count++))
|
| 422 |
+
log_warn "Falhou, continuando..."
|
| 423 |
+
fi
|
| 424 |
+
done
|
| 425 |
+
|
| 426 |
+
if [ $failed_count -gt 0 ]; then
|
| 427 |
+
log_warn "Downloads completos: $((total - failed_count))/$total (${failed_count} falharam)"
|
| 428 |
else
|
| 429 |
+
log_success "Todos os $total downloads completados!"
|
| 430 |
fi
|
| 431 |
+
|
| 432 |
+
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
}
|
| 434 |
|
| 435 |
+
# Clonar ou atualizar repositório git
|
| 436 |
+
clone_or_update() {
|
| 437 |
+
local url="$1"
|
| 438 |
+
local dest="$2"
|
| 439 |
+
local node_name=$(basename "$dest")
|
| 440 |
+
|
| 441 |
+
if is_node_complete "$url"; then
|
| 442 |
+
log_success "Node já instalado: $node_name"
|
| 443 |
+
return 0
|
| 444 |
+
fi
|
| 445 |
+
|
| 446 |
+
if [ -d "$dest/.git" ]; then
|
| 447 |
+
log_info "Atualizando $node_name..."
|
| 448 |
+
timeout 60 git -C "$dest" pull --ff-only 2>/dev/null || {
|
| 449 |
+
log_warn "Timeout ou erro ao atualizar $node_name"
|
| 450 |
+
return 0
|
| 451 |
+
}
|
| 452 |
+
else
|
| 453 |
+
log_info "Clonando $node_name..."
|
| 454 |
+
timeout 60 git clone --recursive --depth 1 "$url" "$dest" 2>/dev/null || {
|
| 455 |
+
log_warn "Falha ao clonar $node_name"
|
| 456 |
+
return 0
|
| 457 |
+
}
|
| 458 |
+
fi
|
| 459 |
+
|
| 460 |
+
if [ -f "$dest/requirements.txt" ]; then
|
| 461 |
+
timeout 120 python3 -m pip install --no-warn-script-location -q -r "$dest/requirements.txt" 2>/dev/null || {
|
| 462 |
+
log_warn "Falha ao instalar requirements para $node_name"
|
| 463 |
+
}
|
| 464 |
+
fi
|
| 465 |
+
|
| 466 |
+
mark_node_complete "$url"
|
| 467 |
+
return 0
|
| 468 |
}
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
+
# -----------------------------
|
| 472 |
+
# Menu de opções
|
| 473 |
+
# -----------------------------
|
| 474 |
+
show_menu() {
|
| 475 |
+
echo ""
|
| 476 |
+
log_info "========================================="
|
| 477 |
+
log_info " ComfyUI Custom Setup v2.0"
|
| 478 |
+
log_info "========================================="
|
| 479 |
+
echo ""
|
| 480 |
+
|
| 481 |
+
local current_state=$(get_state)
|
| 482 |
+
|
| 483 |
+
# Verificar se o estado está vazio ou inválido
|
| 484 |
+
if [ -z "$current_state" ] || ! [[ "$current_state" =~ ^[0-9]+$ ]]; then
|
| 485 |
+
log_info "Iniciando nova instalação..."
|
| 486 |
+
reset_state
|
| 487 |
+
return 0
|
| 488 |
+
fi
|
| 489 |
+
|
| 490 |
+
# Se não for interativo, sempre continuar ou começar do zero
|
| 491 |
+
if [ "$INTERACTIVE" = false ]; then
|
| 492 |
+
if [ "$current_state" != "0" ] && [ "$current_state" -lt "8" ]; then
|
| 493 |
+
log_info "Modo não-interativo: continuando instalação anterior (Step: $current_state)"
|
| 494 |
+
else
|
| 495 |
+
log_info "Modo não-interativo: iniciando nova instalação"
|
| 496 |
+
fi
|
| 497 |
+
return 0
|
| 498 |
+
fi
|
| 499 |
+
|
| 500 |
+
if [ "$current_state" != "0" ] && [ "$current_state" -lt "8" ]; then
|
| 501 |
+
log_warn "Instalação anterior detectada (Step: $current_state)"
|
| 502 |
+
echo ""
|
| 503 |
+
echo "Opções:"
|
| 504 |
+
echo " 1) Continuar instalação de onde parou"
|
| 505 |
+
echo " 2) Reiniciar instalação do zero"
|
| 506 |
+
echo " 3) Sair"
|
| 507 |
+
echo ""
|
| 508 |
+
|
| 509 |
+
# Timeout de 10 segundos, padrão é continuar
|
| 510 |
+
read -t 10 -p "Escolha uma opção [1-3] (padrão: 1 em 10s): " choice || choice="1"
|
| 511 |
+
|
| 512 |
+
case $choice in
|
| 513 |
+
1|"") return 0 ;;
|
| 514 |
+
2) reset_state; return 0 ;;
|
| 515 |
+
3) exit 0 ;;
|
| 516 |
+
*) log_warn "Opção inválida, continuando..."; return 0 ;;
|
| 517 |
+
esac
|
| 518 |
+
fi
|
| 519 |
+
|
| 520 |
+
return 0
|
| 521 |
}
|
| 522 |
|
| 523 |
+
# -----------------------------
|
| 524 |
+
# Instalação principal
|
| 525 |
+
# -----------------------------
|
| 526 |
+
main() {
|
| 527 |
+
# Inicializar sistema de estado
|
| 528 |
+
init_state
|
| 529 |
+
|
| 530 |
+
# Mostrar menu
|
| 531 |
+
show_menu
|
| 532 |
+
|
| 533 |
+
local current_state=$(get_state)
|
| 534 |
+
|
| 535 |
+
# [STEP 1] Verificar e instalar dependências
|
| 536 |
+
if [ "$current_state" -lt "1" ]; then
|
| 537 |
+
log_info "[1/6] Verificando e instalando dependências..."
|
| 538 |
+
|
| 539 |
+
# Instalar aria2c e megatools
|
| 540 |
+
if ! command_exists aria2c; then
|
| 541 |
+
log_info "Instalando aria2c..."
|
| 542 |
+
apt-get update -qq && apt-get install -y -qq aria2 2>/dev/null
|
| 543 |
+
fi
|
| 544 |
+
|
| 545 |
+
install_megatools
|
| 546 |
+
|
| 547 |
+
for cmd in python3 git wget curl; do
|
| 548 |
+
if ! command_exists "$cmd"; then
|
| 549 |
+
log_error "Dependência faltando: $cmd"
|
| 550 |
+
exit 1
|
| 551 |
+
fi
|
| 552 |
+
done
|
| 553 |
+
|
| 554 |
+
log_success "Dependências OK"
|
| 555 |
+
save_state "1"
|
| 556 |
+
fi
|
| 557 |
+
|
| 558 |
+
# [STEP 2] Atualizar pip e instalar ferramentas
|
| 559 |
+
if [ "$current_state" -lt "2" ]; then
|
| 560 |
+
log_info "[2/6] Preparando ferramentas Python..."
|
| 561 |
+
python3 -m pip install --upgrade pip wheel setuptools -q
|
| 562 |
+
python3 -m pip install --upgrade "huggingface_hub[cli,hf_transfer]>=0.26.0" comfy-cli -q
|
| 563 |
+
|
| 564 |
+
if [ -n "$HF_TOKEN" ]; then
|
| 565 |
+
huggingface-cli login --token "$HF_TOKEN" 2>/dev/null || log_warn "Login HF falhou"
|
| 566 |
+
fi
|
| 567 |
+
|
| 568 |
+
log_success "Ferramentas instaladas"
|
| 569 |
+
save_state "2"
|
| 570 |
+
fi
|
| 571 |
+
|
| 572 |
+
# [STEP 3] Instalar ComfyUI
|
| 573 |
+
if [ "$current_state" -lt "3" ]; then
|
| 574 |
+
log_info "[3/6] Instalando ComfyUI..."
|
| 575 |
+
if [ -f "$COMFY_DIR/main.py" ]; then
|
| 576 |
+
log_warn "ComfyUI já existe"
|
| 577 |
+
else
|
| 578 |
+
comfy --skip-prompt install --fast-deps --nvidia
|
| 579 |
+
|
| 580 |
+
if [ ! -f "$COMFY_DIR/main.py" ]; then
|
| 581 |
+
log_error "ComfyUI não foi instalado!"
|
| 582 |
+
exit 1
|
| 583 |
+
fi
|
| 584 |
+
fi
|
| 585 |
+
log_success "ComfyUI instalado"
|
| 586 |
+
save_state "3"
|
| 587 |
+
fi
|
| 588 |
+
|
| 589 |
+
# [STEP 4] Corrigir PyTorch para Blackwell se detectado
|
| 590 |
+
if [ "$current_state" -lt "4" ]; then
|
| 591 |
+
log_info "[4/6] Verificando GPU..."
|
| 592 |
+
|
| 593 |
+
# Detectar GPU
|
| 594 |
+
local gpu_info=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo "")
|
| 595 |
+
|
| 596 |
+
if [[ "$gpu_info" == *"5090"* ]] || [[ "$gpu_info" == *"5080"* ]]; then
|
| 597 |
+
log_warn "RTX ${gpu_info} detectada - corrigindo PyTorch"
|
| 598 |
+
# Instalar torch, torchvision e torchaudio JUNTOS em um comando só
|
| 599 |
+
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
|
| 600 |
+
log_success "PyTorch nightly instalado"
|
| 601 |
+
else
|
| 602 |
+
log_info "GPU: ${gpu_info:-Não detectada} - mantendo PyTorch do ComfyUI"
|
| 603 |
+
fi
|
| 604 |
+
save_state "4"
|
| 605 |
+
fi
|
| 606 |
+
|
| 607 |
+
# [STEP 5] Baixar modelos
|
| 608 |
+
# [STEP 5] Baixar modelos
|
| 609 |
+
if [ "$current_state" -lt "5" ]; then
|
| 610 |
+
log_info "[5/6] Baixando modelos..."
|
| 611 |
+
mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,vae_approx,text_encoders,clip_vision,upscale_models,checkpoints,ultralytics/bbox}
|
| 612 |
+
|
| 613 |
+
process_downloads
|
| 614 |
+
log_success "Downloads processados"
|
| 615 |
+
save_state "5"
|
| 616 |
+
fi
|
| 617 |
+
|
| 618 |
+
# [STEP 6] Instalar custom nodes
|
| 619 |
+
if [ "$current_state" -lt "6" ]; then
|
| 620 |
+
log_info "[6/6] Instalando custom nodes..."
|
| 621 |
+
CN_DIR="$COMFY_DIR/custom_nodes"
|
| 622 |
+
mkdir -p "$CN_DIR"
|
| 623 |
+
|
| 624 |
+
for repo_url in "${CUSTOM_NODES[@]}"; do
|
| 625 |
+
node_name=$(basename "$repo_url")
|
| 626 |
+
clone_or_update "$repo_url" "$CN_DIR/$node_name"
|
| 627 |
+
done
|
| 628 |
+
|
| 629 |
+
for node_name in "${SPECIAL_NODES[@]}"; do
|
| 630 |
+
if ! is_node_complete "special:$node_name"; then
|
| 631 |
+
log_info "Instalando $node_name via comfy-cli..."
|
| 632 |
+
comfy node install "$node_name" 2>/dev/null && mark_node_complete "special:$node_name" || log_warn "Falha: $node_name"
|
| 633 |
+
fi
|
| 634 |
+
done
|
| 635 |
+
|
| 636 |
+
log_success "Custom nodes instalados"
|
| 637 |
+
save_state "6"
|
| 638 |
+
fi
|
| 639 |
+
|
| 640 |
+
# Verificação final
|
| 641 |
+
log_info "Verificando instalação..."
|
| 642 |
+
|
| 643 |
+
echo ""
|
| 644 |
+
log_info "Estatísticas da instalação:"
|
| 645 |
+
|
| 646 |
+
# Verificar ComfyUI
|
| 647 |
+
if [ -f "$COMFY_DIR/main.py" ]; then
|
| 648 |
+
log_success "✓ ComfyUI instalado"
|
| 649 |
+
else
|
| 650 |
+
log_error "✗ ComfyUI não encontrado"
|
| 651 |
+
fi
|
| 652 |
+
|
| 653 |
+
# Contar modelos
|
| 654 |
+
echo ""
|
| 655 |
+
log_info "Modelos instalados:"
|
| 656 |
+
for dir in checkpoints loras vae vae_approx text_encoders clip_vision upscale_models ultralytics; do
|
| 657 |
+
if [ -d "$MODELS_DIR/$dir" ]; then
|
| 658 |
+
local count=$(find "$MODELS_DIR/$dir" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.ckpt" -o -name "*.onnx" \) 2>/dev/null | wc -l)
|
| 659 |
+
if [ $count -gt 0 ]; then
|
| 660 |
+
log_success " $dir: $count arquivo(s)"
|
| 661 |
+
fi
|
| 662 |
+
fi
|
| 663 |
+
done
|
| 664 |
+
|
| 665 |
+
# Contar nodes
|
| 666 |
+
echo ""
|
| 667 |
+
local node_count=$(find "$CN_DIR" -maxdepth 1 -type d 2>/dev/null | wc -l)
|
| 668 |
+
log_success "Custom nodes: $((node_count - 1)) instalados"
|
| 669 |
+
|
| 670 |
+
# Verificar GPU
|
| 671 |
+
echo ""
|
| 672 |
+
local gpu_info=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo "Não detectada")
|
| 673 |
+
log_info "GPU: $gpu_info"
|
| 674 |
+
|
| 675 |
+
# Marcar instalação como completa
|
| 676 |
+
save_state "6"
|
| 677 |
+
|
| 678 |
+
echo ""
|
| 679 |
+
log_success "========================================="
|
| 680 |
+
log_success " Instalação concluída!"
|
| 681 |
+
log_success "========================================="
|
| 682 |
+
|
| 683 |
+
# Se não for interativo ou se for via argumento, iniciar direto
|
| 684 |
+
if [ "$INTERACTIVE" = false ] || [ "${1:-}" = "--start" ]; then
|
| 685 |
+
log_info "Iniciando ComfyUI automaticamente..."
|
| 686 |
+
log_info "URL: http://localhost:$COMFY_PORT"
|
| 687 |
+
cd "$COMFY_DIR"
|
| 688 |
+
exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
|
| 689 |
+
fi
|
| 690 |
+
|
| 691 |
+
echo ""
|
| 692 |
echo "Opções:"
|
| 693 |
echo " 1) Iniciar ComfyUI agora"
|
| 694 |
+
echo " 2) Resetar estado da instalação"
|
| 695 |
+
echo " 3) Sair"
|
| 696 |
+
echo ""
|
| 697 |
+
|
| 698 |
+
# Timeout de 10 segundos, padrão é iniciar
|
| 699 |
+
read -t 10 -p "Escolha uma opção [1-3] (padrão: 1 em 10s): " final_choice || final_choice="1"
|
| 700 |
+
|
| 701 |
+
case $final_choice in
|
| 702 |
+
1|"")
|
| 703 |
+
log_info "Iniciando ComfyUI..."
|
| 704 |
+
log_info "URL: http://localhost:$COMFY_PORT"
|
| 705 |
+
cd "$COMFY_DIR"
|
| 706 |
+
exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
|
| 707 |
+
;;
|
| 708 |
+
2)
|
| 709 |
+
reset_state
|
| 710 |
+
log_success "Estado resetado. Execute o script novamente para reinstalar."
|
| 711 |
+
;;
|
| 712 |
+
3)
|
| 713 |
+
log_info "Saindo..."
|
| 714 |
+
;;
|
| 715 |
+
*)
|
| 716 |
+
log_info "Iniciando ComfyUI (opção padrão)..."
|
| 717 |
+
cd "$COMFY_DIR"
|
| 718 |
+
exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
|
| 719 |
+
;;
|
| 720 |
esac
|
|
|
|
| 721 |
}
|
| 722 |
|
| 723 |
+
# Executar instalação
|
| 724 |
+
main "$@"
|