| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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 |
|
| 42 |
|
| 43 |
|
| 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")" |