Last active
October 9, 2025 10:18
-
-
Save hungngocphat01/4d87739e5d291d4e1346baf11d719b2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| source /venv/main/bin/activate | |
| FORGE_DIR=${WORKSPACE}/stable-diffusion-webui-forge | |
| # Packages are installed after nodes so we can fix them... | |
| APT_PACKAGES=( | |
| #"package-1" | |
| #"package-2" | |
| ) | |
| PIP_PACKAGES=( | |
| "magic-wormhole" | |
| ) | |
| CHECKPOINT_MODELS=( | |
| # "https://civitai.com/api/download/models/1116447?type=Model&format=SafeTensor&size=full&fp=bf16&token=$TOKEN" # nai | |
| # "https://civitai.com/api/download/models/1136462?type=Model&format=SafeTensor&size=pruned&fp=fp16&token=$TOKEN" # obsession | |
| "https://civitai.com/api/download/models/1761560?type=Model&format=SafeTensor&size=pruned&fp=fp16&token=$TOKEN" # wai | |
| ) | |
| UNET_MODELS=( | |
| ) | |
| LORA_MODELS=( | |
| ) | |
| VAE_MODELS=( | |
| ) | |
| ESRGAN_MODELS=( | |
| ) | |
| CONTROLNET_MODELS=( | |
| ) | |
| EXTENSIONS=( | |
| "https://github.com/Mikubill/sd-webui-controlnet" | |
| "https://github.com/hako-mikan/sd-webui-regional-prompter" | |
| "https://github.com/Coyote-A/ultimate-upscale-for-automatic1111" | |
| "https://github.com/oaf40/sd-webui-inpaint-mask-tools" | |
| "https://github.com/zanllp/sd-webui-infinite-image-browsing" | |
| "https://github.com/AlUlkesh/stable-diffusion-webui-images-browser" | |
| "https://github.com/Bing-su/adetailer" | |
| ) | |
| CHECKPOINT_DETECT=( | |
| "https://civitai.com/api/download/models/1863248?type=Archive&format=Other&token=$TOKEN" | |
| ) | |
| ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ### | |
| function provisioning_start() { | |
| provisioning_print_header | |
| provisioning_get_pip_packages | |
| provisioning_get_apt_packages | |
| provisioning_get_extensions | |
| provisioning_get_loras | |
| provisioning_get_detectors | |
| provisioning_get_files \ | |
| "${FORGE_DIR}/models/Stable-diffusion" \ | |
| "${CHECKPOINT_MODELS[@]}" | |
| # Avoid git errors because we run as root but files are owned by 'user' | |
| export GIT_CONFIG_GLOBAL=/tmp/temporary-git-config | |
| git config --file $GIT_CONFIG_GLOBAL --add safe.directory '*' | |
| # Start and exit because webui will probably require a restart | |
| cd "${FORGE_DIR}" | |
| LD_PRELOAD=libtcmalloc_minimal.so.4 \ | |
| python launch.py \ | |
| --skip-python-version-check \ | |
| --no-download-sd-model \ | |
| --do-not-download-clip \ | |
| --no-half \ | |
| --port 11404 \ | |
| --exit | |
| 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_extensions() { | |
| for repo in "${EXTENSIONS[@]}"; do | |
| dir="${repo##*/}" | |
| path="${FORGE_DIR}/extensions/${dir}" | |
| if [[ ! -d $path ]]; then | |
| printf "Downloading extension: %s...\n" "${repo}" | |
| git clone "${repo}" "${path}" --recursive | |
| 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 url in "${arr[@]}"; do | |
| printf "Downloading: %s\n" "${url}" | |
| provisioning_download "${url}" "${dir}" | |
| 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") | |
| # Check if the token is valid | |
| 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") | |
| # Check if the token is valid | |
| if [ "$response" -eq 200 ]; then | |
| return 0 | |
| else | |
| return 1 | |
| fi | |
| } | |
| # Download from $1 URL to $2 file path | |
| function provisioning_download() { | |
| if [[ -n $HF_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?huggingface\.co(/|$|\?) ]]; then | |
| auth_token="$HF_TOKEN" | |
| elif | |
| [[ -n $CIVITAI_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?civitai\.com(/|$|\?) ]]; then | |
| auth_token="$CIVITAI_TOKEN" | |
| fi | |
| if [[ -n $auth_token ]];then | |
| wget --header="Authorization: Bearer $auth_token" -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1" | |
| else | |
| wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1" | |
| fi | |
| } | |
| function provisioning_get_detectors() { | |
| provisioning_get_files \ | |
| "${FORGE_DIR}/models/adetailer" \ | |
| "${CHECKPOINT_DETECT[@]}" | |
| for z in "${FORGE_DIR}/models/adetailer"/*.zip; do | |
| unzip -o -d "${FORGE_DIR}/models/adetailer" "$z"; | |
| done | |
| } | |
| function provisioning_get_loras() { | |
| if [[ -v LORAS ]]; then | |
| URLS=($(for id in $LORAS; do echo "https://civitai.com/api/download/models/$id?type=Model&format=SafeTensor&token=$TOKEN"; done)) | |
| printf "%s\n" "${URLS[@]}" | |
| provisioning_get_files \ | |
| "${FORGE_DIR}/models/Lora" \ | |
| "${URLS[@]}" | |
| else | |
| echo "LORAS environment variable not specified" | |
| fi | |
| } | |
| # Allow user to disable provisioning if they started with a script they didn't want | |
| if [[ ! -f /.noprovisioning ]]; then | |
| provisioning_start | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment