nathanglm commited on
Commit
62c62b6
·
verified ·
1 Parent(s): 995f52c

Update wan.sh

Browse files
Files changed (1) hide show
  1. wan.sh +327 -330
wan.sh CHANGED
@@ -1,331 +1,328 @@
1
- #!/bin/bash
2
-
3
- source /venv/main/bin/activate
4
- COMFYUI_DIR=${WORKSPACE}/ComfyUI
5
-
6
- # Packages are installed after nodes so we can fix them...
7
-
8
- APT_PACKAGES=(
9
- #"package-1"
10
- #"package-2"
11
- )
12
-
13
- PIP_PACKAGES=(
14
- "google-genai"
15
- "xai-sdk"
16
- )
17
-
18
- NODES=(
19
- "https://github.com/ltdrdata/ComfyUI-Manager"
20
- "https://github.com/rgthree/rgthree-comfy"
21
- "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
22
- "https://github.com/yolain/ComfyUI-Easy-Use"
23
- "https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
24
- "https://github.com/sipherxyz/comfyui-art-venture"
25
- "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
26
- "https://github.com/moonwhaler/comfyui-moonpack"
27
- "https://github.com/gseth/ControlAltAI-Nodes"
28
- "https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
29
- "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
30
- "https://github.com/robertvoy/ComfyUI-Flux-Continuum"
31
- "https://github.com/ltdrdata/was-node-suite-comfyui"
32
- "https://github.com/ChangeTheConstants/SeedVarianceEnhancer"
33
- "https://github.com/city96/ComfyUI-GGUF"
34
- "https://github.com/kijai/ComfyUI-KJNodes"
35
- "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
36
- "https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
37
- )
38
-
39
- WORKFLOWS=(
40
- )
41
-
42
- SAMS=(
43
- )
44
-
45
-
46
- CHECKPOINT_MODELS=(
47
- )
48
-
49
- BBOX=(
50
- )
51
-
52
- UNET_MODELS=(
53
- )
54
-
55
- # Format: "URL|filename.safetensors"
56
- LORA_MODELS=(
57
- )
58
-
59
- VAE_MODELS=(
60
- "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/vae/qwen_image_vae.safetensors"
61
- "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/blob/main/split_files/vae/wan2.2_vae.safetensors"
62
- )
63
-
64
- DIFFUSION_MODELS=(
65
- "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/diffusion_models/qwen_image_edit_fp8_e4m3fn.safetensors"
66
- "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/blob/main/Wan22Animate/Wan2_2-Animate-14B_fp8_e4m3fn_scaled_KJ.safetensors"
67
- "https://huggingface.co/numz/SeedVR2_comfyUI/blob/main/seedvr2_ema_3b_fp8_e4m3fn.safetensors"
68
- )
69
-
70
- TEXT_ENCODERS=(
71
- "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/text_encoders/qwen_2.5_vl_7b_fp8_scaled.safetensors"
72
- "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/blob/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors"
73
- )
74
-
75
- ESRGAN_MODELS=(
76
- )
77
-
78
- CONTROLNET_MODELS=(
79
- )
80
-
81
- ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
82
-
83
- function provisioning_start() {
84
- provisioning_print_header
85
- provisioning_get_apt_packages
86
- provisioning_get_nodes
87
- provisioning_get_pip_packages
88
- provisioning_get_files \
89
- "${COMFYUI_DIR}/models/sams" \
90
- "${SAMS[@]}"
91
- provisioning_get_files \
92
- "${COMFYUI_DIR}/models/checkpoints" \
93
- "${CHECKPOINT_MODELS[@]}"
94
- provisioning_get_files \
95
- "${COMFYUI_DIR}/models/ultralytics/bbox" \
96
- "${BBOX[@]}"
97
- provisioning_get_files \
98
- "${COMFYUI_DIR}/models/unet" \
99
- "${UNET_MODELS[@]}"
100
- provisioning_get_files \
101
- "${COMFYUI_DIR}/models/loras" \
102
- "${LORA_MODELS[@]}"
103
- provisioning_get_files \
104
- "${COMFYUI_DIR}/models/diffusion_models" \
105
- "${DIFFUSION_MODELS[@]}"
106
- provisioning_get_files \
107
- "${COMFYUI_DIR}/models/text_encoders" \
108
- "${TEXT_ENCODERS[@]}"
109
- provisioning_get_files \
110
- "${COMFYUI_DIR}/models/controlnet" \
111
- "${CONTROLNET_MODELS[@]}"
112
- provisioning_get_files \
113
- "${COMFYUI_DIR}/models/vae" \
114
- "${VAE_MODELS[@]}"
115
- provisioning_get_files \
116
- "${COMFYUI_DIR}/user/default/workflows" \
117
- "${WORKFLOWS[@]}"
118
- provisioning_get_files \
119
- "${COMFYUI_DIR}/models/esrgan" \
120
- "${ESRGAN_MODELS[@]}"
121
- provisioning_print_end
122
- }
123
-
124
- function provisioning_get_apt_packages() {
125
- if [[ -n $APT_PACKAGES ]]; then
126
- sudo $APT_INSTALL ${APT_PACKAGES[@]}
127
- fi
128
- }
129
-
130
- function provisioning_get_pip_packages() {
131
- if [[ -n $PIP_PACKAGES ]]; then
132
- pip install --no-cache-dir ${PIP_PACKAGES[@]}
133
- fi
134
- }
135
-
136
- function provisioning_get_nodes() {
137
- for repo in "${NODES[@]}"; do
138
- dir="${repo##*/}"
139
- path="${COMFYUI_DIR}/custom_nodes/${dir}"
140
- requirements="${path}/requirements.txt"
141
- if [[ -d $path ]]; then
142
- if [[ ${AUTO_UPDATE,,} != "false" ]]; then
143
- printf "Updating node: %s...\n" "${repo}"
144
- ( cd "$path" && git pull )
145
- if [[ -e $requirements ]]; then
146
- pip install --no-cache-dir -r "$requirements"
147
- fi
148
- fi
149
- else
150
- printf "Downloading node: %s...\n" "${repo}"
151
- git clone "${repo}" "${path}" --recursive
152
- if [[ -e $requirements ]]; then
153
- pip install --no-cache-dir -r "${requirements}"
154
- fi
155
- fi
156
- done
157
- }
158
-
159
- function provisioning_get_files() {
160
- if [[ -z $2 ]]; then return 1; fi
161
-
162
- dir="$1"
163
- mkdir -p "$dir"
164
- shift
165
- arr=("$@")
166
- printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
167
- for entry in "${arr[@]}"; do
168
- # Support "URL|filename" format for custom filenames
169
- if [[ "$entry" == *"|"* ]]; then
170
- url="${entry%%|*}"
171
- filename="${entry##*|}"
172
- else
173
- url="$entry"
174
- filename=""
175
- fi
176
- printf "Downloading: %s\n" "${url}"
177
- provisioning_download "${url}" "${dir}" "${filename}"
178
- printf "\n"
179
- done
180
- }
181
-
182
- function provisioning_print_header() {
183
- printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
184
- }
185
-
186
- function provisioning_print_end() {
187
- printf "\nProvisioning complete: Application will start now\n\n"
188
- }
189
-
190
- function provisioning_has_valid_hf_token() {
191
- [[ -n "$HF_TOKEN" ]] || return 1
192
- url="https://huggingface.co/api/whoami-v2"
193
-
194
- response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
195
- -H "Authorization: Bearer $HF_TOKEN" \
196
- -H "Content-Type: application/json")
197
-
198
- if [ "$response" -eq 200 ]; then
199
- return 0
200
- else
201
- return 1
202
- fi
203
- }
204
-
205
- function provisioning_has_valid_civitai_token() {
206
- [[ -n "$CIVITAI_TOKEN" ]] || return 1
207
- url="https://civitai.com/api/v1/models?hidden=1&limit=1"
208
-
209
- response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
210
- -H "Authorization: Bearer $CIVITAI_TOKEN" \
211
- -H "Content-Type: application/json")
212
-
213
- if [ "$response" -eq 200 ]; then
214
- return 0
215
- else
216
- return 1
217
- fi
218
- }
219
-
220
- # Download CivitAI models with curl (pure bash)
221
- function download_civitai_bash() {
222
- local url="$1"
223
- local output_dir="$2"
224
- local forced_filename="$3"
225
- local model_id=""
226
-
227
- if [[ $url =~ /models/([0-9]+) ]]; then
228
- model_id="${BASH_REMATCH[1]}"
229
- else
230
- printf "ERROR: Could not extract model ID from URL\n"
231
- return 1
232
- fi
233
-
234
- printf "Downloading CivitAI model %s...\n" "$model_id"
235
-
236
- if [[ -n "$forced_filename" ]]; then
237
- local output_file="${output_dir}/${forced_filename}"
238
- if [[ -f "$output_file" ]]; then
239
- printf "File already exists: %s\n" "$forced_filename"
240
- return 0
241
- fi
242
- printf "Downloading to: %s\n" "$forced_filename"
243
- if [[ -n "$CIVITAI_TOKEN" ]]; then
244
- curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
245
- else
246
- curl -L -o "$output_file" --progress-bar "$url"
247
- fi
248
- if [[ $? -eq 0 ]]; then
249
- printf "Download completed: %s\n" "$forced_filename"
250
- return 0
251
- else
252
- printf "ERROR: Download failed for model %s\n" "$model_id"
253
- return 1
254
- fi
255
- fi
256
-
257
- local redirect_url=""
258
- if [[ -n "$CIVITAI_TOKEN" ]]; then
259
- redirect_url=$(curl -s -I -L -H "Authorization: Bearer $CIVITAI_TOKEN" "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
260
- else
261
- redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
262
- fi
263
-
264
- if [[ -z "$redirect_url" ]]; then
265
- printf "ERROR: Could not get redirect URL for model %s\n" "$model_id"
266
- return 1
267
- fi
268
-
269
- local filename=""
270
-
271
- if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
272
- filename="${BASH_REMATCH[1]}"
273
- filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
274
- elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
275
- filename="${BASH_REMATCH[1]}"
276
- elif [[ $redirect_url =~ filename=([^&]+) ]]; then
277
- filename="${BASH_REMATCH[1]}"
278
- else
279
- local path_part=$(echo "$redirect_url" | sed 's/?.*//')
280
- filename=$(basename "$path_part")
281
- if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
282
- filename="${filename}.safetensors"
283
- fi
284
- fi
285
-
286
- filename=$(printf '%b' "${filename//%/\\x}")
287
-
288
- if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
289
- filename="civitai_${model_id}.safetensors"
290
- fi
291
-
292
- local output_file="${output_dir}/${filename}"
293
-
294
- if [[ -f "$output_file" ]]; then
295
- printf "File already exists: %s\n" "$filename"
296
- return 0
297
- fi
298
-
299
- printf "Downloading to: %s\n" "$filename"
300
- curl -L -o "$output_file" --progress-bar "$redirect_url"
301
-
302
- if [[ $? -eq 0 ]]; then
303
- printf "Download completed: %s\n" "$filename"
304
- return 0
305
- else
306
- printf "ERROR: Download failed for model %s\n" "$model_id"
307
- return 1
308
- fi
309
- }
310
-
311
- # Download from $1 URL to $2 file path, with optional $3 forced filename
312
- function provisioning_download() {
313
- local url="$1"
314
- local dir="$2"
315
- local forced_filename="$3"
316
-
317
- if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
318
- download_civitai_bash "$url" "$dir" "$forced_filename"
319
- else
320
- if [[ -n "$forced_filename" ]]; then
321
- wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
322
- else
323
- wget -qnc --content-disposition --show-progress -e dotbytes="${4:-4M}" -P "$dir" "$url"
324
- fi
325
- fi
326
- }
327
-
328
- # Allow user to disable provisioning if they started with a script they didn't want
329
- if [[ ! -f /.noprovisioning ]]; then
330
- provisioning_start
331
  fi
 
1
+ #!/bin/bash
2
+
3
+ source /venv/main/bin/activate
4
+ COMFYUI_DIR=${WORKSPACE}/ComfyUI
5
+
6
+ # Packages are installed after nodes so we can fix them...
7
+
8
+ APT_PACKAGES=(
9
+ #"package-1"
10
+ #"package-2"
11
+ )
12
+
13
+ PIP_PACKAGES=(
14
+ "google-genai"
15
+ "xai-sdk"
16
+ )
17
+
18
+ NODES=(
19
+ "https://github.com/ltdrdata/ComfyUI-Manager"
20
+ "https://github.com/rgthree/rgthree-comfy"
21
+ "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
22
+ "https://github.com/yolain/ComfyUI-Easy-Use"
23
+ "https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
24
+ "https://github.com/sipherxyz/comfyui-art-venture"
25
+ "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
26
+ "https://github.com/moonwhaler/comfyui-moonpack"
27
+ "https://github.com/gseth/ControlAltAI-Nodes"
28
+ "https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
29
+ "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
30
+ "https://github.com/robertvoy/ComfyUI-Flux-Continuum"
31
+ "https://github.com/ltdrdata/was-node-suite-comfyui"
32
+ "https://github.com/ChangeTheConstants/SeedVarianceEnhancer"
33
+ "https://github.com/city96/ComfyUI-GGUF"
34
+ "https://github.com/kijai/ComfyUI-KJNodes"
35
+ "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
36
+ "https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
37
+ "https://github.com/kijai/ComfyUI-WanVideoWrapper"
38
+ "https://github.com/ClownsharkBatwing/RES4LYF"
39
+ "https://github.com/DragonDiffusionbyBoyo/Boyonodes"
40
+ "https://github.com/K3NK3/ComfyUI-K3NK-ComfyUI-Nodes"
41
+ )
42
+
43
+ WORKFLOWS=(
44
+ )
45
+
46
+ SAMS=(
47
+ )
48
+
49
+
50
+ CHECKPOINT_MODELS=(
51
+ )
52
+
53
+ BBOX=(
54
+ )
55
+
56
+ UNET_MODELS=(
57
+ )
58
+
59
+ # Format: "URL|filename.safetensors"
60
+ LORA_MODELS=(
61
+ )
62
+
63
+ VAE_MODELS=(
64
+ )
65
+
66
+ DIFFUSION_MODELS=(
67
+ )
68
+
69
+ TEXT_ENCODERS=(
70
+ )
71
+
72
+ ESRGAN_MODELS=(
73
+ )
74
+
75
+ CONTROLNET_MODELS=(
76
+ )
77
+
78
+ ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
79
+
80
+ function provisioning_start() {
81
+ provisioning_print_header
82
+ provisioning_get_apt_packages
83
+ provisioning_get_nodes
84
+ provisioning_get_pip_packages
85
+ provisioning_get_files \
86
+ "${COMFYUI_DIR}/models/sams" \
87
+ "${SAMS[@]}"
88
+ provisioning_get_files \
89
+ "${COMFYUI_DIR}/models/checkpoints" \
90
+ "${CHECKPOINT_MODELS[@]}"
91
+ provisioning_get_files \
92
+ "${COMFYUI_DIR}/models/ultralytics/bbox" \
93
+ "${BBOX[@]}"
94
+ provisioning_get_files \
95
+ "${COMFYUI_DIR}/models/unet" \
96
+ "${UNET_MODELS[@]}"
97
+ provisioning_get_files \
98
+ "${COMFYUI_DIR}/models/loras" \
99
+ "${LORA_MODELS[@]}"
100
+ provisioning_get_files \
101
+ "${COMFYUI_DIR}/models/diffusion_models" \
102
+ "${DIFFUSION_MODELS[@]}"
103
+ provisioning_get_files \
104
+ "${COMFYUI_DIR}/models/text_encoders" \
105
+ "${TEXT_ENCODERS[@]}"
106
+ provisioning_get_files \
107
+ "${COMFYUI_DIR}/models/controlnet" \
108
+ "${CONTROLNET_MODELS[@]}"
109
+ provisioning_get_files \
110
+ "${COMFYUI_DIR}/models/vae" \
111
+ "${VAE_MODELS[@]}"
112
+ provisioning_get_files \
113
+ "${COMFYUI_DIR}/user/default/workflows" \
114
+ "${WORKFLOWS[@]}"
115
+ provisioning_get_files \
116
+ "${COMFYUI_DIR}/models/esrgan" \
117
+ "${ESRGAN_MODELS[@]}"
118
+ provisioning_print_end
119
+ }
120
+
121
+ function provisioning_get_apt_packages() {
122
+ if [[ -n $APT_PACKAGES ]]; then
123
+ sudo $APT_INSTALL ${APT_PACKAGES[@]}
124
+ fi
125
+ }
126
+
127
+ function provisioning_get_pip_packages() {
128
+ if [[ -n $PIP_PACKAGES ]]; then
129
+ pip install --no-cache-dir ${PIP_PACKAGES[@]}
130
+ fi
131
+ }
132
+
133
+ function provisioning_get_nodes() {
134
+ for repo in "${NODES[@]}"; do
135
+ dir="${repo##*/}"
136
+ path="${COMFYUI_DIR}/custom_nodes/${dir}"
137
+ requirements="${path}/requirements.txt"
138
+ if [[ -d $path ]]; then
139
+ if [[ ${AUTO_UPDATE,,} != "false" ]]; then
140
+ printf "Updating node: %s...\n" "${repo}"
141
+ ( cd "$path" && git pull )
142
+ if [[ -e $requirements ]]; then
143
+ pip install --no-cache-dir -r "$requirements"
144
+ fi
145
+ fi
146
+ else
147
+ printf "Downloading node: %s...\n" "${repo}"
148
+ git clone "${repo}" "${path}" --recursive
149
+ if [[ -e $requirements ]]; then
150
+ pip install --no-cache-dir -r "${requirements}"
151
+ fi
152
+ fi
153
+ done
154
+ }
155
+
156
+ function provisioning_get_files() {
157
+ if [[ -z $2 ]]; then return 1; fi
158
+
159
+ dir="$1"
160
+ mkdir -p "$dir"
161
+ shift
162
+ arr=("$@")
163
+ printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
164
+ for entry in "${arr[@]}"; do
165
+ # Support "URL|filename" format for custom filenames
166
+ if [[ "$entry" == *"|"* ]]; then
167
+ url="${entry%%|*}"
168
+ filename="${entry##*|}"
169
+ else
170
+ url="$entry"
171
+ filename=""
172
+ fi
173
+ printf "Downloading: %s\n" "${url}"
174
+ provisioning_download "${url}" "${dir}" "${filename}"
175
+ printf "\n"
176
+ done
177
+ }
178
+
179
+ function provisioning_print_header() {
180
+ printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
181
+ }
182
+
183
+ function provisioning_print_end() {
184
+ printf "\nProvisioning complete: Application will start now\n\n"
185
+ }
186
+
187
+ function provisioning_has_valid_hf_token() {
188
+ [[ -n "$HF_TOKEN" ]] || return 1
189
+ url="https://huggingface.co/api/whoami-v2"
190
+
191
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
192
+ -H "Authorization: Bearer $HF_TOKEN" \
193
+ -H "Content-Type: application/json")
194
+
195
+ if [ "$response" -eq 200 ]; then
196
+ return 0
197
+ else
198
+ return 1
199
+ fi
200
+ }
201
+
202
+ function provisioning_has_valid_civitai_token() {
203
+ [[ -n "$CIVITAI_TOKEN" ]] || return 1
204
+ url="https://civitai.com/api/v1/models?hidden=1&limit=1"
205
+
206
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
207
+ -H "Authorization: Bearer $CIVITAI_TOKEN" \
208
+ -H "Content-Type: application/json")
209
+
210
+ if [ "$response" -eq 200 ]; then
211
+ return 0
212
+ else
213
+ return 1
214
+ fi
215
+ }
216
+
217
+ # Download CivitAI models with curl (pure bash)
218
+ function download_civitai_bash() {
219
+ local url="$1"
220
+ local output_dir="$2"
221
+ local forced_filename="$3"
222
+ local model_id=""
223
+
224
+ if [[ $url =~ /models/([0-9]+) ]]; then
225
+ model_id="${BASH_REMATCH[1]}"
226
+ else
227
+ printf "ERROR: Could not extract model ID from URL\n"
228
+ return 1
229
+ fi
230
+
231
+ printf "Downloading CivitAI model %s...\n" "$model_id"
232
+
233
+ if [[ -n "$forced_filename" ]]; then
234
+ local output_file="${output_dir}/${forced_filename}"
235
+ if [[ -f "$output_file" ]]; then
236
+ printf "File already exists: %s\n" "$forced_filename"
237
+ return 0
238
+ fi
239
+ printf "Downloading to: %s\n" "$forced_filename"
240
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
241
+ curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
242
+ else
243
+ curl -L -o "$output_file" --progress-bar "$url"
244
+ fi
245
+ if [[ $? -eq 0 ]]; then
246
+ printf "Download completed: %s\n" "$forced_filename"
247
+ return 0
248
+ else
249
+ printf "ERROR: Download failed for model %s\n" "$model_id"
250
+ return 1
251
+ fi
252
+ fi
253
+
254
+ local redirect_url=""
255
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
256
+ redirect_url=$(curl -s -I -L -H "Authorization: Bearer $CIVITAI_TOKEN" "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
257
+ else
258
+ redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
259
+ fi
260
+
261
+ if [[ -z "$redirect_url" ]]; then
262
+ printf "ERROR: Could not get redirect URL for model %s\n" "$model_id"
263
+ return 1
264
+ fi
265
+
266
+ local filename=""
267
+
268
+ if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
269
+ filename="${BASH_REMATCH[1]}"
270
+ filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
271
+ elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
272
+ filename="${BASH_REMATCH[1]}"
273
+ elif [[ $redirect_url =~ filename=([^&]+) ]]; then
274
+ filename="${BASH_REMATCH[1]}"
275
+ else
276
+ local path_part=$(echo "$redirect_url" | sed 's/?.*//')
277
+ filename=$(basename "$path_part")
278
+ if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
279
+ filename="${filename}.safetensors"
280
+ fi
281
+ fi
282
+
283
+ filename=$(printf '%b' "${filename//%/\\x}")
284
+
285
+ if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
286
+ filename="civitai_${model_id}.safetensors"
287
+ fi
288
+
289
+ local output_file="${output_dir}/${filename}"
290
+
291
+ if [[ -f "$output_file" ]]; then
292
+ printf "File already exists: %s\n" "$filename"
293
+ return 0
294
+ fi
295
+
296
+ printf "Downloading to: %s\n" "$filename"
297
+ curl -L -o "$output_file" --progress-bar "$redirect_url"
298
+
299
+ if [[ $? -eq 0 ]]; then
300
+ printf "Download completed: %s\n" "$filename"
301
+ return 0
302
+ else
303
+ printf "ERROR: Download failed for model %s\n" "$model_id"
304
+ return 1
305
+ fi
306
+ }
307
+
308
+ # Download from $1 URL to $2 file path, with optional $3 forced filename
309
+ function provisioning_download() {
310
+ local url="$1"
311
+ local dir="$2"
312
+ local forced_filename="$3"
313
+
314
+ if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
315
+ download_civitai_bash "$url" "$dir" "$forced_filename"
316
+ else
317
+ if [[ -n "$forced_filename" ]]; then
318
+ wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
319
+ else
320
+ wget -qnc --content-disposition --show-progress -e dotbytes="${4:-4M}" -P "$dir" "$url"
321
+ fi
322
+ fi
323
+ }
324
+
325
+ # Allow user to disable provisioning if they started with a script they didn't want
326
+ if [[ ! -f /.noprovisioning ]]; then
327
+ provisioning_start
 
 
 
328
  fi