futurefantasy commited on
Commit
6a65016
·
verified ·
1 Parent(s): 51632a9

Update scripts/unpack_data.sh

Browse files
Files changed (1) hide show
  1. scripts/unpack_data.sh +53 -0
scripts/unpack_data.sh ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ ARCHIVE_DIR="${ROOT_DIR}/data"
6
+ DATA_ROOT="${1:-${ROOT_DIR}/data}"
7
+
8
+ mkdir -p "${DATA_ROOT}"
9
+
10
+ declare -A selected_archives=()
11
+
12
+ while IFS= read -r archive; do
13
+ filename="$(basename "${archive}")"
14
+ base="${filename}"
15
+ if [[ "${filename}" == *.tar.zst ]]; then
16
+ base="${filename%.tar.zst}"
17
+ elif [[ "${filename}" == *.tar ]]; then
18
+ base="${filename%.tar}"
19
+ else
20
+ continue
21
+ fi
22
+
23
+ if [[ -n "${selected_archives[${base}]:-}" ]]; then
24
+ echo "found multiple archive variants for ${base} under ${ARCHIVE_DIR}; keep only one of .tar or .tar.zst" >&2
25
+ exit 1
26
+ fi
27
+ selected_archives["${base}"]="${archive}"
28
+ done < <(find "${ARCHIVE_DIR}" -maxdepth 1 -type f \( -name '*.tar' -o -name '*.tar.zst' \) | sort)
29
+
30
+ if [[ "${#selected_archives[@]}" -eq 0 ]]; then
31
+ echo "no archives found under ${ARCHIVE_DIR}" >&2
32
+ exit 1
33
+ fi
34
+
35
+ mapfile -t archive_bases < <(printf '%s\n' "${!selected_archives[@]}" | sort)
36
+ for base in "${archive_bases[@]}"; do
37
+ archive="${selected_archives[${base}]}"
38
+ echo "extracting ${archive}"
39
+ case "${archive}" in
40
+ *.tar.zst)
41
+ tar --zstd -xf "${archive}" -C "${DATA_ROOT}"
42
+ ;;
43
+ *.tar)
44
+ tar -xf "${archive}" -C "${DATA_ROOT}"
45
+ ;;
46
+ *)
47
+ echo "unsupported archive format: ${archive}" >&2
48
+ exit 1
49
+ ;;
50
+ esac
51
+ done
52
+
53
+ echo "raw data extracted into ${DATA_ROOT}"