|
1 | 1 | #!/bin/bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -vendored="$(dirname "$0")"/../vendored |
| 4 | +bin="$(dirname "$0")" |
| 5 | +vendored="$bin"/../vendored |
5 | 6 |
|
6 | 7 | main() { |
7 | 8 | s3_dst="${1:?A destination s3:// URL where the renew file is hosted is required as the first argument.}" |
8 | 9 | s3_src="${2:?A source s3:// URL where the fallback renew file is hosted is required as the second argument.}" |
| 10 | + nextclade="${3:?A path to the Nextclade executable is required as the third argument}" |
| 11 | + nextclade_dataset="${4:?A path to a Nextclade dataset ZIP archive is required as the fourth argument}" |
9 | 12 | # Nextclade dataset reference wildcard |
10 | | - reference="${3:-}" |
| 13 | + reference="${5:-}" |
| 14 | + |
11 | 15 | if renew-flag-exists; then |
12 | 16 | echo "[INFO] Found renew flag" >&2 |
13 | 17 | echo "false" |
14 | 18 | exit 0 |
15 | 19 | fi |
16 | 20 |
|
| 21 | + cache_versions="$(get-cache-version-info)" |
| 22 | + cache_nextclade_version="$(echo "$cache_versions" | jq -r .nextclade_version)" |
| 23 | + current_nextclade_version="$("$nextclade" --version)" |
| 24 | + if [[ "$cache_nextclade_version" != "$current_nextclade_version" ]]; then |
| 25 | + echo "[INFO] Current Nextclade version ($current_nextclade_version) is different from cache version ($cache_nextclade_version)" >&2 |
| 26 | + echo "false" |
| 27 | + exit 0 |
| 28 | + fi |
| 29 | + |
| 30 | + cache_dataset_version="$(echo "$cache_versions" | jq -r .nextclade_dataset_version)" |
| 31 | + current_dataset_version="$(unzip -p "$nextclade_dataset" pathogen.json | jq -r '.version.tag')" |
| 32 | + if [[ "$cache_dataset_version" != "$current_dataset_version" ]]; then |
| 33 | + echo "[INFO] Current Nextclade dataset version ($current_dataset_version) is different from cache version ($cache_dataset_version)" >&2 |
| 34 | + echo "false" |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | + |
17 | 38 | echo "true" |
18 | 39 | } |
19 | 40 |
|
20 | 41 | renew-flag-exists() { |
21 | | - local renew_file="nextclade${reference}.tsv.zst.renew" |
22 | | - local dst_renew_file="${s3_dst}/${renew_file}" |
23 | | - local src_renew_file="${s3_src}/${renew_file}" |
| 42 | + local renew_file="nextclade$reference.tsv.zst.renew" |
| 43 | + local dst_renew_file="$s3_dst/$renew_file" |
| 44 | + local src_renew_file="$s3_src/$renew_file" |
| 45 | + |
| 46 | + "$vendored"/s3-object-exists "$dst_renew_file" || "$vendored"/s3-object-exists "$src_renew_file" |
| 47 | +} |
| 48 | + |
| 49 | +get-cache-version-info() { |
| 50 | + # TODO: Update check a separate file for version info |
| 51 | + # Currently just checks the first row of the nextclade.tsv file |
| 52 | + local version_file="nextclade$reference.tsv.zst" |
| 53 | + local dst_version_file="$s3_dst/$version_file" |
| 54 | + local src_version_file="$s3_src/$version_file" |
24 | 55 |
|
25 | | - "$vendored"/s3-object-exists "${dst_renew_file}" || "$vendored"/s3-object-exists "${src_renew_file}" |
| 56 | + "$bin"/fetch-cache-version "$dst_version_file" || "$bin"/cache-version "$src_version_file" |
26 | 57 | } |
27 | 58 |
|
28 | 59 | main "$@" |
0 commit comments