File size: 17,551 Bytes
62c62b6
 
 
 
 
 
 
 
 
 
 
 
 
947b6fd
62c62b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e692eb
 
 
 
 
 
 
 
 
 
 
 
 
a1cf511
abb85e5
 
 
bdf6e50
 
 
62c62b6
 
 
d8bfce1
e306e8f
62c62b6
 
 
 
 
8e692eb
 
3d5ab6a
8e692eb
62c62b6
a1cf511
51a873f
df2447e
a1cf511
 
62c62b6
 
 
 
 
 
 
 
 
a1cf511
 
35cd646
a1cf511
 
62c62b6
 
8e692eb
4136ac7
 
4199bfe
4490ee9
36d3642
 
8bf6842
 
 
 
 
 
 
 
 
6871316
 
53d73a9
 
 
 
4490ee9
 
92a8308
 
 
 
62c62b6
 
 
8e692eb
 
62c62b6
 
 
b6ad6d6
8e692eb
 
 
 
 
62c62b6
 
 
 
 
338beab
 
 
 
 
62c62b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e692eb
 
 
a1cf511
 
 
62c62b6
 
 
338beab
 
 
62c62b6
 
 
a1cf511
 
 
62c62b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
995f52c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash

source /venv/main/bin/activate
COMFYUI_DIR=${WORKSPACE}/ComfyUI

# Packages are installed after nodes so we can fix them...

APT_PACKAGES=(
    #"package-1"
    #"package-2"
)

PIP_PACKAGES=(
    "mediapipe==0.10.21"
)

NODES=(
    "https://github.com/ltdrdata/ComfyUI-Manager"
    "https://github.com/rgthree/rgthree-comfy"
    "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
    "https://github.com/yolain/ComfyUI-Easy-Use"
    "https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
    "https://github.com/sipherxyz/comfyui-art-venture"
    "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
    "https://github.com/moonwhaler/comfyui-moonpack"
    "https://github.com/gseth/ControlAltAI-Nodes"
    "https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
    "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
    "https://github.com/robertvoy/ComfyUI-Flux-Continuum"
    "https://github.com/ltdrdata/was-node-suite-comfyui"
    "https://github.com/ChangeTheConstants/SeedVarianceEnhancer"
    "https://github.com/city96/ComfyUI-GGUF"
    "https://github.com/kijai/ComfyUI-KJNodes"
    "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
    "https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
    "https://github.com/kijai/ComfyUI-WanVideoWrapper"
    "https://github.com/PGCRT/CRT-Nodes"
    "https://github.com/chibiace/ComfyUI-Chibi-Nodes"
    "https://github.com/crystian/comfyui-crystools"
    "https://github.com/kijai/ComfyUI-MelBandRoFormer"
    "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite"
    "https://github.com/kijai/ComfyUI-WanAnimatePreprocess"
    "https://github.com/Smirnov75/ComfyUI-mxToolkit"
    "https://github.com/chrisgoringe/cg-use-everywhere"
    "https://github.com/kijai/ComfyUI-Florence2"
    "https://github.com/kijai/ComfyUI-segment-anything-2"
    "https://github.com/un-seen/comfyui-tensorops"
    "https://github.com/jamesWalker55/comfyui-various"
    "https://github.com/cubiq/ComfyUI_essentials"
    "https://github.com/Daxamur/DaxNodes"
    "https://github.com/ClownsharkBatwing/RES4LYF"
    "https://github.com/chrisgoringe/cg-image-filter"
    "https://github.com/M1kep/ComfyLiterals"
    "https://github.com/evanspearman/ComfyMath"
    "https://github.com/digitaljohn/comfyui-propost"
    "https://github.com/Fannovel16/ComfyUI-Frame-Interpolation"
)

WORKFLOWS=(
    "https://huggingface.co/nathanglm/sofia/resolve/main/WAN%20v1.json"
    "https://huggingface.co/nathanglm/sofia/resolve/main/WAN%20ANIMATE%20v1.json"
)

SAMS=(
)

CLIP=(
    "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/umt5-xxl-enc-bf16.safetensors"
    "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors"
)

