adbrasi commited on
Commit
457f286
·
verified ·
1 Parent(s): d5483f6

Upload PackreatorComfyUi2.sh

Browse files
Files changed (1) hide show
  1. PackreatorComfyUi2.sh +332 -0
PackreatorComfyUi2.sh ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, handled by comfy-cli)
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
+ readonly DOWNLOAD_FILES=(
28
+ "https://civitai.com/api/download/models/1761560?type=Model&format=SafeTensor&size=pruned&fp=fp16|checkpoints|"
29
+ "https://civitai.com/api/download/models/1268294?type=Model&format=SafeTensor|loras|"
30
+ "https://civitai.com/api/download/models/1715330?type=Model&format=SafeTensor|loras|"
31
+ "https://civitai.com/api/download/models/1499397?type=Model&format=SafeTensor|loras|"
32
+ "https://huggingface.co/Kim2091/AnimeSharpV3/resolve/main/2x-AnimeSharpV3.pth|upscale_models|2x-AnimeSharpV3.pth"
33
+ "https://huggingface.co/adbrasi/testedownload/resolve/main/99coins_anime_girl_face_m_seg.pt|ultralytics/bbox|99coins_anime_girl_face_m_seg.pt"
34
+ )
35
+
36
+ # Model directories to create
37
+ readonly MODEL_DIRS=(
38
+ "checkpoints"
39
+ "loras"
40
+ "upscale_models"
41
+ "ultralytics/bbox"
42
+ )
43
+
44
+ # Workflow configuration
45
+ readonly WORKFLOW_URL="https://huggingface.co/adbrasi/testedownload/resolve/main/packreator_setup.json"
46
+
47
+ # Global variables
48
+ BASE_DIR=""
49
+ COMFY_INSTALL_DIR=""
50
+ MODELS_DIR=""
51
+ WORKFLOW_FILE=""
52
+ SUDO_PREFIX=""
53
+ ARIA2C_AVAILABLE=false
54
+ ENV_NAME=""
55
+
56
+ # ============================================================================
57
+ # UTILITY FUNCTIONS
58
+ # ============================================================================
59
+
60
+ log_info() {
61
+ echo "INFO: $1" >&2
62
+ }
63
+
64
+ log_warning() {
65
+ echo "WARNING: $1" >&2
66
+ }
67
+
68
+ log_error() {
69
+ echo "ERROR: $1" >&2
70
+ }
71
+
72
+ command_exists() {
73
+ command -v "$1" >/dev/null 2>&1
74
+ }
75
+
76
+ is_root() {
77
+ [ "$(id -u)" -eq 0 ]
78
+ }
79
+
80
+ # ============================================================================
81
+ # ENVIRONMENT DETECTION
82
+ # ============================================================================
83
+
84
+ detect_environment() {
85
+ log_info "Detecting environment..."
86
+
87
+ if [ -d "/teamspace/studios/this_studio" ]; then
88
+ BASE_DIR="/teamspace/studios/this_studio"
89
+ ENV_NAME="lightning"
90
+ elif [ -d "/workspace" ] && [ ! -d "/teamspace/studios/this_studio" ]; then
91
+ BASE_DIR="/workspace"
92
+ ENV_NAME="runpod"
93
+ elif is_root && [ ! -d "/teamspace/studios/this_studio" ] && [ ! -d "/workspace" ]; then
94
+ BASE_DIR="/root"
95
+ ENV_NAME="vastai"
96
+ else
97
+ BASE_DIR="$HOME"
98
+ ENV_NAME="generic"
99
+ fi
100
+
101
+ COMFY_INSTALL_DIR="${BASE_DIR}/my_comfy_setup"
102
+ MODELS_DIR="${COMFY_INSTALL_DIR}/models"
103
+ WORKFLOW_FILE="${COMFY_INSTALL_DIR}/workflow.json"
104
+
105
+ log_info "Environment detected: $ENV_NAME"
106
+ log_info "Base directory: $BASE_DIR"
107
+ log_info "ComfyUI install directory: $COMFY_INSTALL_DIR"
108
+ log_info "Models directory: $MODELS_DIR"
109
+ }
110
+
111
+ # ============================================================================
112
+ # PERMISSION MANAGEMENT
113
+ # ============================================================================
114
+
115
+ setup_permissions() {
116
+ log_info "Setting up permissions..."
117
+
118
+ if is_root; then
119
+ SUDO_PREFIX=""
120
+ log_info "Running as root, no sudo needed"
121
+ elif command_exists sudo; then
122
+ SUDO_PREFIX="sudo "
123
+ log_info "Non-root user with sudo available"
124
+ else
125
+ SUDO_PREFIX=""
126
+ log_warning "Non-root user without sudo, some system operations may fail"
127
+ fi
128
+ }
129
+
130
+ # ============================================================================
131
+ # SYSTEM DEPENDENCIES
132
+ # ============================================================================
133
+
134
+ install_system_dependencies() {
135
+ log_info "Installing system dependencies..."
136
+
137
+ if command_exists apt-get; then
138
+ ${SUDO_PREFIX}apt-get update -qq || log_warning "Failed to update package list"
139
+ ${SUDO_PREFIX}apt-get install -y -qq python3 python3-pip git || { log_error "Failed to install basic dependencies (python3, pip, git)"; exit 1; }
140
+ if ${SUDO_PREFIX}apt-get install -y -qq aria2 >/dev/null 2>&1; then ARIA2C_AVAILABLE=true; log_info "aria2c installed successfully"; else ARIA2C_AVAILABLE=false; log_info "aria2c installation failed, will use wget/curl as fallback"; fi
141
+ else
142
+ log_warning "apt-get not available, skipping system package installation"
143
+ if command_exists aria2c; then ARIA2C_AVAILABLE=true; log_info "aria2c already available"; fi
144
+ fi
145
+ }
146
+
147
+ # ============================================================================
148
+ # COMFY-CLI INSTALLATION
149
+ # ============================================================================
150
+
151
+ install_comfy_cli() {
152
+ log_info "Installing comfy-cli..."
153
+
154
+ python3 -m pip install --upgrade comfy-cli || { log_error "Failed to install comfy-cli"; exit 1; }
155
+
156
+ if ! command_exists comfy; then
157
+ if [ -d "$HOME/.local/bin" ]; then export PATH="$HOME/.local/bin:$PATH"; log_info "Added $HOME/.local/bin to PATH"; fi
158
+ if ! command_exists comfy; then log_error "comfy command not found in PATH after installation"; exit 1; fi
159
+ fi
160
+
161
+ log_info "comfy-cli version: $(comfy --version 2>/dev/null || echo 'unknown')"
162
+ }
163
+
164
+ # ============================================================================
165
+ # COMFYUI CORE INSTALLATION
166
+ # ============================================================================
167
+
168
+ install_comfyui_core() {
169
+ log_info "Installing ComfyUI core..."
170
+ comfy --workspace "$COMFY_INSTALL_DIR" --skip-prompt install --nvidia --fast-deps || { log_error "Failed to install ComfyUI core"; exit 1; }
171
+ log_info "ComfyUI core installed successfully"
172
+ }
173
+
174
+ # ============================================================================
175
+ # DIRECTORY STRUCTURE
176
+ # ============================================================================
177
+
178
+ create_model_directories() {
179
+ log_info "Creating model directories..."
180
+ for dir in "${MODEL_DIRS[@]}"; do mkdir -p "$MODELS_DIR/$dir"; log_info "Created directory: $MODELS_DIR/$dir"; done
181
+ mkdir -p "$COMFY_INSTALL_DIR"
182
+ }
183
+
184
+ # ============================================================================
185
+ # CUSTOM NODES INSTALLATION
186
+ # ============================================================================
187
+
188
+ install_custom_nodes() {
189
+ log_info "Installing custom nodes..."
190
+
191
+ log_info "Installing custom node from registry: civicomfy"
192
+ comfy --workspace "$COMFY_INSTALL_DIR" node registry-install civicomfy || { log_warning "Failed to install custom node from registry: civicomfy"; }
193
+
194
+ for node_url in "${CUSTOM_NODES[@]}"; do
195
+ log_info "Installing custom node from Git: $node_url"
196
+ comfy --workspace "$COMFY_INSTALL_DIR" node install "$node_url" || { log_warning "Failed to install custom node: $node_url"; }
197
+ done
198
+ }
199
+
200
+ # ============================================================================
201
+ # SPECIAL NODE: STORY DIFFUSION (NOVA FUNÇÃO)
202
+ # ============================================================================
203
+
204
+ install_story_diffusion_node() {
205
+ log_info "Installing special node: StoryDiffusion..."
206
+ local node_repo="https://github.com/smthemex/ComfyUI_StoryDiffusion.git"
207
+ local node_name="ComfyUI_StoryDiffusion"
208
+ local custom_nodes_dir="${COMFY_INSTALL_DIR}/custom_nodes"
209
+ local target_dir="${custom_nodes_dir}/${node_name}"
210
+ local requirements_file="${target_dir}/requirements.txt"
211
+
212
+ # Garante que o diretório de nós customizados exista
213
+ mkdir -p "$custom_nodes_dir"
214
+
215
+ if [ -d "$target_dir" ]; then
216
+ log_info "StoryDiffusion node already exists. Skipping clone."
217
+ else
218
+ log_info "Cloning StoryDiffusion repository into $target_dir"
219
+ if ! git clone "$node_repo" "$target_dir"; then
220
+ log_error "Failed to clone StoryDiffusion repository."
221
+ # Continuar mesmo com falha, apenas avisar
222
+ return 1
223
+ fi
224
+ fi
225
+
226
+ if [ -f "$requirements_file" ]; then
227
+ log_info "Installing StoryDiffusion dependencies from $requirements_file..."
228
+ if ! python3 -m pip install -r "$requirements_file"; then
229
+ log_warning "Failed to install StoryDiffusion dependencies. This might cause issues."
230
+ else
231
+ log_info "StoryDiffusion dependencies installed successfully."
232
+ fi
233
+ else
234
+ log_info "No requirements.txt found for StoryDiffusion. Skipping dependency installation."
235
+ fi
236
+ }
237
+
238
+
239
+ # ============================================================================
240
+ # DOWNLOAD FUNCTIONS
241
+ # ============================================================================
242
+
243
+ add_civitai_token() { local url="$1"; if [[ "$url" == *"civitai.com/api/download"* ]] && [[ "$url" != *"token="* ]]; then echo "${url}&token=${CIVITAI_TOKEN}"; else echo "$url"; fi; }
244
+
245
+ download_file() {
246
+ local url="$1"; local target_dir="$2"; local filename="$3"; url=$(add_civitai_token "$url"); local download_cmd=""; local success=false
247
+ if $ARIA2C_AVAILABLE && command_exists aria2c; then local aria_opts="-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=0"; if [ -n "$filename" ]; then download_cmd="aria2c $aria_opts --dir=\"$target_dir\" --out=\"$filename\" \"$url\""; else download_cmd="aria2c $aria_opts --dir=\"$target_dir\" --content-disposition=true \"$url\""; fi; if eval "$download_cmd" >/dev/null 2>&1; then success=true; fi; fi
248
+ if ! $success && command_exists wget; then local wget_opts="-q --show-progress -c"; if [ -n "$filename" ]; then download_cmd="wget $wget_opts -O \"$target_dir/$filename\" \"$url\""; else download_cmd="wget $wget_opts --content-disposition -P \"$target_dir\" \"$url\""; fi; if eval "$download_cmd"; then success=true; fi; fi
249
+ if ! $success && command_exists curl; then log_warning "Using curl fallback for $url"; if [ -n "$filename" ]; then download_cmd="curl -L -C - -o \"$target_dir/$filename\" \"$url\""; else if curl --help 2>/dev/null | grep -q "output-dir"; then download_cmd="curl -L -J -O --output-dir \"$target_dir\" \"$url\""; else local fallback_name; fallback_name=$(basename "$url" | cut -d'?' -f1); [ -z "$fallback_name" ] && fallback_name="downloaded_file"; download_cmd="curl -L -C - -o \"$target_dir/$fallback_name\" \"$url\""; fi; fi; if eval "$download_cmd"; then success=true; fi; fi
250
+ if ! $success; then log_error "Failed to download: $url"; return 1; fi; return 0
251
+ }
252
+
253
+ # ============================================================================
254
+ # PARALLEL DOWNLOADS
255
+ # ============================================================================
256
+
257
+ download_all_files() {
258
+ log_info "Starting parallel downloads..."; local pids=(); local download_logs=()
259
+ for file_spec in "${DOWNLOAD_FILES[@]}"; do IFS='|' read -r url target_subdir filename <<< "$file_spec"; local target_dir="$MODELS_DIR/$target_subdir"; local display_name="${filename:-$(basename "$url" | cut -d'?' -f1)}"; log_info "Starting download: $display_name -> $target_dir"; local log_file; log_file=$(mktemp); download_logs+=("$log_file"); ( if download_file "$url" "$target_dir" "$filename" >"$log_file" 2>&1; then echo "SUCCESS: Downloaded $display_name" >> "$log_file"; else echo "FAILED: Failed to download $display_name" >> "$log_file"; exit 1; fi ) & pids+=($!); done
260
+ local failed_count=0; for i in "${!pids[@]}"; do if wait "${pids[$i]}"; then log_info "Download completed successfully"; else failed_count=$((failed_count + 1)); log_warning "Download failed - check logs"; fi; if [ -f "${download_logs[$i]}" ]; then cat "${download_logs[$i]}" >&2; rm -f "${download_logs[$i]}"; fi; done
261
+ if [ $failed_count -gt 0 ]; then log_warning "$failed_count downloads failed, but continuing..."; else log_info "All downloads completed successfully"; fi
262
+ }
263
+
264
+ # ============================================================================
265
+ # WORKFLOW DOWNLOAD
266
+ # ============================================================================
267
+
268
+ download_workflow() {
269
+ log_info "Baixando o workflow de: $WORKFLOW_URL"; log_info "Salvando como: $WORKFLOW_FILE"; local success=false
270
+ if command_exists wget; then if wget -q --show-progress -O "$WORKFLOW_FILE" "$WORKFLOW_URL"; then success=true; fi; fi
271
+ if ! $success && command_exists curl; then if curl -L -o "$WORKFLOW_FILE" "$WORKFLOW_URL"; then success=true; fi; fi
272
+ if ! $success && command_exists aria2c; then if aria2c -q -o "$(basename "$WORKFLOW_FILE")" -d "$(dirname "$WORKFLOW_FILE")" "$WORKFLOW_URL"; then success=true; fi; fi
273
+ if ! $success; then log_error "Nenhuma ferramenta de download (wget, curl, aria2c) funcionou ou está disponível."; exit 1; fi
274
+ if [ ! -f "$WORKFLOW_FILE" ]; then log_error "O arquivo do workflow não foi baixado com sucesso."; exit 1; fi; log_info "Workflow baixado com sucesso."
275
+ }
276
+
277
+ # ============================================================================
278
+ # WORKFLOW DEPENDENCIES
279
+ # ============================================================================
280
+
281
+ install_workflow_dependencies() {
282
+ log_info "Instalando dependências do workflow a partir de: $WORKFLOW_FILE"
283
+ if [ ! -f "$WORKFLOW_FILE" ]; then log_error "Arquivo de workflow não encontrado: $WORKFLOW_FILE"; return 1; fi
284
+ comfy --workspace "$COMFY_INSTALL_DIR" node install-deps --workflow="$WORKFLOW_FILE" || { log_warning "Algumas dependências do workflow podem ter falhado ao instalar."; log_info "Isso pode ser normal. O ComfyUI mostrará os nós ausentes ao iniciar."; }
285
+ log_info "Instalação de dependências do workflow concluída."
286
+ }
287
+
288
+ # ============================================================================
289
+ # COMFYUI LAUNCH
290
+ # ============================================================================
291
+
292
+ launch_comfyui() {
293
+ log_info "Launching ComfyUI on port 8818..."; log_info "ComfyUI will be accessible at: http://0.0.0.0:8818"
294
+ exec comfy --workspace "$COMFY_INSTALL_DIR" launch -- --fast --listen 0.0.0.0 --port 8818
295
+ }
296
+
297
+ # ============================================================================
298
+ # MAIN EXECUTION
299
+ # ============================================================================
300
+
301
+ main() {
302
+ log_info "Starting ComfyUI automated setup..."
303
+ log_info "========================================"
304
+
305
+ detect_environment
306
+ setup_permissions
307
+ install_system_dependencies
308
+ install_comfy_cli
309
+ install_comfyui_core
310
+ create_model_directories
311
+ install_custom_nodes
312
+
313
+ # NOVA ETAPA: Instala o nó StoryDiffusion e suas dependências
314
+ install_story_diffusion_node
315
+
316
+ download_all_files
317
+ download_workflow
318
+ install_workflow_dependencies
319
+
320
+ log_info "========================================"
321
+ log_info "Setup completed successfully!"
322
+ log_info "========================================"
323
+ launch_comfyui
324
+ }
325
+
326
+ # ============================================================================
327
+ # SCRIPT EXECUTION
328
+ # ============================================================================
329
+
330
+ trap 'log_error "Script interrupted"; exit 1' INT TERM
331
+
332
+ main "$@"