| #!/bin/bash |
| |
| |
| |
| |
| |
| |
|
|
| REPO_ID="aleph65/ComfyUI" |
| TAG="[refresh-workspace]" |
| TOKEN="${HUGGING_FACE_ACCESS_TOKEN:-${HF_TOKEN:-}}" |
|
|
| if [[ "${WORKSPACE_REFRESH:-true}" == "false" ]]; then |
| echo "$TAG disabled via WORKSPACE_REFRESH=false β skipping." |
| exit 0 |
| fi |
| if [[ ! -d /workspace || ! -w /workspace ]]; then |
| echo "$TAG /workspace missing or not writable β skipping." >&2 |
| exit 0 |
| fi |
|
|
| set -u |
|
|
| |
| update_workspace_file() { |
| local name="$1" check="$2" |
| local url="https://huggingface.co/$REPO_ID/resolve/main/$name" |
| local dest="/workspace/$name" |
| local tmp auth=() |
| tmp=$(mktemp) || return 0 |
| [[ -n "$TOKEN" ]] && auth=(-H "Authorization: Bearer $TOKEN") |
| if curl -fsSL --connect-timeout 10 --max-time 60 "${auth[@]}" "$url" -o "$tmp" \ |
| && head -c 2 "$tmp" | grep -q "$check"; then |
| if ! cmp -s "$tmp" "$dest" 2>/dev/null; then |
| |
| |
| if head -c2 "$tmp" | grep -q '#!'; then chmod 755 "$tmp"; else chmod 644 "$tmp"; fi |
| mv "$tmp" "$dest" |
| echo "$TAG updated $name from hf.co/$REPO_ID." |
| fi |
| else |
| echo "$TAG could not fetch latest $name β keeping existing copy." >&2 |
| fi |
| rm -f "$tmp" |
| } |
| update_workspace_file download_missing_models.sh '#!' || true |
| update_workspace_file README.md '.' || true |
| update_workspace_file start_comfy '#!' || true |
| update_workspace_file claude_start.sh '#!' || true |
|
|
| |
| |
| |
| TMP_DIR=$(mktemp -d) |
| if timeout 240 python3 - "$REPO_ID" "$TMP_DIR" "$TOKEN" <<'PY' |
| import sys |
| repo_id, tmp, token = sys.argv[1], sys.argv[2], sys.argv[3] |
| from huggingface_hub import snapshot_download |
| snapshot_download(repo_id=repo_id, allow_patterns=["workflows/*"], |
| local_dir=tmp, token=token or None) |
| PY |
| then |
| if [[ -d "$TMP_DIR/workflows" ]]; then |
| rsync -a --delete --exclude='.cache' "$TMP_DIR/workflows/" /workspace/workflows/ |
| echo "$TAG workflows/ synced from hf.co/$REPO_ID ($(find /workspace/workflows -name '*.json' | wc -l) json files)." |
| else |
| echo "$TAG snapshot returned no workflows/ β keeping existing copies." >&2 |
| fi |
| else |
| echo "$TAG workflows sync failed β keeping existing copies." >&2 |
| fi |
| rm -rf "$TMP_DIR" |
|
|