CLIP_VISION=(
    "https://huggingface.co/openai/clip-vit-large-patch14/resolve/main/model.safetensors|clip-vit-large-patch14.safetensors"
    "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/clip_vision/clip_vision_h.safetensors"
)

CHECKPOINT_MODELS=(
)

BBOX=(
)

UNET_MODELS=(
)

UPSCALE_MODELS=(
    "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth"
    "https://huggingface.co/lllyasviel/Annotators/resolve/main/RealESRGAN_x4plus.pth"
)

# Format: "URL|filename.safetensors"
LORA_MODELS=(
    "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/LoRAs/Wan22_relight/WanAnimate_relight_lora_fp16.safetensors"
    "https://huggingface.co/lightx2v/Wan2.2-I2V-A14B-Moe-Distill-Lightx2v/resolve/main/loras/low_noise_model_rank64.safetensors|LIGHTX2V_I2V_2_2_LOW.safetensors"
    "https://huggingface.co/lightx2v/Wan2.2-I2V-A14B-Moe-Distill-Lightx2v/resolve/main/loras/high_noise_model_rank64.safetensors|LIGHTX2V_I2V_2_2_HIGH.safetensors"
    "https://civitai.com/api/download/models/2140962?type=Model&format=SafeTensor&size=full&fp=fp16|Wan21_I2V_14B_lightx2v_cfg_step_distill_lora_rank64.safetensors"
    "https://civitai.com/api/download/models/2066914?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-T2V-2.2-Lenovo-UltraReal.safetensors"
    "https://civitai.com/api/download/models/2209481?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Perfect-Fingering-LOW-v1.safetensors"
    "https://civitai.com/api/download/models/2209275?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Perfect-Fingering-HIGH-v1.safetensors"
    "https://civitai.com/api/download/models/2553271?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-DR34ML4Y-All-In-One-NSFW-LOW-v2.safetensors"
    "https://civitai.com/api/download/models/2553151?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-DR34ML4Y-All-In-One-NSFW-HIGH-v2.safetensors"
    "https://civitai.com/api/download/models/2012120?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Genitals-helper.safetensors"
    "https://civitai.com/api/download/models/2073605?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-General-NSFW-HIGH.safetensors"
    "https://civitai.com/api/download/models/2083303?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-General-NSFW-LOW.safetensors"
    "https://civitai.com/api/download/models/2405949?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Dildo-Classic-Closeup-LOW-v2.safetensors"
    "https://civitai.com/api/download/models/2405940?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Dildo-Classic-Closeup-HIGH-v2.safetensors"
    "https://civitai.com/api/download/models/2405930?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Dildo-Classic-Fullbody-LOW-v2.safetensors"
    "https://civitai.com/api/download/models/2405917?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Dildo-Classic-Fullbody-HIGH-v2.safetensors"
    "https://civitai.com/api/download/models/2448070?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Breast-Play-LOW-v2.safetensors"
    "https://civitai.com/api/download/models/2448064?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Breast-Play-HIGH-v2.safetensors"
    "https://civitai.com/api/download/models/2564047?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Rub-Pussy-LOW.safetensors"
    "https://civitai.com/api/download/models/2563945?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Rub-Pussy-HIGH.safetensors"
    "https://civitai.com/api/download/models/2098396?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-POV-Missionary-LOW.safetensors"
    "https://civitai.com/api/download/models/2098405?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-POV-Missionary-HIGH.safetensors"
    "https://civitai.com/api/download/models/2665810?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-T2V-2.2-Boobs-Physics-LOW-v8.safetensors"
    "https://civitai.com/api/download/models/2661167?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-T2V-2.2-Boobs-Physics-HIGH-v8.safetensors"
    "https://civitai.com/api/download/models/2347125?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Ass-shaking-dance-LOW-v2.safetensors"
    "https://civitai.com/api/download/models/2347127?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Ass-shaking-dance-HIGH-v2.safetensors"
    "https://civitai.com/api/download/models/2191270?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Bouncing-Boobs-LOW.safetensors"
    "https://civitai.com/api/download/models/2191217?type=Model&format=SafeTensor&size=full&fp=fp16|WAN-I2V-2.2-Bouncing-Boobs-HIGH.safetensors"
)

