Update wan.sh
Browse files
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 |
-
|
| 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 |
-
provisioning_get_files \
|
| 89 |
-
"${COMFYUI_DIR}/models/
|
| 90 |
-
"${
|
| 91 |
-
provisioning_get_files \
|
| 92 |
-
"${COMFYUI_DIR}/models/
|
| 93 |
-
"${
|
| 94 |
-
provisioning_get_files \
|
| 95 |
-
"${COMFYUI_DIR}/models/
|
| 96 |
-
"${
|
| 97 |
-
provisioning_get_files \
|
| 98 |
-
"${COMFYUI_DIR}/models/
|
| 99 |
-
"${
|
| 100 |
-
provisioning_get_files \
|
| 101 |
-
"${COMFYUI_DIR}/models/
|
| 102 |
-
"${
|
| 103 |
-
provisioning_get_files \
|
| 104 |
-
"${COMFYUI_DIR}/models/
|
| 105 |
-
"${
|
| 106 |
-
provisioning_get_files \
|
| 107 |
-
"${COMFYUI_DIR}/models/
|
| 108 |
-
"${
|
| 109 |
-
provisioning_get_files \
|
| 110 |
-
"${COMFYUI_DIR}/models/
|
| 111 |
-
"${
|
| 112 |
-
provisioning_get_files \
|
| 113 |
-
"${COMFYUI_DIR}/
|
| 114 |
-
"${
|
| 115 |
-
provisioning_get_files \
|
| 116 |
-
"${COMFYUI_DIR}/
|
| 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 |
-
url="$
|
| 171 |
-
filename="
|
| 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 |
-
local
|
| 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 |
-
printf "Download
|
| 250 |
-
return
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
filename="${BASH_REMATCH[1]}"
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
filename="$
|
| 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 |
-
printf "Download
|
| 304 |
-
return
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 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
|