scripts/update-droptables.sh 1.9 K · 54 lines · raw · history

1 #!/usr/bin/env bash
2 #
3 # Refresh the vendored copy of Digital Extremes' drop tables.
4 #
5 # /Warframe reads Blog/Resources/droptables.html rather than warframe.com,
6 # which blocks requests from the server. This runs before a publish so each
7 # deploy ships current data. Commit the result.
8 #
9 # A failed refresh is a warning, not an error: the committed copy is still good
10 # data, and an outage at DE should not block a deploy that has nothing to do
11 # with Warframe. Missing the file entirely is an error, because then there is
12 # nothing to publish.
13
14 set -uo pipefail
15
16 url="${WARFRAME_DROPTABLES_URL:-https://www.warframe.com/droptables}"
17 repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
18 target="$repo/Blog/Resources/droptables.html"
19 tmp="$(mktemp)"
20 trap 'rm -f "$tmp"' EXIT
21
22 de_last_update() {
23 grep -A1 '<b>Last Update:</b>' "$1" 2>/dev/null | tail -1 | tr -d '\r'
24 }
25
26 keep_existing() {
27 echo "WARNING: could not refresh the drop tables: $1" >&2
28
29 if [ ! -f "$target" ]; then
30 echo "ERROR: and there is no committed copy at $target to fall back on." >&2
31 exit 1
32 fi
33
34 echo "WARNING: publishing the committed copy (DE last update $(de_last_update "$target"))." >&2
35 exit 0
36 }
37
38 echo "Fetching $url"
39 curl -sSL --fail --max-time 180 -o "$tmp" "$url" || keep_existing "download failed"
40
41 # The publish that follows ships whatever lands here, so an error page or a
42 # truncated download must not replace a copy that is known good. The real page
43 # is around 4 MB across twenty sections; anything far short of that is not it.
44 bytes=$(wc -c < "$tmp" | tr -d ' ')
45 sections=$(grep -c '<h3 id=' "$tmp")
46
47 if [ "$bytes" -lt 1000000 ] || [ "$sections" -lt 15 ]; then
48 keep_existing "got $bytes bytes and $sections sections, which is not the drop table page"
49 fi
50
51 mv "$tmp" "$target"
52 trap - EXIT
53
54 echo "Updated Blog/Resources/droptables.html: $bytes bytes, $sections sections, DE last update $(de_last_update "$target")"