VAE_MODELS=(
    "https://huggingface.co/Kijai/WanVideo_comfy/blob/main/FlashVSR/Wan2_1_FlashVSR_TCDecoder_fp32.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/Wan2_1_VAE_bf16.safetensors"
)

DIFFUSION_MODELS=(
    "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/resolve/main/Wan22Animate/Wan2_2-Animate-14B_fp8_scaled_e4m3fn_KJ_v2.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/FlashVSR/Wan2_1-T2V-1_3B_FlashVSR_fp32.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/FlashVSR/Wan2_1_FlashVSR_LQ_proj_model_bf16.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/resolve/main/Wan22Animate/Wan2_2-Animate-14B_fp8_scaled_e4m3fn_KJ_v2.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/resolve/main/I2V/Wan2_2-I2V-A14B-HIGH_fp8_e4m3fn_scaled_KJ.safetensors"
    "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/resolve/main/I2V/Wan2_2-I2V-A14B-LOW_fp8_e4m3fn_scaled_KJ.safetensors"
)

TEXT_ENCODERS=(
)

DETECTION=(
    "https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/wholebody/vitpose-l-wholebody.onnx"
    "https://huggingface.co/Wan-AI/Wan2.2-Animate-14B/resolve/main/process_checkpoint/det/yolov10m.onnx"
)

ESRGAN_MODELS=(
)

CONTROLNET_MODELS=(
)

### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###

function provisioning_start() {
    provisioning_print_header
    provisioning_get_apt_packages
    provisioning_get_nodes
    provisioning_get_pip_packages
    provisioning_get_files \
        "${COMFYUI_DIR}/models/sams" \
        "${SAMS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/checkpoints" \
        "${CHECKPOINT_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/ultralytics/bbox" \
        "${BBOX[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/unet" \
        "${UNET_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/clip" \
        "${CLIP[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/clip_vision" \
        "${CLIP_VISION[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/loras" \
        "${LORA_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/detection" \
        "${DETECTION[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/diffusion_models" \
        "${DIFFUSION_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/upscale_models" \
        "${UPSCALE_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/text_encoders" \
        "${TEXT_ENCODERS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/controlnet" \
        "${CONTROLNET_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/vae" \
        "${VAE_MODELS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/user/default/workflows" \
        "${WORKFLOWS[@]}"
    provisioning_get_files \
        "${COMFYUI_DIR}/models/esrgan" \
        "${ESRGAN_MODELS[@]}"
    provisioning_print_end
}

function provisioning_get_apt_packages() {
    if [[ -n $APT_PACKAGES ]]; then
            sudo $APT_INSTALL ${APT_PACKAGES[@]}
    fi
}

function provisioning_get_pip_packages() {
    if [[ -n $PIP_PACKAGES ]]; then
            pip install --no-cache-dir ${PIP_PACKAGES[@]}
    fi
}

function provisioning_get_nodes() {
    for repo in "${NODES[@]}"; do
        dir="${repo##*/}"
        path="${COMFYUI_DIR}/custom_nodes/${dir}"
        requirements="${path}/requirements.txt"
        if [[ -d $path ]]; then
            if [[ ${AUTO_UPDATE,,} != "false" ]]; then
                printf "Updating node: %s...\n" "${repo}"
                ( cd "$path" && git pull )
                if [[ -e $requirements ]]; then
                   pip install --no-cache-dir -r "$requirements"
                fi
            fi
        else
            printf "Downloading node: %s...\n" "${repo}"
            git clone "${repo}" "${path}" --recursive
            if [[ -e $requirements ]]; then
                pip install --no-cache-dir -r "${requirements}"
            fi
        fi
    done
}

function provisioning_get_files() {
    if [[ -z $2 ]]; then return 1; fi
    
    dir="$1"
    mkdir -p "$dir"
    shift
    arr=("$@")
    printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
    for entry in "${arr[@]}"; do
        # Support "URL|filename" format for custom filenames
        if [[ "$entry" == *"|"* ]]; then
            url="${entry%%|*}"
            filename="${entry##*|}"
        else
            url="$entry"
            filename=""
        fi
        printf "Downloading: %s\n" "${url}"
        provisioning_download "${url}" "${dir}" "${filename}"
        printf "\n"
    done
}

