update.sh: robust to file changes mid-script