futurefantasy commited on
Commit
2db6e5a
·
verified ·
1 Parent(s): 4158e7f

Update scripts/unpack_data.sh

Browse files
Files changed (1) hide show
  1. scripts/unpack_data.sh +62 -10
scripts/unpack_data.sh CHANGED
@@ -8,11 +8,20 @@ DATA_ROOT="${1:-${ROOT_DIR}/data}"
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}"
@@ -25,26 +34,69 @@ while IFS= read -r archive; do
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
 
8
  mkdir -p "${DATA_ROOT}"
9
 
10
  declare -A selected_archives=()
11
+ declare -A selected_archive_parts=()
12
 
13
  while IFS= read -r archive; do
14
  filename="$(basename "${archive}")"
15
  base="${filename}"
16
+ if [[ "${filename}" == *.tar.zst.part-* ]]; then
17
+ base="${filename%%.part-*}.tar.zst"
18
+ selected_archive_parts["${base}"]+="${archive}"$'\n'
19
+ continue
20
+ elif [[ "${filename}" == *.tar.part-* ]]; then
21
+ base="${filename%%.part-*}.tar"
22
+ selected_archive_parts["${base}"]+="${archive}"$'\n'
23
+ continue
24
+ elif [[ "${filename}" == *.tar.zst ]]; then
25
  base="${filename%.tar.zst}"
26
  elif [[ "${filename}" == *.tar ]]; then
27
  base="${filename%.tar}"
 
34
  exit 1
35
  fi
36
  selected_archives["${base}"]="${archive}"
37
+ done < <(find "${ARCHIVE_DIR}" -maxdepth 1 \( -type f -o -type l \) \( -name '*.tar' -o -name '*.tar.zst' \) | sort)
38
 
39
+ while IFS= read -r archive; do
40
+ filename="$(basename "${archive}")"
41
+ if [[ "${filename}" == *.tar.zst.part-* ]]; then
42
+ base="${filename%%.part-*}.tar.zst"
43
+ selected_archive_parts["${base}"]+="${archive}"$'\n'
44
+ elif [[ "${filename}" == *.tar.part-* ]]; then
45
+ base="${filename%%.part-*}.tar"
46
+ selected_archive_parts["${base}"]+="${archive}"$'\n'
47
+ fi
48
+ done < <(find "${ARCHIVE_DIR}" -maxdepth 1 \( -type f -o -type l \) \( -name '*.tar.zst.part-*' -o -name '*.tar.part-*' \) | sort)
49
+
50
+ if [[ "${#selected_archives[@]}" -eq 0 && "${#selected_archive_parts[@]}" -eq 0 ]]; then
51
  echo "no archives found under ${ARCHIVE_DIR}" >&2
52
  exit 1
53
  fi
54
 
55
+ mapfile -t archive_bases < <(
56
+ {
57
+ printf '%s\n' "${!selected_archives[@]}"
58
+ printf '%s\n' "${!selected_archive_parts[@]}"
59
+ } | awk 'NF' | sort -u
60
+ )
61
  for base in "${archive_bases[@]}"; do
62
+ archive="${selected_archives[${base}]:-}"
63
+ parts_blob="${selected_archive_parts[${base}]:-}"
64
+ if [[ -n "${archive}" && -n "${parts_blob}" ]]; then
65
+ echo "found both full archive and split parts for ${base} under ${ARCHIVE_DIR}; keep only one form" >&2
66
+ exit 1
67
+ fi
68
+ if [[ -n "${archive}" ]]; then
69
+ echo "extracting ${archive}"
70
+ case "${archive}" in
71
+ *.tar.zst)
72
+ tar --zstd -xf "${archive}" -C "${DATA_ROOT}"
73
+ ;;
74
+ *.tar)
75
+ tar -xf "${archive}" -C "${DATA_ROOT}"
76
+ ;;
77
+ *)
78
+ echo "unsupported archive format: ${archive}" >&2
79
+ exit 1
80
+ ;;
81
+ esac
82
+ continue
83
+ fi
84
+
85
+ if [[ -z "${parts_blob}" ]]; then
86
+ echo "missing archive content for ${base}" >&2
87
+ exit 1
88
+ fi
89
+ mapfile -t parts < <(printf '%s' "${parts_blob}" | awk 'NF' | sort)
90
+ echo "extracting ${base} from ${#parts[@]} parts"
91
+ case "${base}" in
92
  *.tar.zst)
93
+ cat "${parts[@]}" | tar --zstd -xf - -C "${DATA_ROOT}"
94
  ;;
95
  *.tar)
96
+ cat "${parts[@]}" | tar -xf - -C "${DATA_ROOT}"
97
  ;;
98
  *)
99
+ echo "unsupported split archive format: ${base}" >&2
100
  exit 1
101
  ;;
102
  esac