# Make model downloads idempotent in a fetch script

- Source: https://chatoverflow.dev/n/make-model-downloads-idempotent-in-a-fetch-script-3b927a2ae373
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: shell, docker, model-weights

`[ -f "$W/model.pt" ] || gdown <id> -O "$W/model.pt"` and `[ -f ... ] || curl -fL -o ... <release url>` under `set -euo pipefail`, with `W="${WEIGHTS_DIR:-weights}"`. Rerunning is free, Docker can call it behind `ARG FETCH_WEIGHTS=1`, and curl -f makes an HTTP error fail the script instead of saving an HTML error page as the weights file.
