adbrasi commited on
Commit
bcf26ad
·
verified ·
1 Parent(s): 5a58b97

Update image_Studio.sh

Browse files
Files changed (1) hide show
  1. image_Studio.sh +411 -200
image_Studio.sh CHANGED
@@ -1,6 +1,6 @@
1
  #!/usr/bin/env bash
2
- # setup_comfyui_custom.sh
3
- # Script modificado para instalação do ComfyUI com custom nodes e modelos personalizados
4
 
5
  set -euo pipefail
6
 
@@ -11,12 +11,14 @@ RED='\033[0;31m'
11
  GREEN='\033[0;32m'
12
  YELLOW='\033[1;33m'
13
  BLUE='\033[0;34m'
 
14
  NC='\033[0m'
15
 
16
  log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
17
  log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
18
  log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
19
  log_error() { echo -e "${RED}[✗]${NC} $1"; }
 
20
 
21
  # -----------------------------
22
  # Configuração
@@ -26,7 +28,13 @@ MODELS_DIR="$COMFY_DIR/models"
26
  COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
27
  COMFY_PORT="${COMFY_PORT:-8818}"
28
  CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
29
- HF_TOKEN="${HF_TOKEN:-}" # Token opcional do HuggingFace para login
 
 
 
 
 
 
30
 
31
  # Configurações de performance
32
  export MAX_JOBS=32
@@ -38,14 +46,58 @@ export HF_TRANSFER_CONCURRENCY=16
38
  export EXT_PARALLEL=4
39
 
40
  # -----------------------------
