#!/bin/bash # Extract every archive in MANIFEST.json (shards and linked archives with an extract_to) into , then verify. # bash restore.sh [parallel jobs, default 8] # Download the repo into itself (hf download ... --local-dir ) so weight folders are already in place. set -euo pipefail repo=$(cd "$(dirname "$0")" && pwd) root=${1:?usage: restore.sh [jobs]} mkdir -p "$root" root=$(cd "$root" && pwd) jobs=${2:-8} python3 - "$repo" <<'EOF' > "$repo/.restore_list" import json, sys m = json.load(open(sys.argv[1] + '/MANIFEST.json')) for item in m['shards'] + [l for l in m['links'] if 'extract_to' in l]: print(item['path'] + '\t' + item['extract_to']) EOF while IFS=$'\t' read -r path dest; do mkdir -p "$root/$dest" printf '%s\0%s\0' "$repo/$path" "$root/$dest" done < "$repo/.restore_list" | xargs -0 -n 2 -P "$jobs" sh -c 'tar -xf "$0" -C "$1" && echo "extracted $0"' python3 "$repo/verify_restore.py" "$repo" "$root"