function provisioning_print_header() {
    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"
}

function provisioning_print_end() {
    printf "\nProvisioning complete:  Application will start now\n\n"
}

function provisioning_has_valid_hf_token() {
    [[ -n "$HF_TOKEN" ]] || return 1
    url="https://huggingface.co/api/whoami-v2"

    response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
        -H "Authorization: Bearer $HF_TOKEN" \
        -H "Content-Type: application/json")

    if [ "$response" -eq 200 ]; then
        return 0
    else
        return 1
    fi
}

function provisioning_has_valid_civitai_token() {
    [[ -n "$CIVITAI_TOKEN" ]] || return 1
    url="https://civitai.com/api/v1/models?hidden=1&limit=1"

    response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
        -H "Authorization: Bearer $CIVITAI_TOKEN" \
        -H "Content-Type: application/json")

    if [ "$response" -eq 200 ]; then
        return 0
        else
        return 1
    fi
}

# Download CivitAI models with curl (pure bash)
function download_civitai_bash() {
    local url="$1"
    local output_dir="$2"
    local forced_filename="$3"
    local model_id=""
    
    if [[ $url =~ /models/([0-9]+) ]]; then
        model_id="${BASH_REMATCH[1]}"
    else
        printf "ERROR: Could not extract model ID from URL\n"
        return 1
    fi
    
    printf "Downloading CivitAI model %s...\n" "$model_id"

    if [[ -n "$forced_filename" ]]; then
        local output_file="${output_dir}/${forced_filename}"
        if [[ -f "$output_file" ]]; then
            printf "File already exists: %s\n" "$forced_filename"
            return 0
        fi
        printf "Downloading to: %s\n" "$forced_filename"
        if [[ -n "$CIVITAI_TOKEN" ]]; then
            curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
        else
            curl -L -o "$output_file" --progress-bar "$url"
        fi
        if [[ $? -eq 0 ]]; then
            printf "Download completed: %s\n" "$forced_filename"
            return 0
        else
            printf "ERROR: Download failed for model %s\n" "$model_id"
            return 1
        fi
    fi
    
    local redirect_url=""
    if [[ -n "$CIVITAI_TOKEN" ]]; then
        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')
    else
        redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
    fi
    
    if [[ -z "$redirect_url" ]]; then
        printf "ERROR: Could not get redirect URL for model %s\n" "$model_id"
        return 1
    fi
    
    local filename=""
    
    if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
        filename="${BASH_REMATCH[1]}"
        filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
    elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
        filename="${BASH_REMATCH[1]}"
    elif [[ $redirect_url =~ filename=([^&]+) ]]; then
        filename="${BASH_REMATCH[1]}"
    else
        local path_part=$(echo "$redirect_url" | sed 's/?.*//')
        filename=$(basename "$path_part")
        if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
            filename="${filename}.safetensors"
        fi
    fi
    
    filename=$(printf '%b' "${filename//%/\\x}")
    
    if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
        filename="civitai_${model_id}.safetensors"
    fi
    
    local output_file="${output_dir}/${filename}"
    
    if [[ -f "$output_file" ]]; then
        printf "File already exists: %s\n" "$filename"
        return 0
    fi
    
    printf "Downloading to: %s\n" "$filename"
    curl -L -o "$output_file" --progress-bar "$redirect_url"
    
    if [[ $? -eq 0 ]]; then
        printf "Download completed: %s\n" "$filename"
        return 0
    else
        printf "ERROR: Download failed for model %s\n" "$model_id"
        return 1
    fi
}

# Download from $1 URL to $2 file path, with optional $3 forced filename
function provisioning_download() {
    local url="$1"
    local dir="$2"
    local forced_filename="$3"

    if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
        download_civitai_bash "$url" "$dir" "$forced_filename"
    else
        if [[ -n "$forced_filename" ]]; then
            wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
        else
            wget -qnc --content-disposition --show-progress -e dotbytes="${4:-4M}" -P "$dir" "$url"
        fi
    fi
}

# Allow user to disable provisioning if they started with a script they didn't want
if [[ ! -f /.noprovisioning ]]; then
    provisioning_start
fi