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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # ComfyUI Automated Setup Script
4
+ # Supports LightningAI, RunPod, VastAI, and generic Linux environments
5
+ # Author: Generated for automated ComfyUI deployment
6
+ # Modified based on user request.
7
+
8
+ set -e
9
+ set -o pipefail
10
+
11
+ # ============================================================================
12
+ # GLOBAL CONFIGURATIONS
13
+ # ============================================================================
14
+
15
+ # Civitai API Token
16
+ readonly CIVITAI_TOKEN="0b698de03658fb8df2eeef90bad3ab9a"
17
+
18
+ # Custom Nodes to Install (from Git)
19
+ readonly CUSTOM_NODES=(
20
+ "https://github.com/adbrasi/cezarsave34"
21
+ "https://github.com/adbrasi/pageonetor"
22
+ "https://github.com/adbrasi/pakreatorio"
23
+ "https://github.com/Cezarsaint/custom_prompt_manager"
24
+ )
25
+
26
+ # Files to Download - Format: "URL|target_subdir|filename"
27
+ # If filename is empty, let aria2c/wget determine from Content-Disposition
28
+ readonly DOWNLOAD_FILES=(
29
+ "https://civitai.com/api/download/models/1761560?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|"
30
+ "https://civitai.com/api/download/models/1268294?type=Model&format=SafeTensor|loras|"
31
+ "https://civitai.com/api/download/models/1715330?type=Model&format=SafeTensor|loras|"
32
+ "https://civitai.com/api/download/models/1499397?type=Model&format=SafeTensor|loras|" # NOVO LORA ADICIONADO
33
+ "https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth"
34
+ "https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt"
35
+ )
36
+
37
+ # Model directories to create
38
+ readonly MODEL_DIRS=(
39
+ "checkpoints"
40
+ "loras"
41
+ "upscale_models"
42
+ "ultralytics/bbox"
43
+ )
44
+
45
+ # Workflow configuration
46
+ readonly WORKFLOW_URL="https://huggingface.co/adbrasi/testedownload/resolve/main/packreator_setup.json"
47
+
48
+ # Global variables
49
+ BASE_DIR=""
50
+ COMFY_INSTALL_DIR=""
51
+ MODELS_DIR=""
52
+ WORKFLOW_FILE=""
53
+ SUDO_PREFIX=""
54
+ ARIA2C_AVAILABLE=false
55
+ ENV_NAME=""
56
+
57
+ # ============================================================================
58
+ # UTILITY FUNCTIONS
59
+ # ============================================================================
60
+
61
+ log_info() {
62
+ echo "INFO: $1" >&2
63
+ }
64
+
65
+ log_warning() {
66
+ echo "WARNING: $1" >&2
67
+ }
68
+
69
+ log_error() {
70
+ echo "ERROR: $1" >&2
71
+ }
72
+
73
+ command_exists() {
74
+ command -v "$1" >/dev/null 2>&1
75
+ }
76
+
77
+ is_root() {
78
+ [ "$(id -u)" -eq 0 ]
79
+ }
80
+
81
+ # ============================================================================
82
+ # ENVIRONMENT DETECTION
83
+ # ============================================================================
84
+
85
+ detect_environment() {
86
+ log_info "Detecting environment..."
87
+
88
+ if [ -d "/teamspace/studios/this_studio" ]; then
89
+ BASE_DIR="/teamspace/studios/this_studio"
90
+ ENV_NAME="lightning"
91
+ elif [ -d "/workspace" ] && [ ! -d "/teamspace/studios/this_studio" ]; then
92
+ BASE_DIR="/workspace"
93
+ ENV_NAME="runpod"
94
+ elif is_root && [ ! -d "/teamspace/studios/this_studio" ] && [ ! -d "/workspace" ]; then
95
+ BASE_DIR="/root"
96
+ ENV_NAME="vastai"
97
+ else
98
+ BASE_DIR="$HOME"
99
+ ENV_NAME="generic"
100
+ fi
101
+
102
+ COMFY_INSTALL_DIR="${BASE_DIR}/my_comfy_setup"
103
+ MODELS_DIR="${COMFY_INSTALL_DIR}/models"
104
+ WORKFLOW_FILE="${COMFY_INSTALL_DIR}/workflow.json"
105
+
106
+ log_info "Environment detected: $ENV_NAME"
107
+ log_info "Base directory: $BASE_DIR"
108
+ log_info "ComfyUI install directory: $COMFY_INSTALL_DIR"
109
+ log_info "Models directory: $MODELS_DIR"
110
+ }
111
+
112
+ # ============================================================================
113
+ # PERMISSION MANAGEMENT
114
+ # ============================================================================
115
+
116
+ setup_permissions() {
117
+ log_info "Setting up permissions..."
118
+
119
+ if is_root; then
120
+ SUDO_PREFIX=""
121
+ log_info "Running as root, no sudo needed"
122
+ elif command_exists sudo; then
123
+ SUDO_PREFIX="sudo "
124
+ log_info "Non-root user with sudo available"
125
+ else
126
+ SUDO_PREFIX=""
127
+ log_warning "Non-root user without sudo, some system operations may fail"
128
+ fi
129
+ }
130
+
131
+ # ============================================================================
132
+ # SYSTEM DEPENDENCIES
133
+ # ============================================================================
134
+
135
+ install_system_dependencies() {
136
+ log_info "Installing system dependencies..."
137
+
138
+ # Update package list
139
+ if command_exists apt-get; then
140
+ ${SUDO_PREFIX}apt-get update -qq || log_warning "Failed to update package list"
141
+
142
+ # Install basic dependencies
143
+ ${SUDO_PREFIX}apt-get install -y -qq python3 python3-pip git || {
144
+ log_error "Failed to install basic dependencies (python3, pip, git)"
145
+ exit 1
146
+ }
147
+
148
+ # Try to install aria2c
149
+ if ${SUDO_PREFIX}apt-get install -y -qq aria2 >/dev/null 2>&1; then
150
+ ARIA2C_AVAILABLE=true
151
+ log_info "aria2c installed successfully"
152
+ else
153
+ ARIA2C_AVAILABLE=false
154
+ log_info "aria2c installation failed, will use wget/curl as fallback"
155
+ fi
156
+ else
157
+ log_warning "apt-get not available, skipping system package installation"
158
+ # Check if aria2c is already available
159
+ if command_exists aria2c; then
160
+ ARIA2C_AVAILABLE=true
161
+ log_info "aria2c already available"
162
+ fi
163
+ fi
164
+ }
165
+
166
+ # ============================================================================
167
+ # COMFY-CLI INSTALLATION
168
+ # ============================================================================
169
+
170
+ install_comfy_cli() {
171
+ log_info "Installing comfy-cli..."
172
+
173
+ python3 -m pip install --upgrade comfy-cli || {
174
+ log_error "Failed to install comfy-cli"
175
+ exit 1
176
+ }
177
+
178
+ # Check if comfy is in PATH
179
+ if ! command_exists comfy; then
180
+ if [ -d "$HOME/.local/bin" ]; then
181
+ export PATH="$HOME/.local/bin:$PATH"
182
+ log_info "Added $HOME/.local/bin to PATH"
183
+ fi
184
+
185
+ if ! command_exists comfy; then
186
+ log_error "comfy command not found in PATH after installation"
187
+ exit 1
188
+ fi
189
+ fi
190
+
191
+ log_info "comfy-cli version: $(comfy --version 2>/dev/null || echo 'unknown')"
192
+ }
193
+
194
+ # ============================================================================
195
+ # COMFYUI CORE INSTALLATION
196
+ # ============================================================================
197
+
198
+ install_comfyui_core() {
199
+ log_info "Installing ComfyUI core..."
200
+
201
+ # MODIFICADO: Adicionado --fast-deps
202
+ comfy --workspace "$COMFY_INSTALL_DIR" --skip-prompt install --nvidia --fast-deps || {
203
+ log_error "Failed to install ComfyUI core"
204
+ exit 1
205
+ }
206
+
207
+ log_info "ComfyUI core installed successfully"
208
+ }
209
+
210
+ # ============================================================================
211
+ # DIRECTORY STRUCTURE
212
+ # ============================================================================
213
+
214
+ create_model_directories() {
215
+ log_info "Creating model directories..."
216
+
217
+ # Create model directories
218
+ for dir in "${MODEL_DIRS[@]}"; do
219
+ mkdir -p "$MODELS_DIR/$dir"
220
+ log_info "Created directory: $MODELS_DIR/$dir"
221
+ done
222
+
223
+ mkdir -p "$COMFY_INSTALL_DIR"
224
+ }
225
+
226
+ # ============================================================================
227
+ # CUSTOM NODES INSTALLATION
228
+ # ============================================================================
229
+
230
+ install_custom_nodes() {
231
+ log_info "Installing custom nodes..."
232
+
233
+ # MODIFICADO: Adicionado instalação via registro
234
+ log_info "Installing custom node from registry: civicomfy"
235
+ comfy --workspace "$COMFY_INSTALL_DIR" node registry-install civicomfy || {
236
+ log_warning "Failed to install custom node from registry: civicomfy"
237
+ }
238
+
239
+ # MODIFICADO: Nova lista de nós a partir do Git
240
+ for node_url in "${CUSTOM_NODES[@]}"; do
241
+ log_info "Installing custom node from Git: $node_url"
242
+ comfy --workspace "$COMFY_INSTALL_DIR" node install "$node_url" || {
243
+ log_warning "Failed to install custom node: $node_url"
244
+ }
245
+ done
246
+ }
247
+
248
+ # ============================================================================
249
+ # DOWNLOAD FUNCTIONS
250
+ # ============================================================================
251
+
252
+ add_civitai_token() {
253
+ local url="$1"
254
+ if [[ "$url" == *"civitai.com/api/download"* ]] && [[ "$url" != *"token="* ]]; then
255
+ echo "${url}&token=${CIVITAI_TOKEN}"
256
+ else
257
+ echo "$url"
258
+ fi
259
+ }
260
+
261
+ download_file() {
262
+ local url="$1"
263
+ local target_dir="$2"
264
+ local filename="$3"
265
+
266
+ url=$(add_civitai_token "$url")
267
+
268
+ local download_cmd=""
269
+ local success=false
270
+
271
+ if $ARIA2C_AVAILABLE && command_exists aria2c; then
272
+ local aria_opts="-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=0"
273
+ if [ -n "$filename" ]; then
274
+ download_cmd="aria2c $aria_opts --dir=\"$target_dir\" --out=\"$filename\" \"$url\""
275
+ else
276
+ download_cmd="aria2c $aria_opts --dir=\"$target_dir\" --content-disposition=true \"$url\""
277
+ fi
278
+ if eval "$download_cmd" >/dev/null 2>&1; then success=true; fi
279
+ fi
280
+
281
+ if ! $success && command_exists wget; then
282
+ local wget_opts="-q --show-progress -c"
283
+ if [ -n "$filename" ]; then
284
+ download_cmd="wget $wget_opts -O \"$target_dir/$filename\" \"$url\""
285
+ else
286
+ download_cmd="wget $wget_opts --content-disposition -P \"$target_dir\" \"$url\""
287
+ fi
288
+ if eval "$download_cmd"; then success=true; fi
289
+ fi
290
+
291
+ if ! $success && command_exists curl; then
292
+ log_warning "Using curl fallback for $url"
293
+ if [ -n "$filename" ]; {
294
+ download_cmd="curl -L -C - -o \"$target_dir/$filename\" \"$url\"";
295
+ } else {
296
+ if curl --help 2>/dev/null | grep -q "output-dir"; then
297
+ download_cmd="curl -L -J -O --output-dir \"$target_dir\" \"$url\"";
298
+ else
299
+ local fallback_name; fallback_name=$(basename "$url" | cut -d'?' -f1); [ -z "$fallback_name" ] && fallback_name="downloaded_file"
300
+ download_cmd="curl -L -C - -o \"$target_dir/$fallback_name\" \"$url\"";
301
+ fi;
302
+ }
303
+ if eval "$download_cmd"; then success=true; fi
304
+ fi
305
+
306
+ if ! $success; then
307
+ log_error "Failed to download: $url"
308
+ return 1
309
+ fi
310
+ return 0
311
+ }
312
+
313
+ # ============================================================================
314
+ # PARALLEL DOWNLOADS
315
+ # ============================================================================
316
+
317
+ download_all_files() {
318
+ log_info "Starting parallel downloads..."
319
+ local pids=()
320
+ local download_logs=()
321
+
322
+ for file_spec in "${DOWNLOAD_FILES[@]}"; do
323
+ IFS='|' read -r url target_subdir filename <<< "$file_spec"
324
+
325
+ local target_dir="$MODELS_DIR/$target_subdir"
326
+ local display_name="${filename:-$(basename "$url" | cut -d'?' -f1)}"
327
+ log_info "Starting download: $display_name -> $target_dir"
328
+
329
+ local log_file; log_file=$(mktemp)
330
+ download_logs+=("$log_file")
331
+
332
+ (
333
+ if download_file "$url" "$target_dir" "$filename" >"$log_file" 2>&1; then
334
+ echo "SUCCESS: Downloaded $display_name" >> "$log_file"
335
+ else
336
+ echo "FAILED: Failed to download $display_name" >> "$log_file"; exit 1
337
+ fi
338
+ ) &
339
+ pids+=($!)
340
+ done
341
+
342
+ local failed_count=0
343
+ for i in "${!pids[@]}"; do
344
+ if wait "${pids[$i]}"; then
345
+ log_info "Download completed successfully"
346
+ else
347
+ failed_count=$((failed_count + 1)); log_warning "Download failed - check logs"
348
+ fi
349
+ if [ -f "${download_logs[$i]}" ]; then
350
+ cat "${download_logs[$i]}" >&2; rm -f "${download_logs[$i]}"
351
+ fi
352
+ done
353
+
354
+ if [ $failed_count -gt 0 ]; then
355
+ log_warning "$failed_count downloads failed, but continuing..."
356
+ else
357
+ log_info "All downloads completed successfully"
358
+ fi
359
+ }
360
+
361
+ # ============================================================================
362
+ # WORKFLOW DOWNLOAD (NOVA FUNÇÃO)
363
+ # ============================================================================
364
+
365
+ download_workflow() {
366
+ log_info "Baixando o workflow de: $WORKFLOW_URL"
367
+ log_info "Salvando como: $WORKFLOW_FILE"
368
+
369
+ local success=false
370
+
371
+ # Tenta diferentes métodos de download
372
+ if command_exists wget; then
373
+ if wget -q --show-progress -O "$WORKFLOW_FILE" "$WORKFLOW_URL"; then
374
+ success=true
375
+ fi
376
+ elif command_exists curl; then
377
+ if curl -L -o "$WORKFLOW_FILE" "$WORKFLOW_URL"; then
378
+ success=true
379
+ fi
380
+ elif command_exists aria2c; then
381
+ # aria2c precisa do nome do arquivo e diretório separados
382
+ if aria2c -q -o "$(basename "$WORKFLOW_FILE")" -d "$(dirname "$WORKFLOW_FILE")" "$WORKFLOW_URL"; then
383
+ success=true
384
+ fi
385
+ else
386
+ log_error "Nenhuma ferramenta de download disponível (wget, curl ou aria2c)."
387
+ exit 1
388
+ fi
389
+
390
+ if ! $success; then
391
+ log_error "Falha ao baixar o arquivo do workflow."
392
+ exit 1
393
+ fi
394
+
395
+ if [ ! -f "$WORKFLOW_FILE" ]; then
396
+ log_error "O arquivo do workflow não foi baixado com sucesso."
397
+ exit 1
398
+ fi
399
+
400
+ log_info "Workflow baixado com sucesso."
401
+ }
402
+
403
+ # ============================================================================
404
+ # DEPENDÊNCIAS DO WORKFLOW (NOVA FUNÇÃO)
405
+ # ============================================================================
406
+
407
+ install_workflow_dependencies() {
408
+ log_info "Instalando dependências do workflow a partir de: $WORKFLOW_FILE"
409
+
410
+ if [ ! -f "$WORKFLOW_FILE" ]; then
411
+ log_error "Arquivo de workflow não encontrado: $WORKFLOW_FILE"
412
+ return 1
413
+ fi
414
+
415
+ # Usa o workspace correto para instalar as dependências
416
+ comfy --workspace "$COMFY_INSTALL_DIR" node install-deps --workflow="$WORKFLOW_FILE" || {
417
+ log_warning "Algumas dependências do workflow podem ter falhado ao instalar."
418
+ log_info "Isso pode ser normal. O ComfyUI mostrará os nós ausentes ao iniciar."
419
+ }
420
+
421
+ log_info "Instalação de dependências do workflow concluída."
422
+ }
423
+
424
+
425
+ # ============================================================================
426
+ # COMFYUI LAUNCH
427
+ # ============================================================================
428
+
429
+ launch_comfyui() {
430
+ log_info "Launching ComfyUI on port 8818..."
431
+ log_info "ComfyUI will be accessible at: http://0.0.0.0:8818"
432
+
433
+ # Launch ComfyUI
434
+ exec comfy --workspace "$COMFY_INSTALL_DIR" launch -- --fast --listen 0.0.0.0 --port 8818
435
+ }
436
+
437
+ # ============================================================================
438
+ # MAIN EXECUTION
439
+ # ============================================================================
440
+
441
+ main() {
442
+ log_info "Starting ComfyUI automated setup..."
443
+ log_info "========================================"
444
+
445
+ # Step 1: Environment Detection
446
+ detect_environment
447
+
448
+ # Step 2: Permission Setup
449
+ setup_permissions
450
+
451
+ # Step 3: System Dependencies
452
+ install_system_dependencies
453
+
454
+ # Step 4: Install comfy-cli
455
+ install_comfy_cli
456
+
457
+ # Step 5: Install ComfyUI Core
458
+ install_comfyui_core
459
+
460
+ # Step 6: Create Directory Structure
461
+ create_model_directories
462
+
463
+ # Step 7: Install Custom Nodes
464
+ install_custom_nodes
465
+
466
+ # Step 8: Download Files in Parallel
467
+ download_all_files
468
+
469
+ # Step 9: Download Workflow
470
+ download_workflow
471
+
472
+ # Step 10: Install Workflow Dependencies
473
+ install_workflow_dependencies
474
+
475
+ # Step 11: Launch ComfyUI
476
+ log_info "========================================"
477
+ log_info "Setup completed successfully!"
478
+ log_info "========================================"
479
+ launch_comfyui
480
+ }
481
+
482
+ # ============================================================================
483
+ # SCRIPT EXECUTION
484
+ # ============================================================================
485
+
486
+ # Trap to handle script interruption
487
+ trap 'log_error "Script interrupted"; exit 1' INT TERM
488
+
489
+ # Run main function
490
+ main "$@"