File size: 6,682 Bytes
e609fe4 | 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 | #!/usr/bin/env bash
# ============================================================================
# ComfyUI + Krea 2 Identity Edit β one-shot RunPod bootstrap
# Run on a fresh pod: export HF_TOKEN=... CIVITAI_TOKEN=... ; bash comfy_bootstrap.sh
# Safe to re-run: clones are skipped if present, downloads resume.
# ============================================================================
set -euo pipefail
# βββββββββββββββββββββββββββ CONFIG (edit this) ββββββββββββββββββββββββββββ
COMFY_WORKSPACE="/root/comfy" # ComfyUI ends up in $COMFY_WORKSPACE/ComfyUI
COMFY_ROOT="${COMFY_WORKSPACE}/ComfyUI"
MODELS="${COMFY_ROOT}/models"
# Secrets β set these as POD ENV VARS in your RunPod template so you never type them.
: "${HF_TOKEN:?Set HF_TOKEN (accept the Krea-2 license on HF first)}"
: "${CIVITAI_TOKEN:?Set CIVITAI_TOKEN (Civitai > Account > API Keys)}"
export HF_TOKEN # huggingface_hub picks this up automatically
export HF_HUB_ENABLE_HF_TRANSFER=1 # fast large-file transfers
# Manager security (matches the weak + personal_cloud combo you set by hand)
SECURITY_LEVEL="weak"
NETWORK_MODE="personal_cloud"
# HuggingFace models: "repo|path_in_repo|local_dir"
# Comfy-Org/Krea-2's folder layout mirrors models/, so --local-dir $MODELS drops
# each file into the correct subfolder automatically.
HF_MODELS=(
"Comfy-Org/Krea-2|diffusion_models/krea2_turbo_fp8_scaled.safetensors|${MODELS}"
"Comfy-Org/Krea-2|text_encoders/qwen3vl_4b_fp8_scaled.safetensors|${MODELS}"
"Comfy-Org/Krea-2|vae/qwen_image_vae.safetensors|${MODELS}"
"conradlocke/krea2-identity-edit|krea2_identity_edit_v1_2.safetensors|${MODELS}/loras/Krea2"
"lodestones/Kroma|kroma-v0.2-turbo.safetensors|${MODELS}/diffusion_models"
)
# Custom nodes (git repos). Requirements auto-installed if a requirements.txt exists.
CUSTOM_NODES=(
"https://github.com/lbouaraba/comfyui-krea2edit" # Krea 2 Identity Edit nodes (required)
"https://github.com/rgthree/rgthree-comfy" # Power Lora Loader
)
# Civitai downloads: "versionId|target_subdir_under_models"
# Use the *version* id (the number in the /api/download/models/<id> URL, or the
# "Model Version ID" on the page). Fill in your own list here.
CIVITAI_ITEMS=(
"3220691|loras"
"3112728|diffusion_models"
"3223899|diffusion_models"
"3221218|loras"
"3139241|diffusion_models"
"3231611|diffusion_models"
"3292830|diffusion_models"
"3130045|loras"
"3192618|loras"
"3121642|loras"
)
# Optional: a workflow JSON to drop into the UI's workflow list.
# Either a raw URL (gist/HF) or leave empty and copy it in manually.
WORKFLOW_URL="" # e.g. "https://gist.githubusercontent.com/you/xxx/raw/krea2_identity_edit.json"
# ββββββββββββββββββββββββββ END CONFIG βββββββββββββββββββββββββββββββββββββ
log() { echo -e "\n\033[1;36mβΆ $*\033[0m"; }
# 1. System + Python deps ----------------------------------------------------
log "Installing base tooling"
apt-get update -qq && apt-get install -y -qq git aria2 wget >/dev/null 2>&1 || true
pip install -q -U comfy-cli "huggingface_hub[hf_transfer]" hf_transfer
# 2. ComfyUI + Manager (non-interactive) -------------------------------------
if [[ ! -d "${COMFY_ROOT}" ]]; then
log "Installing ComfyUI into ${COMFY_ROOT}"
comfy --skip-prompt --workspace "${COMFY_ROOT}" install --nvidia --fast-deps
else
log "ComfyUI already present β skipping install"
fi
comfy set-default "${COMFY_ROOT}" >/dev/null 2>&1 || true
# 3. Pre-seed ComfyUI-Manager config.ini (weak + personal_cloud) -------------
log "Setting Manager security=${SECURITY_LEVEL}, network_mode=${NETWORK_MODE}"
CFG_DIR="${COMFY_ROOT}/user/default/ComfyUI-Manager"
mkdir -p "${CFG_DIR}"
CFG="${CFG_DIR}/config.ini"
if [[ -f "${CFG}" ]]; then
# Update existing keys in place; append if missing.
grep -q '^security_level' "${CFG}" && sed -i "s|^security_level.*|security_level = ${SECURITY_LEVEL}|" "${CFG}" || echo "security_level = ${SECURITY_LEVEL}" >> "${CFG}"
grep -q '^network_mode' "${CFG}" && sed -i "s|^network_mode.*|network_mode = ${NETWORK_MODE}|" "${CFG}" || echo "network_mode = ${NETWORK_MODE}" >> "${CFG}"
else
printf '[default]\nsecurity_level = %s\nnetwork_mode = %s\n' "${SECURITY_LEVEL}" "${NETWORK_MODE}" > "${CFG}"
fi
# 4. Custom nodes ------------------------------------------------------------
log "Installing custom nodes"
cd "${COMFY_ROOT}/custom_nodes"
for repo in "${CUSTOM_NODES[@]}"; do
name="$(basename "${repo}")"
if [[ -d "${name}" ]]; then
echo " ${name} exists β git pull"
git -C "${name}" pull --ff-only || true
else
echo " cloning ${name}"
git clone --depth 1 "${repo}"
fi
[[ -f "${name}/requirements.txt" ]] && pip install -q -r "${name}/requirements.txt" || true
done
# 5. HuggingFace models ------------------------------------------------------
log "Downloading HuggingFace models"
for entry in "${HF_MODELS[@]}"; do
IFS='|' read -r repo path dir <<< "${entry}"
echo " ${repo} :: ${path}"
hf download "${repo}" "${path}" --local-dir "${dir}"
done
# 6. Civitai downloads -------------------------------------------------------
if [[ ${#CIVITAI_ITEMS[@]} -gt 0 ]]; then
log "Downloading Civitai models"
for entry in "${CIVITAI_ITEMS[@]}"; do
IFS='|' read -r vid subdir <<< "${entry}"
dest="${MODELS}/${subdir}"; mkdir -p "${dest}"
echo " version ${vid} -> ${subdir}"
# aria2 is faster on big files; --content-disposition keeps Civitai's real filename.
aria2c -c -x8 -s8 --content-disposition -d "${dest}" \
"https://civitai.red/api/download/models/${vid}?token=${CIVITAI_TOKEN}" \
|| wget -c --content-disposition -P "${dest}" \
"https://civitai.red/api/download/models/${vid}?token=${CIVITAI_TOKEN}"
done
else
log "No Civitai items configured β skipping"
fi
# 7. Workflow JSON -----------------------------------------------------------
if [[ -n "${WORKFLOW_URL}" ]]; then
log "Installing workflow"
WF_DIR="${COMFY_ROOT}/user/default/workflows"; mkdir -p "${WF_DIR}"
wget -q -O "${WF_DIR}/$(basename "${WORKFLOW_URL%%\?*}")" "${WORKFLOW_URL}"
fi
# 8. Launch ------------------------------------------------------------------
log "Launching ComfyUI on :8188"
comfy launch --background -- --listen 127.0.0.1 --port 8188
echo -e "\n\033[1;32mβ
Done. Open the pod's :8188 proxy URL. Re-run this script anytime to update.\033[0m"
|