Update script.sh
Browse files
script.sh
CHANGED
|
@@ -8,6 +8,12 @@ export GIT_TERMINAL_PROMPT=0
|
|
| 8 |
source /venv/main/bin/activate
|
| 9 |
COMFYUI_DIR="${WORKSPACE:-/workspace}/ComfyUI"
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
NODES=(
|
| 12 |
"https://github.com/ltdrdata/ComfyUI-Impact-Pack.git"
|
| 13 |
"https://github.com/ltdrdata/ComfyUI-Impact-Subpack.git"
|
|
@@ -45,139 +51,58 @@ WORKFLOWS=(
|
|
| 45 |
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/Single_Posture.json"
|
| 46 |
)
|
| 47 |
|
| 48 |
-
PREINSTALLED_PACKAGES=( "torch" "torchvision" "torchaudio" "numpy" "pillow" "pyyaml" "tqdm" "requests" "opencv-python" "scipy" )
|
| 49 |
log_info() { echo "--> $1"; }
|
| 50 |
log_warn() { echo " ⚠️ $1"; }
|
| 51 |
log_error() { echo " ❌ $1"; }
|
| 52 |
log_success() { echo " ✅ $1"; }
|
| 53 |
log_step() { echo ""; echo "=== [Step $1] $2 ==="; }
|
|
|
|
| 54 |
package_installed() { $PYTHON_BIN -c "import $1" 2>/dev/null && return 0 || return 1; }
|
| 55 |
filter_requirements() { local req_file="$1"; local tmp_file="${req_file}.filtered"; > "$tmp_file"; while IFS= read -r line; do [[ -z "$line" || "$line" =~ ^# ]] && continue; local pkg_name; pkg_name=$(echo "$line" | sed 's/[<>=!].*//' | xargs); if [[ -z "$pkg_name" ]]; then continue; fi; local module_name="${pkg_name//-/_}"; if package_installed "$module_name"; then log_info "跳過已安裝套件: $pkg_name"; else echo "$line" >> "$tmp_file"; fi; done < "$req_file"; if [ -s "$tmp_file" ]; then mv "$tmp_file" "$req_file"; return 0; else rm -f "$tmp_file"; log_info "所有套件都已安裝"; return 1; fi; }
|
| 56 |
-
if [ -f "/workspace/.provision_complete" ]; then log_success "環境已配置,跳過重複執行"; log_info "如需重新配置,請刪除 /workspace/.provision_complete"; exit 0; fi
|
| 57 |
-
if [[ -f /.noprovisioning ]]; then log_warn "檢測到 /.noprovisioning 文件,跳過配置"; exit 0; fi
|
| 58 |
-
if [ -f "/venv/main/bin/python" ]; then PYTHON_BIN="/venv/main/bin/python"; PIP_BIN="/venv/main/bin/pip"; else PYTHON_BIN="python3"; PIP_BIN="pip3"; fi
|
| 59 |
provisioning_has_valid_hf_token() { [[ -n "${HF_TOKEN:-}" ]] || return 1; local response; response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://huggingface.co/api/whoami-v2" -H "Authorization: Bearer $HF_TOKEN" -H "Content-Type: application/json"); [ "$response" -eq 200 ]; }
|
| 60 |
provisioning_has_valid_civitai_token() { [[ -n "${CIVITAI_TOKEN:-}" ]] || return 1; local response; response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://civitai.com/api/v1/models?hidden=1&limit=1" -H "Authorization: Bearer $CIVITAI_TOKEN" -H "Content-Type: application/json"); [ "$response" -eq 200 ]; }
|
| 61 |
install_node() { local repo_url="$1"; local branch_name="${2:-}"; local repo_name; repo_name=$(basename "$repo_url" .git); local install_path="${COMFYUI_DIR}/custom_nodes/${repo_name}"; if [ -d "$install_path" ]; then if [[ "${AUTO_UPDATE:-true}" != "false" ]]; then log_info "更新節點: $repo_name"; (cd "$install_path" && git pull -q 2>&1 | grep -v "Already up to date" || true); else log_info "'$repo_name' 已存在,跳過"; return; fi; else log_info "克隆節點: $repo_name"; if [ -n "$branch_name" ]; then git clone --depth 1 --single-branch --branch "$branch_name" "$repo_url" "$install_path" -q 2>&1 || true; else git clone --depth 1 --single-branch "$repo_url" "$install_path" -q 2>&1 || true; fi; fi; if [ -f "$install_path/requirements.txt" ]; then log_info "處理 $repo_name 的依賴..."; sed -i -e '/^torch/d' -e '/^sam2/d' "$install_path/requirements.txt" 2>/dev/null || true; if filter_requirements "$install_path/requirements.txt"; then log_info "安裝 $repo_name 的新依賴..."; $PIP_BIN install -q --no-cache-dir -r "$install_path/requirements.txt" 2>&1 | grep -v "Requirement already satisfied" || log_warn "部分依賴安裝失敗"; fi; fi; if [ -f "$install_path/install.py" ]; then log_info "運行 $repo_name 的安裝腳本..."; $PYTHON_BIN "$install_path/install.py" 2>&1 || log_warn "安裝腳本執行失敗"; fi; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
log_info "檔案 '$filename' 已存在且完整,跳過下載"
|
| 74 |
-
return 0
|
| 75 |
-
fi
|
| 76 |
-
|
| 77 |
-
log_info "下載: $filename"
|
| 78 |
-
|
| 79 |
-
local max_retries=3
|
| 80 |
-
local attempt=0
|
| 81 |
-
local auth_header=""
|
| 82 |
-
local success=1
|
| 83 |
-
|
| 84 |
-
if [[ "$url" =~ huggingface\.co ]] && provisioning_has_valid_hf_token; then
|
| 85 |
-
auth_header="Authorization: Bearer $HF_TOKEN"
|
| 86 |
-
log_info "使用 HuggingFace Token"
|
| 87 |
-
elif [[ "$url" =~ civitai\.com ]] && provisioning_has_valid_civitai_token; then
|
| 88 |
-
auth_header="Authorization: Bearer $CIVITAI_TOKEN"
|
| 89 |
-
log_info "使用 CivitAI Token"
|
| 90 |
-
fi
|
| 91 |
-
|
| 92 |
-
while [ "$attempt" -lt "$max_retries" ]; do
|
| 93 |
-
attempt=$((attempt + 1))
|
| 94 |
-
[ "$attempt" -gt 1 ] && sleep 10
|
| 95 |
-
|
| 96 |
-
if command -v aria2c >/dev/null 2>&1; then
|
| 97 |
-
log_info "使用 aria2c (3 線程) 下載: $filename (嘗試 $attempt/$max_retries)"
|
| 98 |
-
local aria_opts=(
|
| 99 |
-
--console-log-level=error -c -x 3 -s 3 -k 1M
|
| 100 |
-
--max-connection-per-server=3 --max-tries=3 --retry-wait=5
|
| 101 |
-
--timeout=180 --file-allocation=falloc --auto-file-renaming=false
|
| 102 |
-
-d "$(dirname "$dest_path")" -o "${filename}.tmp"
|
| 103 |
-
)
|
| 104 |
-
[[ -n "$auth_header" ]] && aria_opts+=(--header="$auth_header")
|
| 105 |
-
|
| 106 |
-
aria2c "${aria_opts[@]}" "$url"
|
| 107 |
-
if [ $? -eq 0 ]; then
|
| 108 |
-
success=0
|
| 109 |
-
break
|
| 110 |
fi
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
--
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
wget "${wget_opts[@]}" "$url"
|
| 120 |
-
if [ $? -eq 0 ]; then
|
| 121 |
-
success=0
|
| 122 |
-
break
|
| 123 |
fi
|
| 124 |
fi
|
| 125 |
-
done
|
| 126 |
-
|
| 127 |
-
if [ "$success" -eq 0 ] && [ -s "$tmp_path" ]; then
|
| 128 |
-
mv "$tmp_path" "$dest_path"
|
| 129 |
-
log_success "下載完成: $filename"
|
| 130 |
-
return 0
|
| 131 |
-
else
|
| 132 |
-
log_error "下載失敗: $filename"
|
| 133 |
-
rm -f "$tmp_path"
|
| 134 |
-
return 1
|
| 135 |
fi
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
log_info "下載 ${#urls[@]} 個文件到 $dest_dir"
|
| 143 |
-
local MAX_PARALLEL=3
|
| 144 |
-
for url in "${urls[@]}"; do
|
| 145 |
-
while [ $(jobs -r | wc -l) -ge $MAX_PARALLEL ]; do sleep 1; done
|
| 146 |
-
local filename; filename=$(basename "$url" | sed 's/?.*//')
|
| 147 |
-
download_file "${dest_dir}/${filename}" "$url" &
|
| 148 |
-
done
|
| 149 |
-
wait
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
verify_and_retry_downloads() {
|
| 153 |
-
local dest_dir="$1"; shift; local urls=("$@")
|
| 154 |
-
if [ ${#urls[@]} -eq 0 ]; then return 0; fi
|
| 155 |
-
log_info "檢查 $dest_dir 中的文件..."
|
| 156 |
-
|
| 157 |
-
local missing_files=()
|
| 158 |
-
for url in "${urls[@]}"; do
|
| 159 |
-
local filename; filename=$(basename "$url" | sed 's/?.*//')
|
| 160 |
-
local dest_path="${dest_dir}/${filename}"
|
| 161 |
-
|
| 162 |
-
if [ ! -s "$dest_path" ]; then
|
| 163 |
-
log_warn "檔案缺失或不完整: $filename"
|
| 164 |
-
missing_files+=("$url")
|
| 165 |
fi
|
| 166 |
-
done
|
| 167 |
-
|
| 168 |
-
if [ ${#missing_files[@]} -gt 0 ]; then
|
| 169 |
-
log_warn "發現 ${#missing_files[@]} 個缺失/不完整文件,重新下載..."
|
| 170 |
-
download_to_directory "$dest_dir" "${missing_files[@]}"
|
| 171 |
else
|
| 172 |
-
|
| 173 |
fi
|
| 174 |
}
|
| 175 |
|
| 176 |
-
provisioning_print_header() { echo ""; echo "##############################################"; echo "# #"; echo "# Provisioning Container #"; echo "# #"; echo "# This will take some time #"; echo "# #"; echo "##############################################"; echo ""; }
|
| 177 |
-
provisioning_print_end() { echo ""; echo "##############################################"; echo "# #"; echo "# Provisioning Complete! #"; echo "# #"; echo "# Total time: $((END_TIME - START_TIME)) seconds"; echo "# #"; echo "##############################################"; echo ""; }
|
| 178 |
-
|
| 179 |
provisioning_step2_nodes() {
|
| 180 |
-
log_step "2" "安裝節點與套件"
|
| 181 |
if [ ${#NODES[@]} -gt 0 ]; then
|
| 182 |
cd "${COMFYUI_DIR}/custom_nodes" || exit 1
|
| 183 |
log_info "並行安裝 ${#NODES[@]} 個節點..."
|
|
@@ -190,14 +115,17 @@ provisioning_step2_nodes() {
|
|
| 190 |
log_success "節點安裝完成"
|
| 191 |
cd "${COMFYUI_DIR}" || exit 1
|
| 192 |
fi
|
| 193 |
-
if [ ${#PIP_PACKAGES[@]
|
| 194 |
log_info "檢查並安裝額外的 Python 套件..."
|
| 195 |
local packages_to_install=()
|
| 196 |
for pkg in "${PIP_PACKAGES[@]}"; do
|
| 197 |
local pkg_name="${pkg/[<>=!].*/}"; local module_name="${pkg_name//-/_}"
|
| 198 |
if package_installed "$module_name"; then log_info "跳過已安裝套件: $pkg_name"; else packages_to_install+=("$pkg"); fi
|
| 199 |
done
|
| 200 |
-
if [ ${#packages_to_install[@]} -gt 0 ]; then
|
|
|
|
|
|
|
|
|
|
| 201 |
fi
|
| 202 |
}
|
| 203 |
|
|
@@ -215,22 +143,15 @@ provisioning_step3_downloads() {
|
|
| 215 |
fi
|
| 216 |
}
|
| 217 |
|
|
|
|
|
|
|
|
|
|
| 218 |
START_TIME=$(date +%s)
|
| 219 |
log_info "開始時間: $(date)"
|
| 220 |
provisioning_print_header
|
| 221 |
cd "${COMFYUI_DIR}" || exit 1
|
| 222 |
|
| 223 |
-
|
| 224 |
-
if ! command -v aria2c >/dev/null 2>&1; then
|
| 225 |
-
log_info "aria2 未安裝,開始安裝..."
|
| 226 |
-
if command -v sudo &>/dev/null && sudo -n true 2>/dev/null; then
|
| 227 |
-
sudo apt-get update -qq && sudo apt-get install -y -qq aria2 && log_success "aria2 安裝完成" || log_warn "aria2 安裝失敗"
|
| 228 |
-
else
|
| 229 |
-
log_warn "無 sudo 權限,無法安裝 aria2 (下載將使用 wget 備用)"
|
| 230 |
-
fi
|
| 231 |
-
else
|
| 232 |
-
log_success "aria2 已安裝,跳過"
|
| 233 |
-
fi
|
| 234 |
|
| 235 |
provisioning_step2_nodes &
|
| 236 |
NODE_PID=$!
|
|
|
|
| 8 |
source /venv/main/bin/activate
|
| 9 |
COMFYUI_DIR="${WORKSPACE:-/workspace}/ComfyUI"
|
| 10 |
|
| 11 |
+
APT_PACKAGES=(
|
| 12 |
+
"aria2"
|
| 13 |
+
)
|
| 14 |
+
PIP_PACKAGES=(
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
NODES=(
|
| 18 |
"https://github.com/ltdrdata/ComfyUI-Impact-Pack.git"
|
| 19 |
"https://github.com/ltdrdata/ComfyUI-Impact-Subpack.git"
|
|
|
|
| 51 |
"https://huggingface.co/JCscrew/RisuAI_asset_generator/resolve/main/Single_Posture.json"
|
| 52 |
)
|
| 53 |
|
|
|
|
| 54 |
log_info() { echo "--> $1"; }
|
| 55 |
log_warn() { echo " ⚠️ $1"; }
|
| 56 |
log_error() { echo " ❌ $1"; }
|
| 57 |
log_success() { echo " ✅ $1"; }
|
| 58 |
log_step() { echo ""; echo "=== [Step $1] $2 ==="; }
|
| 59 |
+
if [ -f "/venv/main/bin/python" ]; then PYTHON_BIN="/venv/main/bin/python"; PIP_BIN="/venv/main/bin/pip"; else PYTHON_BIN="python3"; PIP_BIN="pip3"; fi
|
| 60 |
package_installed() { $PYTHON_BIN -c "import $1" 2>/dev/null && return 0 || return 1; }
|
| 61 |
filter_requirements() { local req_file="$1"; local tmp_file="${req_file}.filtered"; > "$tmp_file"; while IFS= read -r line; do [[ -z "$line" || "$line" =~ ^# ]] && continue; local pkg_name; pkg_name=$(echo "$line" | sed 's/[<>=!].*//' | xargs); if [[ -z "$pkg_name" ]]; then continue; fi; local module_name="${pkg_name//-/_}"; if package_installed "$module_name"; then log_info "跳過已安裝套件: $pkg_name"; else echo "$line" >> "$tmp_file"; fi; done < "$req_file"; if [ -s "$tmp_file" ]; then mv "$tmp_file" "$req_file"; return 0; else rm -f "$tmp_file"; log_info "所有套件都已安裝"; return 1; fi; }
|
|
|
|
|
|
|
|
|
|
| 62 |
provisioning_has_valid_hf_token() { [[ -n "${HF_TOKEN:-}" ]] || return 1; local response; response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://huggingface.co/api/whoami-v2" -H "Authorization: Bearer $HF_TOKEN" -H "Content-Type: application/json"); [ "$response" -eq 200 ]; }
|
| 63 |
provisioning_has_valid_civitai_token() { [[ -n "${CIVITAI_TOKEN:-}" ]] || return 1; local response; response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "https://civitai.com/api/v1/models?hidden=1&limit=1" -H "Authorization: Bearer $CIVITAI_TOKEN" -H "Content-Type: application/json"); [ "$response" -eq 200 ]; }
|
| 64 |
install_node() { local repo_url="$1"; local branch_name="${2:-}"; local repo_name; repo_name=$(basename "$repo_url" .git); local install_path="${COMFYUI_DIR}/custom_nodes/${repo_name}"; if [ -d "$install_path" ]; then if [[ "${AUTO_UPDATE:-true}" != "false" ]]; then log_info "更新節點: $repo_name"; (cd "$install_path" && git pull -q 2>&1 | grep -v "Already up to date" || true); else log_info "'$repo_name' 已存在,跳過"; return; fi; else log_info "克隆節點: $repo_name"; if [ -n "$branch_name" ]; then git clone --depth 1 --single-branch --branch "$branch_name" "$repo_url" "$install_path" -q 2>&1 || true; else git clone --depth 1 --single-branch "$repo_url" "$install_path" -q 2>&1 || true; fi; fi; if [ -f "$install_path/requirements.txt" ]; then log_info "處理 $repo_name 的依賴..."; sed -i -e '/^torch/d' -e '/^sam2/d' "$install_path/requirements.txt" 2>/dev/null || true; if filter_requirements "$install_path/requirements.txt"; then log_info "安裝 $repo_name 的新依賴..."; $PIP_BIN install -q --no-cache-dir -r "$install_path/requirements.txt" 2>&1 | grep -v "Requirement already satisfied" || log_warn "部分依賴安裝失敗"; fi; fi; if [ -f "$install_path/install.py" ]; then log_info "運行 $repo_name 的安裝腳本..."; $PYTHON_BIN "$install_path/install.py" 2>&1 || log_warn "安裝腳本執行失敗"; fi; }
|
| 65 |
+
download_file() { local dest_path="$1"; local url="$2"; local filename; filename=$(basename "$dest_path"); local tmp_path="${dest_path}.tmp"; mkdir -p "$(dirname "$dest_path")"; if [ -s "$dest_path" ]; then log_info "檔案 '$filename' 已存在且完整,跳過下載"; return 0; fi; log_info "下載: $filename"; local max_retries=3; local attempt=0; local auth_header=""; local success=1; if [[ "$url" =~ huggingface\.co ]] && provisioning_has_valid_hf_token; then auth_header="Authorization: Bearer $HF_TOKEN"; log_info "使用 HuggingFace Token"; elif [[ "$url" =~ civitai\.com ]] && provisioning_has_valid_civitai_token; then auth_header="Authorization: Bearer $CIVITAI_TOKEN"; log_info "使用 CivitAI Token"; fi; while [ "$attempt" -lt "$max_retries" ]; do attempt=$((attempt + 1)); [ "$attempt" -gt 1 ] && sleep 10; if command -v aria2c >/dev/null 2>&1; then log_info "使用 aria2c (3 線程) 下載: $filename (嘗試 $attempt/$max_retries)"; local aria_opts=( --console-log-level=error -c -x 3 -s 3 -k 1M --max-connection-per-server=3 --max-tries=3 --retry-wait=5 --timeout=180 --file-allocation=falloc --auto-file-renaming=false -d "$(dirname "$dest_path")" -o "${filename}.tmp" ); [[ -n "$auth_header" ]] && aria_opts+=(--header="$auth_header"); aria2c "${aria_opts[@]}" "$url"; if [ $? -eq 0 ]; then success=0; break; fi; else log_info "使用 wget 下載: $filename (嘗試 $attempt/$max_retries)"; local wget_opts=( -O "$tmp_path" -c --timeout=60 --tries=3 --content-disposition --show-progress ); [[ -n "$auth_header" ]] && wget_opts+=(--header="$auth_header"); wget "${wget_opts[@]}" "$url"; if [ $? -eq 0 ]; then success=0; break; fi; fi; done; if [ "$success" -eq 0 ] && [ -s "$tmp_path" ]; then mv "$tmp_path" "$dest_path"; log_success "下載完成: $filename"; return 0; else log_error "下載失敗: $filename"; rm -f "$tmp_path"; return 1; fi; }
|
| 66 |
+
download_to_directory() { local dest_dir="$1"; shift; local urls=("$@"); if [ ${#urls[@]} -eq 0 ]; then return 0; fi; mkdir -p "$dest_dir"; log_info "下載 ${#urls[@]} 個文件到 $dest_dir"; local MAX_PARALLEL=3; for url in "${urls[@]}"; do while [ $(jobs -r | wc -l) -ge $MAX_PARALLEL ]; do sleep 1; done; local filename; filename=$(basename "$url" | sed 's/?.*//'); download_file "${dest_dir}/${filename}" "$url" &; done; wait; }
|
| 67 |
+
verify_and_retry_downloads() { local dest_dir="$1"; shift; local urls=("$@"); if [ ${#urls[@]} -eq 0 ]; then return 0; fi; log_info "檢查 $dest_dir 中的文件..."; local missing_files=(); for url in "${urls[@]}"; do local filename; filename=$(basename "$url" | sed 's/?.*//'); local dest_path="${dest_dir}/${filename}"; if [ ! -s "$dest_path" ]; then log_warn "檔案缺失或不完整: $filename"; missing_files+=("$url"); fi; done; if [ ${#missing_files[@]} -gt 0 ]; then log_warn "發現 ${#missing_files[@]} 個缺失/不完整文件,重新下載..."; download_to_directory "$dest_dir" "${missing_files[@]}"; else log_success "所有文件已確認存在且完整"; fi; }
|
| 68 |
+
provisioning_print_header() { echo ""; echo "##############################################"; echo "# #"; echo "# Provisioning Container #"; echo "# #"; echo "# This will take some time #"; echo "# #"; echo "##############################################"; echo ""; }
|
| 69 |
+
provisioning_print_end() { echo ""; echo "##############################################"; echo "# #"; echo "# Provisioning Complete! #"; echo "# #"; echo "# Total time: $((END_TIME - START_TIME)) seconds"; echo "# #"; echo "##############################################"; echo ""; }
|
| 70 |
|
| 71 |
+
provisioning_step1_install_core_deps() {
|
| 72 |
+
log_step "1" "安裝系統與 ComfyUI 核心依賴"
|
| 73 |
+
if [ ${#APT_PACKAGES[@]} -gt 0 ]; then
|
| 74 |
+
log_info "準備安裝 ${#APT_PACKAGES[@]} 個系統套件..."
|
| 75 |
+
local packages_to_install=()
|
| 76 |
+
for pkg in "${APT_PACKAGES[@]}"; do
|
| 77 |
+
if ! dpkg -s "$pkg" >/dev/null 2>&1; then
|
| 78 |
+
packages_to_install+=("$pkg")
|
| 79 |
+
else
|
| 80 |
+
log_success "$pkg 已安裝,跳過"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
fi
|
| 82 |
+
done
|
| 83 |
+
if [ ${#packages_to_install[@]} -gt 0 ]; then
|
| 84 |
+
log_info "正在安裝: ${packages_to_install[*]}"
|
| 85 |
+
if command -v sudo &>/dev/null && sudo -n true 2>/dev/null; then
|
| 86 |
+
sudo apt-get update -qq && sudo apt-get install -y -qq "${packages_to_install[@]}" && log_success "系統套件安裝完成" || log_warn "部分系統套件安裝失敗"
|
| 87 |
+
else
|
| 88 |
+
log_warn "無 sudo 權限,無法安裝系統套件"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
fi
|
| 90 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
fi
|
| 92 |
+
local comfyui_req_file="${COMFYUI_DIR}/requirements.txt"
|
| 93 |
+
if [ -f "$comfyui_req_file" ]; then
|
| 94 |
+
log_info "處理 ComfyUI 核心依賴: $comfyui_req_file"
|
| 95 |
+
if filter_requirements "$comfyui_req_file"; then
|
| 96 |
+
log_info "安裝 ComfyUI 的新依賴..."
|
| 97 |
+
$PIP_BIN install -q --no-cache-dir -r "$comfyui_req_file" 2>&1 | grep -v "Requirement already satisfied" || log_warn "ComfyUI 部分核心依賴安裝失敗"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
else
|
| 100 |
+
log_warn "找不到 ComfyUI 的核心 requirements.txt 文件!"
|
| 101 |
fi
|
| 102 |
}
|
| 103 |
|
|
|
|
|
|
|
|
|
|
| 104 |
provisioning_step2_nodes() {
|
| 105 |
+
log_step "2" "安裝節點與額外套件"
|
| 106 |
if [ ${#NODES[@]} -gt 0 ]; then
|
| 107 |
cd "${COMFYUI_DIR}/custom_nodes" || exit 1
|
| 108 |
log_info "並行安裝 ${#NODES[@]} 個節點..."
|
|
|
|
| 115 |
log_success "節點安裝完成"
|
| 116 |
cd "${COMFYUI_DIR}" || exit 1
|
| 117 |
fi
|
| 118 |
+
if [ ${#PIP_PACKAGES[@]} -gt 0 ]; then
|
| 119 |
log_info "檢查並安裝額外的 Python 套件..."
|
| 120 |
local packages_to_install=()
|
| 121 |
for pkg in "${PIP_PACKAGES[@]}"; do
|
| 122 |
local pkg_name="${pkg/[<>=!].*/}"; local module_name="${pkg_name//-/_}"
|
| 123 |
if package_installed "$module_name"; then log_info "跳過已安裝套件: $pkg_name"; else packages_to_install+=("$pkg"); fi
|
| 124 |
done
|
| 125 |
+
if [ ${#packages_to_install[@]} -gt 0 ]; then
|
| 126 |
+
log_info "正在安裝額外套件: ${packages_to_install[*]}"
|
| 127 |
+
$PIP_BIN install -q --no-cache-dir "${packages_to_install[@]}" 2>&1 | grep -v "Requirement already satisfied" || true;
|
| 128 |
+
fi
|
| 129 |
fi
|
| 130 |
}
|
| 131 |
|
|
|
|
| 143 |
fi
|
| 144 |
}
|
| 145 |
|
| 146 |
+
if [ -f "/workspace/.provision_complete" ]; then log_success "環境已配置,跳過重複執行"; log_info "如需重新配置,請刪除 /workspace/.provision_complete"; exit 0; fi
|
| 147 |
+
if [[ -f /.noprovisioning ]]; then log_warn "檢測到 /.noprovisioning 文件,跳過配置"; exit 0; fi
|
| 148 |
+
|
| 149 |
START_TIME=$(date +%s)
|
| 150 |
log_info "開始時間: $(date)"
|
| 151 |
provisioning_print_header
|
| 152 |
cd "${COMFYUI_DIR}" || exit 1
|
| 153 |
|
| 154 |
+
provisioning_step1_install_core_deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
provisioning_step2_nodes &
|
| 157 |
NODE_PID=$!
|