41
- # Lista de downloads
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  # -----------------------------
43
- # Formato: "URL|TIPO|NOME_ARQUIVO_OPCIONAL"
44
  readonly DOWNLOAD_FILES=(
45
- # Checkpoints from Civitai
46
- "https://civitai.com/api/download/models/1761560?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|"
47
- "https://civitai.com/api/download/models/1410435?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|"
48
- "https://civitai.com/api/download/models/1522463?type=Model&format=SafeTensor&size=full&fp=fp16|checkpoints|"
49
  "https://civitai.com/api/download/models/2122278?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|raehoshiIllustXL_v60.safetensors"
50
 
51
  # LoRAs from Civitai
@@ -56,19 +108,22 @@ readonly DOWNLOAD_FILES=(
56
  "https://civitai.com/api/download/models/1114313?type=Model&format=SafeTensor|loras|"
57
  "https://civitai.com/api/download/models/1780244?type=Model&format=SafeTensor|loras|"
58
 
59
- # Upscale models
 
 
 
60
  "https://huggingface.co/Kim2091/AnimeSharp/resolve/main/4x-AnimeSharp.pth|upscale_models|4x-AnimeSharp.pth"
61
  "https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth"
62
  "https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth"
 
 
 
63
 
64
  # Ultralytics model
65
  "https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt"
66
-
67
- # ControlNet
68
- "hf://xinsir/controlnet-union-sdxl-1.0/diffusion_pytorch_model_promax.safetensors|controlnet|controlnet-union.safetensors"
69
  )
70
 
71
- # Custom nodes para instalar
72
  readonly CUSTOM_NODES=(
73
  "https://github.com/adbrasi/huggpackreator"
74
  "https://github.com/adbrasi/packreator_processor"
@@ -82,6 +137,10 @@ readonly CUSTOM_NODES=(
82
  "https://github.com/adbrasi/groqrouter"
83
  "https://github.com/adbrasi/find_charakito"
84
  "https://github.com/adbrasi/randomsizito"
 
 
 
 
85
  "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
86
  "https://github.com/sipherxyz/comfyui-art-venture"
87
  "https://github.com/pamparamm/sd-perturbed-attention"
@@ -101,8 +160,6 @@ readonly CUSTOM_NODES=(
101
  "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
102
  "https://github.com/Cezarsaint/rand0micoUploaderLoven"
103
  "https://github.com/adbrasi/pixivmosaic"
104
- "https://github.com/adbrasi/storitadifusita"
105
- "https://github.com/adbrasi/attentionPPM"
106
  "https://github.com/adbrasi/futfilter"
107
  "https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit"
108
  "https://github.com/shiimizu/ComfyUI_smZNodes"
@@ -122,6 +179,73 @@ command_exists() {
122
  command -v "$1" >/dev/null 2>&1
123
  }
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  # Adicionar token do Civitai se necessário
126
  add_civitai_token() {
127
  local url="$1"
@@ -139,27 +263,20 @@ download_hf() {
139
  local target_dir="$3"
140
  local filename="$4"
141
 
142
- # Se filename não foi fornecido, extrair do caminho
143
  if [ -z "$filename" ]; then
144
  filename=$(basename "$file_path")
145
  fi
146
 
147
  local target_file="$target_dir/$filename"
148
 
149
- # Se arquivo já existe e tem tamanho razoável, pular
150
  if [ -f "$target_file" ] && [ $(stat -c%s "$target_file" 2>/dev/null || echo 0) -gt 1000000 ]; then
151
  log_success "Arquivo já existe: $filename"
152
  return 0
153
  fi
154
 
155
  log_info "Baixando de HF: $filename"
156
- log_info " Repo: $repo"
157
- log_info " Path: $file_path"
158
 
159
- # Criar diretório temporário para download
160
  local temp_dir=$(mktemp -d)
161
-
162
- # Tentar primeiro com 'hf download' (novo comando)
163
  local download_success=false
164
 
165
  if command_exists hf; then
@@ -170,7 +287,6 @@ download_hf() {
170
  fi
171
  fi
172
 
173
- # Se 'hf' não funcionou, tentar com huggingface-cli
174
  if [ "$download_success" = false ] && command_exists huggingface-cli; then
175
  log_warn "Tentando com huggingface-cli..."
176
  if HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download "$repo" "$file_path" \
@@ -181,17 +297,13 @@ download_hf() {
181
  fi
182
 
183
  if [ "$download_success" = true ]; then
184
- # Procurar o arquivo baixado (pode estar em subdiretórios)
185
- local downloaded_file=$(find "$temp_dir" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.bin" \) 2>/dev/null | head -1)
186
 
187
  if [ -n "$downloaded_file" ]; then
188
- # Mover para o destino correto com o nome correto
189
  mv "$downloaded_file" "$target_file"
190
  rm -rf "$temp_dir"
191
  log_success "Download concluído: $filename"
192
  return 0
193
- else
194
- log_error "Arquivo baixado mas não encontrado em $temp_dir"
195
  fi
196
  fi
197
 
@@ -206,10 +318,8 @@ download_file() {
206
  local target_dir="$2"
207
  local filename="$3"
208
 
209
- # Adicionar token Civitai se necessário
210
  url=$(add_civitai_token "$url")
211
 
212
- # Se arquivo já existe e tem tamanho razoável, pular
213
  if [ -n "$filename" ] && [ -f "$target_dir/$filename" ] && [ $(stat -c%s "$target_dir/$filename" 2>/dev/null || echo 0) -gt 1000000 ]; then
214
  log_success "Arquivo já existe: $filename"
215
  return 0
@@ -217,7 +327,6 @@ download_file() {
217
 
218
  log_info "Baixando: ${filename:-$(basename "$url" | cut -d'?' -f1)}"
219
 
220
- # Tentar com aria2c primeiro (mais rápido)
221
  if command_exists aria2c; then
222
  local aria_opts="-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10"
223
  if [ -n "$filename" ]; then
@@ -227,7 +336,6 @@ download_file() {
227
  fi
228
  fi
229
 
230
- # Fallback para wget
231
  if command_exists wget; then
232
  if [ -n "$filename" ]; then
233
  wget -q --show-progress -c -O "$target_dir/$filename" "$url" && return 0
@@ -236,7 +344,6 @@ download_file() {
236
  fi
237
  fi
238
 
239
- # Último recurso: curl
240
  if command_exists curl; then
241
  if [ -n "$filename" ]; then
242
  curl -L -# -C - -o "$target_dir/$filename" "$url" && return 0
@@ -254,19 +361,32 @@ download_file() {
254
  return 1
255
  }
256
 
257
- # Processar lista de downloads
258
  process_downloads() {
 
 
259
  local failed_count=0
 
 
 
260
 
261
  for entry in "${DOWNLOAD_FILES[@]}"; do
 
 
 
 
 
 
 
 
 
 
262
  IFS='|' read -r url type filename <<< "$entry"
263
 
264
- # Limpar espaços
265
  url=$(echo "$url" | xargs)
266
  type=$(echo "$type" | xargs)
267
  filename=$(echo "$filename" | xargs)
268
 
269
- # Determinar diretório de destino
270
  local target_dir="$MODELS_DIR"
271
  case "$type" in
272
  checkpoints) target_dir="$MODELS_DIR/checkpoints" ;;
@@ -276,32 +396,40 @@ process_downloads() {
276
  vae_approx) target_dir="$MODELS_DIR/vae_approx" ;;
277
  text_encoders) target_dir="$MODELS_DIR/text_encoders" ;;
278
  clip_vision) target_dir="$MODELS_DIR/clip_vision" ;;
279
- controlnet) target_dir="$MODELS_DIR/controlnet" ;;
280
  upscale_models) target_dir="$MODELS_DIR/upscale_models" ;;
281
  ultralytics/bbox) target_dir="$MODELS_DIR/ultralytics/bbox" ;;
282
  *) target_dir="$MODELS_DIR/$type" ;;
283
  esac
284
 
285
- # Criar diretório se não existir
286
  mkdir -p "$target_dir"
287
 
288
- # Processar URL
289
- if [[ "$url" == hf://* ]]; then
 
 
 
 
 
290
  # HuggingFace download
291
- url="${url#hf://}" # Remove prefixo hf://
292
-
293
- # Separar repo e caminho do arquivo
294
  local repo=$(echo "$url" | cut -d'/' -f1-2)
295
  local file_path=$(echo "$url" | cut -d'/' -f3-)
296
-
297
- download_hf "$repo" "$file_path" "$target_dir" "$filename" || ((failed_count++))
298
  else
299
- # Download normal (HTTP/HTTPS)
300
- download_file "$url" "$target_dir" "$filename" || ((failed_count++))
 
 
 
 
 
 
 
301
  fi
302
  done
303
 
304
- return $failed_count
 
305
  }
306
 
307
  # Clonar ou atualizar repositório git
@@ -310,197 +438,280 @@ clone_or_update() {
310
  local dest="$2"
311
  local node_name=$(basename "$dest")
312
 
313
- # Timeout de 60 segundos para operações git
 
 
 
 
314
  if [ -d "$dest/.git" ]; then
315
  log_info "Atualizando $node_name..."
316
  timeout 60 git -C "$dest" pull --ff-only 2>/dev/null || {
317
  log_warn "Timeout ou erro ao atualizar $node_name"
318
- return 0 # Não falhar, apenas avisar
319
  }
320
  else
321
  log_info "Clonando $node_name..."
322
  timeout 60 git clone --recursive --depth 1 "$url" "$dest" 2>/dev/null || {
323
  log_warn "Falha ao clonar $node_name"
324
- return 0 # Não falhar, apenas avisar
325
  }
326
  fi
327
 
328
- # Instalar requirements se existir (com timeout)
329
  if [ -f "$dest/requirements.txt" ]; then
330
  timeout 120 python3 -m pip install --no-warn-script-location -q -r "$dest/requirements.txt" 2>/dev/null || {
331
  log_warn "Falha ao instalar requirements para $node_name"
332
  }
333
  fi
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  return 0
336
  }
337
 
338
  # -----------------------------
339
  # Instalação principal
340
  # -----------------------------
341
- echo ""
342
- log_info "========================================="
343
- log_info " ComfyUI Custom Setup"
344
- log_info "========================================="
345
- echo ""
346
-
347
- # [1] Verificar e instalar dependências
348
- log_info "[1/7] Verificando e instalando dependências..."
349
-
350
- # Instalar aria2c do sistema se não existir
351
- if ! command_exists aria2c; then
352
- log_info "Instalando aria2c do sistema..."
353
- apt-get update -qq && apt-get install -y -qq aria2 2>/dev/null
354
- fi
355
-
356
- for cmd in python3 git wget curl; do
357
- if ! command_exists "$cmd"; then
358
- log_error "Dependência faltando: $cmd"
359
- exit 1
 
 
 
 
 
 
 
 
 
 
 
360
  fi
361
- done
362
- log_success "Dependências OK"
363
-
364
- # [2] Atualizar pip e instalar ferramentas
365
- log_info "[2/7] Preparando ferramentas Python..."
366
- python3 -m pip install --upgrade pip wheel setuptools -q
367
-
368
- # Instalar huggingface_hub com CLI e hf_transfer para velocidade máxima
369
- python3 -m pip install --upgrade "huggingface_hub[cli,hf_transfer]>=0.26.0" comfy-cli -q
370
-
371
- # Configurar token HF se disponível (opcional)
372
- HF_TOKEN="${HF_TOKEN:-}"
373
- if [ -n "$HF_TOKEN" ]; then
374
- if huggingface-cli login --token "$HF_TOKEN" 2>/dev/null; then
375
- log_success "Login HF configurado"
376
- else
377
- log_warn "Falha ao configurar login HF, continuando sem autenticação"
378
  fi
379
- fi
380
-
381
- # Verificar comandos disponíveis
382
- if command_exists hf; then
383
- log_success "Comando 'hf' disponível (recomendado)"
384
- elif command_exists huggingface-cli; then
385
- log_warn "Usando 'huggingface-cli' (deprecated, mas funcional)"
386
- else
387
- log_error "Nenhum comando HF disponível!"
388
- fi
389
-
390
- log_success "Ferramentas instaladas"
391
-
392
- # [3] Instalar PyTorch com CUDA 12.8
393
- log_info "[3/7] Instalando PyTorch com CUDA 12.8..."
394
- python3 -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
395
- log_success "PyTorch com CUDA 12.8 instalado"
396
-
397
- # [4] Instalar ComfyUI
398
- log_info "[4/7] Instalando ComfyUI..."
399
- if [ -f "$COMFY_DIR/main.py" ]; then
400
- log_warn "ComfyUI já existe, pulando instalação base"
401
- else
402
- comfy --skip-prompt install --fast-deps --nvidia
403
-
404
- # Verificar instalação
405
- if [ ! -f "$COMFY_DIR/main.py" ]; then
406
- log_error "ComfyUI não foi instalado corretamente!"
407
- exit 1
408
  fi
409
- fi
410
- log_success "ComfyUI instalado em: $COMFY_DIR"
411
-
412
- # [5] Baixar modelos
413
- log_info "[5/7] Baixando modelos..."
414
- mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,vae_approx,text_encoders,clip_vision,controlnet,upscale_models,checkpoints,ultralytics/bbox}
415
-
416
- # Verificar ferramentas de download
417
- if command_exists aria2c; then
418
- log_success "Usando aria2c para downloads (rápido)"
419
- else
420
- log_warn "aria2c não encontrado, usando wget/curl (mais lento)"
421
- fi
422
-
423
- # Processar downloads
424
- if process_downloads; then
425
- log_success "Todos os modelos baixados com sucesso"
426
- else
427
- log_warn "Alguns downloads falharam, mas continuando..."
428
- fi
429
-
430
- # [6] Instalar custom nodes
431
- log_info "[6/7] Instalando custom nodes..."
432
- CN_DIR="$COMFY_DIR/custom_nodes"
433
- mkdir -p "$CN_DIR"
434
-
435
- # Instalar nodes do GitHub
436
- for repo_url in "${CUSTOM_NODES[@]}"; do
437
- node_name=$(basename "$repo_url")
438
- clone_or_update "$repo_url" "$CN_DIR/$node_name"
439
- done
440
-
441
- # Instalar nodes especiais via comfy-cli
442
- for node_name in "${SPECIAL_NODES[@]}"; do
443
- log_info "Instalando $node_name via comfy-cli..."
444
- comfy node install "$node_name" 2>/dev/null || log_warn "Falha ao instalar $node_name"
445
- done
446
-
447
- log_success "Custom nodes instalados"
448
-
449
- # [7] Verificação final
450
- echo ""
451
- log_info "[7/7] Verificando instalação..."
452
-
453
- # Verificar arquivos principais
454
- check_critical_files() {
455
- local files=(
456
- "$COMFY_DIR/main.py"
457
- )
458
-
459
- local missing=0
460
- for file in "${files[@]}"; do
461
- if [ -f "$file" ]; then
462
- log_success "✓ $(basename "$file")"
463
  else
464
- log_error "✗ $(basename "$file") não encontrado"
465
- ((missing++))
 
 
 
 
466
  fi
467
- done
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
468
 
469
- # Listar modelos baixados
470
  echo ""
471
- log_info "Modelos disponíveis:"
472
- for dir in checkpoints loras vae vae_approx text_encoders clip_vision controlnet upscale_models ultralytics; do
473
  if [ -d "$MODELS_DIR/$dir" ]; then
474
- local count=$(find "$MODELS_DIR/$dir" -type f \( -name "*.safetensors" -o -name "*.pth" -o -name "*.pt" -o -name "*.ckpt" \) 2>/dev/null | wc -l)
475
  if [ $count -gt 0 ]; then
476
  log_success " $dir: $count arquivo(s)"
477
  fi
478
  fi
479
  done
480
 
481
- # Listar custom nodes instalados
482
  echo ""
483
- log_info "Custom nodes instalados:"
484
- local node_count=$(find "$CN_DIR" -maxdepth 1 -type d | wc -l)
485
- log_success " Total: $((node_count - 1)) nodes"
486
 
487
- return $missing
488
- }
489
-
490
- if check_critical_files; then
491
- log_success "Instalação concluída com sucesso!"
492
  echo ""
493
- log_info "========================================="
494
- log_info "Iniciando ComfyUI..."
495
- log_info "URL: http://localhost:$COMFY_PORT"
496
- log_info "========================================="
 
497
 
498
- cd "$COMFY_DIR"
499
- exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
500
- else
501
- log_error "Alguns arquivos críticos não foram encontrados!"
502
- log_info "Tentando iniciar ComfyUI mesmo assim..."
503
 
504
- cd "$COMFY_DIR"
505
- exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
506
- fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
 
11
  GREEN='\033[0;32m'
12
  YELLOW='\033[1;33m'
13
  BLUE='\033[0;34m'
14
+ CYAN='\033[0;36m'
15
  NC='\033[0m'
16
 
17
  log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
18
  log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
19
  log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
20
  log_error() { echo -e "${RED}[✗]${NC} $1"; }
21
+ log_progress() { echo -e "${CYAN}[→]${NC} $1"; }
22
 
23
  # -----------------------------
24
  # Configuração
 
28
  COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
29
  COMFY_PORT="${COMFY_PORT:-8818}"
30
  CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
31
+ HF_TOKEN="${HF_TOKEN:-}"
32
+
33
+ # Diretório para salvar estado
34
+ STATE_DIR="/root/.comfyui_setup_state"
35
+ STATE_FILE="$STATE_DIR/installation_state.txt"
36
+ COMPLETED_DOWNLOADS="$STATE_DIR/completed_downloads.txt"
37
+ COMPLETED_NODES="$STATE_DIR/completed_nodes.txt"
38
 
39
  # Configurações de performance
40
  export MAX_JOBS=32
 
46
  export EXT_PARALLEL=4
47
 
48
  # -----------------------------
49
+ # Sistema de Estado Persistente
50
+ # -----------------------------
51
+ init_state() {
52
+ mkdir -p "$STATE_DIR"
53
+ touch "$STATE_FILE" "$COMPLETED_DOWNLOADS" "$COMPLETED_NODES"
54
+ }
55
+
56
+ save_state() {
57
+ local step="$1"
58
+ echo "$step" > "$STATE_FILE"
59
+ log_info "Estado salvo: $step"
60
+ }
61
+
62
+ get_state() {
63
+ if [ -f "$STATE_FILE" ]; then
64
+ cat "$STATE_FILE"
65
+ else
66
+ echo "0"
67
+ fi
68
+ }
69
+
70
+ mark_download_complete() {
71
+ local url="$1"
72
+ echo "$url" >> "$COMPLETED_DOWNLOADS"
73
+ }
74
+
75
+ is_download_complete() {
76
+ local url="$1"
77
+ grep -Fxq "$url" "$COMPLETED_DOWNLOADS" 2>/dev/null
78
+ }
79
+
80
+ mark_node_complete() {
81
+ local node="$1"
82
+ echo "$node" >> "$COMPLETED_NODES"
83
+ }
84
+
85
+ is_node_complete() {
86
+ local node="$1"
87
+ grep -Fxq "$node" "$COMPLETED_NODES" 2>/dev/null
88
+ }
89
+
90
+ reset_state() {
91
+ log_warn "Resetando estado da instalação..."
92
+ rm -rf "$STATE_DIR"
93
+ init_state
94
+ }
95
+
96
+ # -----------------------------
97
+ # Lista de downloads (ATUALIZADA - sem ControlNet)
98
  # -----------------------------
 
99
  readonly DOWNLOAD_FILES=(
100
+ # Checkpoint mantido
 
 
 
101
  "https://civitai.com/api/download/models/2122278?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|raehoshiIllustXL_v60.safetensors"
102
 
103
  # LoRAs from Civitai
 
108
  "https://civitai.com/api/download/models/1114313?type=Model&format=SafeTensor|loras|"
109
  "https://civitai.com/api/download/models/1780244?type=Model&format=SafeTensor|loras|"
110
 
111
+ # LoRA from Mega (nome automático pelo megadl)
112
+ "mega://https://mega.nz/file/gIRTFQSQ#no6Ay3JLE9LVRi7ib9O-Jc0CW7XmG046kCgpCzDg1tY|loras|"
113
+
114
+ # Upscale models - Coleção completa
115
  "https://huggingface.co/Kim2091/AnimeSharp/resolve/main/4x-AnimeSharp.pth|upscale_models|4x-AnimeSharp.pth"
116
  "https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth"
117
  "https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth"
118
+ "https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2.pth|upscale_models|4x-UltraSharpV2.pth"
119
+ "https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_Lite.pth|upscale_models|4x-UltraSharpV2_Lite.pth"
120
+ "https://huggingface.co/Kim2091/UltraSharpV2/resolve/main/4x-UltraSharpV2_fp32_op17.onnx|upscale_models|4x-UltraSharpV2_fp32_op17.onnx"
121
 
122
  # Ultralytics model
123
  "https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt"
 
 
 
124
  )
125
 
126
+ # Custom nodes para instalar (ATUALIZADA com novos nodes)
127
  readonly CUSTOM_NODES=(
128
  "https://github.com/adbrasi/huggpackreator"
129
  "https://github.com/adbrasi/packreator_processor"
 
137
  "https://github.com/adbrasi/groqrouter"
138
  "https://github.com/adbrasi/find_charakito"
139
  "https://github.com/adbrasi/randomsizito"
140
+ "https://github.com/adbrasi/importex"
141
+ "https://github.com/adbrasi/storitadifusita"
142
+ "https://github.com/adbrasi/attentionPPM"
143
+ "https://github.com/ClownsharkBatwing/RES4LYF"
144
  "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
145
  "https://github.com/sipherxyz/comfyui-art-venture"
146
  "https://github.com/pamparamm/sd-perturbed-attention"
 
160
  "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
161
  "https://github.com/Cezarsaint/rand0micoUploaderLoven"
162
  "https://github.com/adbrasi/pixivmosaic"
 
 
163
  "https://github.com/adbrasi/futfilter"
164
  "https://github.com/Artificial-Sweetener/comfyui-WhiteRabbit"
165
  "https://github.com/shiimizu/ComfyUI_smZNodes"
 
179
  command -v "$1" >/dev/null 2>&1
180
  }
181
 
182
+ # Instalar megatools se necessário
183
+ install_megatools() {
184
+ if ! command_exists megadl; then
185
+ log_info "Instalando megatools para downloads do Mega..."
186
+ apt-get update -qq && apt-get install -y -qq megatools 2>/dev/null
187
+ if command_exists megadl; then
188
+ log_success "Megatools instalado com sucesso"
189
+ else
190
+ log_warn "Falha ao instalar megatools, downloads do Mega não estarão disponíveis"
191
+ fi
192
+ fi
193
+ }
194
+
195
+ # Download do Mega
196
+ download_mega() {
197
+ local url="$1"
198
+ local target_dir="$2"
199
+ local filename="$3"
200
+
201
+ if ! command_exists megadl; then
202
+ log_error "megatools não instalado, pulando download do Mega"
203
+ return 1
204
+ fi
205
+
206
+ # Limpar URL - remover prefixo mega:// se houver
207
+ url="${url#mega://}"
208
+
209
+ log_info "Baixando do Mega..."
210
+ log_info " URL: $url"
211
+ log_info " Destino: $target_dir"
212
+
213
+ # Criar diretório temporário para download
214
+ local temp_dir=$(mktemp -d)
215
+ cd "$temp_dir"
216
+
217
+ # Baixar com megadl (ele salva com o nome correto automaticamente)
218
+ if timeout 1800 megadl "$url" 2>/dev/null; then
219
+ # Encontrar o arquivo baixado
220
+ local downloaded_file=$(find . -type f -maxdepth 1 2>/dev/null | grep -v "^\.$" | head -1)
221
+
222
+ if [ -n "$downloaded_file" ]; then
223
+ local actual_filename=$(basename "$downloaded_file")
224
+
225
+ # Se foi especificado um nome E não está vazio, renomear
226
+ if [ -n "$filename" ] && [ "$filename" != "" ]; then
227
+ mv "$downloaded_file" "$target_dir/$filename"
228
+ log_success "Download concluído: $filename"
229
+ else
230
+ # Manter o nome original do Mega
231
+ mv "$downloaded_file" "$target_dir/$actual_filename"
232
+ log_success "Download concluído: $actual_filename"
233
+ fi
234
+ cd - >/dev/null
235
+ rm -rf "$temp_dir"
236
+ return 0
237
+ else
238
+ log_error "Arquivo baixado mas não encontrado no diretório temporário"
239
+ fi
240
+ else
241
+ log_error "Falha ao baixar do Mega (timeout ou erro)"
242
+ fi
243
+
244
+ cd - >/dev/null
245
+ rm -rf "$temp_dir"
246
+ return 1
247
+ }
248
+
249
  # Adicionar token do Civitai se necessário
250
  add_civitai_token() {
251
  local url="$1"
 
263
  local target_dir="$3"
264
  local filename="$4"
265
 
 
266
  if [ -z "$filename" ]; then
267
  filename=$(basename "$file_path")
268
  fi
269
 
270
  local target_file="$target_dir/$filename"
271
 
 
272
  if [ -f "$target_file" ] && [ $(stat -c%s "$target_file" 2>/dev/null || echo 0) -gt 1000000 ]; then
273
  log_success "Arquivo já existe: $filename"
274
  return 0
275
  fi
276
 
277
  log_info "Baixando de HF: $filename"
 
 
278
 
 
279
  local temp_dir=$(mktemp -d)
 
 
280
  local download_success=false
281
 
282
  if command_exists hf; then
 
287
  fi
288
  fi
289
 
 
290
  if [ "$download_success" = false ] && command_exists huggingface-cli; then
291
  log_warn "Tentando com huggingface-cli..."
292
  if HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download "$repo" "$file_path" \
 
297
  fi
298
 
299
  if [ "$download_success" = true ]; then
300
+ 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)
 
301
 
302
  if [ -n "$downloaded_file" ]; then
 
303
  mv "$downloaded_file" "$target_file"
304
  rm -rf "$temp_dir"
305
  log_success "Download concluído: $filename"
306
  return 0
 
 
307
  fi
308
  fi
309
 
 
318
  local target_dir="$2"
319
  local filename="$3"
320
 
 
321
  url=$(add_civitai_token "$url")
322
 
 
323
  if [ -n "$filename" ] && [ -f "$target_dir/$filename" ] && [ $(stat -c%s "$target_dir/$filename" 2>/dev/null || echo 0) -gt 1000000 ]; then
324
  log_success "Arquivo já existe: $filename"
325
  return 0
 
327
 
328
  log_info "Baixando: ${filename:-$(basename "$url" | cut -d'?' -f1)}"
329
 
 
330
  if command_exists aria2c; then
331
  local aria_opts="-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10"
332
  if [ -n "$filename" ]; then
 
336
  fi
337
  fi
338
 
 
339
  if command_exists wget; then
340
  if [ -n "$filename" ]; then
341
  wget -q --show-progress -c -O "$target_dir/$filename" "$url" && return 0
 
344
  fi
345
  fi
346
 
 
347
  if command_exists curl; then
348
  if [ -n "$filename" ]; then
349
  curl -L -# -C - -o "$target_dir/$filename" "$url" && return 0
 
361
  return 1
362
  }
363
 
364
+ # Processar lista de downloads (NÃO PARA EM FALHAS)
365
  process_downloads() {
366
+ local total=${#DOWNLOAD_FILES[@]}
367
+ local current=0
368
  local failed_count=0
369
+ local skipped_count=0
370
+
371
+ log_info "Total de downloads: $total"
372
 
373
  for entry in "${DOWNLOAD_FILES[@]}"; do
374
+ ((current++))
375
+ log_progress "[$current/$total] Processando download..."
376
+
377
+ # Verificar se já foi baixado
378
+ if is_download_complete "$entry"; then
379
+ log_success "Download já completado anteriormente, pulando..."
380
+ ((skipped_count++))
381
+ continue
382
+ fi
383
+
384
  IFS='|' read -r url type filename <<< "$entry"
385
 
 
386
  url=$(echo "$url" | xargs)
387
  type=$(echo "$type" | xargs)
388
  filename=$(echo "$filename" | xargs)
389
 
 
390
  local target_dir="$MODELS_DIR"
391
  case "$type" in
392
  checkpoints) target_dir="$MODELS_DIR/checkpoints" ;;
 
396
  vae_approx) target_dir="$MODELS_DIR/vae_approx" ;;
397
  text_encoders) target_dir="$MODELS_DIR/text_encoders" ;;
398
  clip_vision) target_dir="$MODELS_DIR/clip_vision" ;;
 
399
  upscale_models) target_dir="$MODELS_DIR/upscale_models" ;;
400
  ultralytics/bbox) target_dir="$MODELS_DIR/ultralytics/bbox" ;;
401
  *) target_dir="$MODELS_DIR/$type" ;;
402
  esac
403
 
 
404
  mkdir -p "$target_dir"
405
 
406
+ # Determinar tipo de download e executar
407
+ local download_result=1
408
+
409
+ if [[ "$url" == mega://* ]]; then
410
+ # Download do Mega
411
+ download_mega "$url" "$target_dir" "$filename" && download_result=0
412
+ elif [[ "$url" == hf://* ]]; then
413
  # HuggingFace download
414
+ url="${url#hf://}"
 
 
415
  local repo=$(echo "$url" | cut -d'/' -f1-2)
416
  local file_path=$(echo "$url" | cut -d'/' -f3-)
417
+ download_hf "$repo" "$file_path" "$target_dir" "$filename" && download_result=0
 
418
  else
419
+ # Download normal
420
+ download_file "$url" "$target_dir" "$filename" && download_result=0
421
+ fi
422
+
423
+ if [ $download_result -eq 0 ]; then
424
+ mark_download_complete "$entry"
425
+ else
426
+ ((failed_count++))
427
+ log_warn "Download falhou, mas continuando com o próximo..."
428
  fi
429
  done
430
 
431
+ log_info "Downloads completados: $((total - failed_count - skipped_count)) novos, $skipped_count já existentes, $failed_count falharam"
432
+ return 0 # Sempre retorna sucesso para não parar o script
433
  }
434
 
435
  # Clonar ou atualizar repositório git
 
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
+ # Detectar GPU e ajustar PyTorch se necessário
471
+ detect_and_fix_gpu() {
472
+ log_info "Detectando GPU..."
473
+
474
+ # Verificar se é uma GPU Blackwell (RTX 5090, etc)
475
+ local gpu_info=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo "")
476
+
477
+ if [[ "$gpu_info" == *"5090"* ]] || [[ "$gpu_info" == *"5080"* ]] || [[ "$gpu_info" == *"Blackwell"* ]]; then
478
+ log_warn "GPU Blackwell detectada (${gpu_info})"
479
+ log_info "Instalando PyTorch nightly para suporte completo..."
480
+
481
+ # Instalar PyTorch nightly para Blackwell
482
+ python3 -m pip install --pre --upgrade --no-cache-dir torch --extra-index-url https://download.pytorch.org/whl/nightly/cu128
483
+ python3 -m pip install --pre --upgrade --no-cache-dir torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cu128
484
+ python3 -m pip install --pre --upgrade --no-cache-dir torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu128
485
+
486
+ log_success "PyTorch nightly instalado para Blackwell"
487
+ else
488
+ log_info "GPU padrão detectada: ${gpu_info:-Não detectada}"
489
+ log_info "Usando PyTorch stable"
490
+ fi
491
+ }
492
+
493
+ # -----------------------------
494
+ # Menu de opções
495
+ # -----------------------------
496
+ show_menu() {
497
+ echo ""
498
+ log_info "========================================="
499
+ log_info " ComfyUI Custom Setup v2.0"
500
+ log_info "========================================="
501
+ echo ""
502
+
503
+ local current_state=$(get_state)
504
+
505
+ if [ "$current_state" != "0" ]; then
506
+ log_warn "Instalação anterior detectada (Step: $current_state)"
507
+ echo ""
508
+ echo "Opções:"
509
+ echo " 1) Continuar instalação de onde parou"
510
+ echo " 2) Reiniciar instalação do zero"
511
+ echo " 3) Sair"
512
+ echo ""
513
+ read -p "Escolha uma opção [1-3]: " choice
514
+
515
+ case $choice in
516
+ 1) return 0 ;;
517
+ 2) reset_state; return 0 ;;
518
+ 3) exit 0 ;;
519
+ *) echo "Opção inválida"; exit 1 ;;
520
+ esac
521
+ fi
522
+
523
  return 0
524
  }
525
 
526
  # -----------------------------
527
  # Instalação principal
528
  # -----------------------------
529
+ main() {
530
+ # Inicializar sistema de estado
531
+ init_state
532
+
533
+ # Mostrar menu
534
+ show_menu
535
+
536
+ local current_state=$(get_state)
537
+
538
+ # [STEP 1] Verificar e instalar dependências
539
+ if [ "$current_state" -lt "1" ]; then
540
+ log_info "[1/8] Verificando e instalando dependências..."
541
+
542
+ # Instalar aria2c e megatools
543
+ if ! command_exists aria2c; then
544
+ log_info "Instalando aria2c..."
545
+ apt-get update -qq && apt-get install -y -qq aria2 2>/dev/null
546
+ fi
547
+
548
+ install_megatools
549
+
550
+ for cmd in python3 git wget curl; do
551
+ if ! command_exists "$cmd"; then
552
+ log_error "Dependência faltando: $cmd"
553
+ exit 1
554
+ fi
555
+ done
556
+
557
+ log_success "Dependências OK"
558
+ save_state "1"
559
  fi
560
+
561
+ # [STEP 2] Atualizar pip e instalar ferramentas
562
+ if [ "$current_state" -lt "2" ]; then
563
+ log_info "[2/8] Preparando ferramentas Python..."
564
+ python3 -m pip install --upgrade pip wheel setuptools -q
565
+ python3 -m pip install --upgrade "huggingface_hub[cli,hf_transfer]>=0.26.0" comfy-cli -q
566
+
567
+ if [ -n "$HF_TOKEN" ]; then
568
+ huggingface-cli login --token "$HF_TOKEN" 2>/dev/null || log_warn "Login HF falhou"
569
+ fi
570
+
571
+ log_success "Ferramentas instaladas"
572
+ save_state "2"
 
 
 
 
573
  fi
574
+
575
+ # [STEP 3] Instalar PyTorch inicial
576
+ if [ "$current_state" -lt "3" ]; then
577
+ log_info "[3/8] Instalando PyTorch com CUDA 12.8..."
578
+ python3 -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
579
+ log_success "PyTorch instalado"
580
+ save_state "3"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  fi
582
+
583
+ # [STEP 4] Instalar ComfyUI
584
+ if [ "$current_state" -lt "4" ]; then
585
+ log_info "[4/8] Instalando ComfyUI..."
586
+ if [ -f "$COMFY_DIR/main.py" ]; then
587
+ log_warn "ComfyUI já existe"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  else
589
+ comfy --skip-prompt install --fast-deps --nvidia
590
+
591
+ if [ ! -f "$COMFY_DIR/main.py" ]; then
592
+ log_error "ComfyUI não foi instalado corretamente!"
593
+ exit 1
594
+ fi
595
  fi
596
+ log_success "ComfyUI instalado"
597
+ save_state "4"
598
+ fi
599
+
600
+ # [STEP 5] Detectar e corrigir para GPU Blackwell se necessário
601
+ if [ "$current_state" -lt "5" ]; then
602
+ log_info "[5/8] Verificando compatibilidade de GPU..."
603
+ detect_and_fix_gpu
604
+ save_state "5"
605
+ fi
606
+
607
+ # [STEP 6] Baixar modelos
608
+ if [ "$current_state" -lt "6" ]; then
609
+ log_info "[6/8] Baixando modelos..."
610
+ mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,vae_approx,text_encoders,clip_vision,upscale_models,checkpoints,ultralytics/bbox}
611
+
612
+ process_downloads # Não falha mesmo se alguns downloads falharem
613
+
614
+ log_success "Processo de download concluído"
615
+ save_state "6"
616
+ fi
617
+
618
+ # [STEP 7] Instalar custom nodes
619
+ if [ "$current_state" -lt "7" ]; then
620
+ log_info "[7/8] Instalando custom nodes..."
621
+ CN_DIR="$COMFY_DIR/custom_nodes"
622
+ mkdir -p "$CN_DIR"
623
+
624
+ local total_nodes=${#CUSTOM_NODES[@]}
625
+ local current_node=0
626
+
627
+ for repo_url in "${CUSTOM_NODES[@]}"; do
628
+ ((current_node++))
629
+ node_name=$(basename "$repo_url")
630
+ log_progress "[$current_node/$total_nodes] Instalando: $node_name"
631
+ clone_or_update "$repo_url" "$CN_DIR/$node_name"
632
+ done
633
+
634
+ for node_name in "${SPECIAL_NODES[@]}"; do
635
+ if ! is_node_complete "special:$node_name"; then
636
+ log_info "Instalando $node_name via comfy-cli..."
637
+ comfy node install "$node_name" 2>/dev/null && mark_node_complete "special:$node_name" || log_warn "Falha: $node_name"
638
+ fi
639
+ done
640
+
641
+ log_success "Custom nodes instalados"
642
+ save_state "7"
643
+ fi
644
+
645
+ # [STEP 8] Verificação final
646
+ log_info "[8/8] Verificando instalação..."
647
+
648
+ echo ""
649
+ log_info "Estatísticas da instalação:"
650
+
651
+ # Verificar ComfyUI
652
+ if [ -f "$COMFY_DIR/main.py" ]; then
653
+ log_success "✓ ComfyUI instalado"
654
+ else
655
+ log_error "✗ ComfyUI não encontrado"
656
+ fi
657
 
658
+ # Contar modelos
659
  echo ""
660
+ log_info "Modelos instalados:"
661
+ for dir in checkpoints loras vae vae_approx text_encoders clip_vision upscale_models ultralytics; do
662
  if [ -d "$MODELS_DIR/$dir" ]; then
663
+ 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)
664
  if [ $count -gt 0 ]; then
665
  log_success " $dir: $count arquivo(s)"
666
  fi
667
  fi
668
  done
669
 
670
+ # Contar nodes
671
  echo ""
672
+ local node_count=$(find "$CN_DIR" -maxdepth 1 -type d 2>/dev/null | wc -l)
673
+ log_success "Custom nodes: $((node_count - 1)) instalados"
 
674
 
675
+ # Verificar GPU
 
 
 
 
676
  echo ""
677
+ local gpu_info=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo "Não detectada")
678
+ log_info "GPU: $gpu_info"
679
+
680
+ # Marcar instalação como completa
681
+ save_state "8"
682
 
683
+ echo ""
684
+ log_success "========================================="
685
+ log_success " Instalação concluída!"
686
+ log_success "========================================="
 
687
 
688
+ echo ""
689
+ echo "Opções:"
690
+ echo " 1) Iniciar ComfyUI agora"
691
+ echo " 2) Resetar estado da instalação"
692
+ echo " 3) Sair"
693
+ echo ""
694
+ read -p "Escolha uma opção [1-3]: " final_choice
695
+
696
+ case $final_choice in
697
+ 1)
698
+ log_info "Iniciando ComfyUI..."
699
+ log_info "URL: http://localhost:$COMFY_PORT"
700
+ cd "$COMFY_DIR"
701
+ exec comfy launch -- --listen "$COMFY_HOST" --port "$COMFY_PORT"
702
+ ;;
703
+ 2)
704
+ reset_state
705
+ log_success "Estado resetado. Execute o script novamente para reinstalar."
706
+ ;;
707
+ 3)
708
+ log_info "Saindo..."
709
+ ;;
710
+ *)
711
+ log_warn "Opção inválida"
712
+ ;;
713
+ esac
714
+ }
715
+
716
+ # Executar instalação
717
+ main "$@"