#!/usr/bin/env bash # # build.sh: the historical pictures and the figures for "The Huns" # # Fetches photographs, manuscript pages and paintings from Wikimedia Commons and map data from # Natural Earth, prepares the pictures for the post, and draws the map, the banquet hall, the charts # and the cover. # # Pictures: Wikimedia Commons; authors and licences are listed at the foot of the post # Map: Natural Earth 1:50m, public domain, https://www.naturalearthdata.com # Needs: curl, ImageMagick, rsvg-convert, the Noto fonts, Python 3 with Pillow # # The painted scenes marked "AI illustration" come from paint.sh. # # Usage: ./build.sh [options] # -f, --force prepare pictures again although they exist # -g, --figures-only only draw the map, the hall, the charts and the cover # -n, --dry-run print what would run # -h, --help # # PYTHON=/path/to/python3 selects the interpreter. # # Output: huns-*.jpg, huns-*.png, huns-map.svg and huns-hall.svg next to this file. # Downloads are kept in ${XDG_CACHE_HOME:-~/.cache}/rose-huns. set -Eeuo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/rose-huns" PYTHON="${PYTHON:-python3}" FORCE=0 FIGURES=0 DRY=0 # file in the cache | sha256 | source SOURCES=( "plaque.jpg|d9c0ceaeb9bf081e3d4f9861d2a8205b83681ecc4c0e2e03d484a48ad8dae1b9|https://upload.wikimedia.org/wikipedia/commons/b/b9/Dress_ornament_in_shape_of_a_tiger%2C_Xiongnu%2C_200-100_BC%2C_gold_-_%C3%96stasiatiska_museet%2C_Stockholm_-_DSC09564.JPG" "carpet.jpg|8e1a3d8969227987a501673922482fda92ad3c4529523cd4de78018b9aef1dbd|https://upload.wikimedia.org/wikipedia/commons/8/88/Facial_portrait_of_a_nobleman_of_Central_Asian_type%2C_Noin-Ula_carpet%2C_1st_century_BCE_-_1st_century_CE.jpg" "cauldron.jpg|c72fbe778de9066651aa4fb1acddd6fde8dc1621ebf0b707b9bf272ce4f550b9|https://upload.wikimedia.org/wikipedia/commons/0/0b/DSC_0559_%282%29_Hunnic_cauldron_from_a_burial_found_at_J%C4%99drzychowice_%28copy%2C_1927%29%2C_original_in_Pushkin_State_Museum_of_Fine_Arts%2C_Russia.jpg" "coin.jpg|8592d3e834b4a9702a5db87779da78ce4d89f2756b978ee5d00c0b849b0b99ff|https://upload.wikimedia.org/wikipedia/commons/2/2b/HunCoinDerivedFromSassanianDesign5thCE.JPG" "plaquette.jpg|ed7a22531c5254166e5d97b7ec7023c47563a87ec0a4c6be4b4bbcad63fc00a0|https://upload.wikimedia.org/wikipedia/commons/8/88/Placchetta_dall%27antico%2C_attila%2C_1490-1500_ca..JPG" "feast.jpg|dda29c6678612a337f17b76d84481fd5bbe438cb992d76eeacd7a20080dfb520|https://upload.wikimedia.org/wikipedia/commons/e/e4/Than_M%C3%B3r_-_Attila_lakom%C3%A1ja_%281870%29.jpg" "leo.jpg|cb0ab06bbce4dbc1ee7c131dfd47f3c4426bc70fd5eac44945c74e07148b21ad|https://upload.wikimedia.org/wikipedia/commons/8/82/Raphael_-_The_Meeting_of_Leo_the_Great_and_Attila.jpg" "aquileia.jpg|1598e408da40e28a74ace5b50ba732337082ab297402a72ed51e7001e4ea892d|https://upload.wikimedia.org/wikipedia/commons/a/a4/Chronicon_Pictum_P014_Atilla_Aquilei%C3%A1t_ostromolja.JPG" "death.jpg|3e6f3709401a540364fb8e0489aa37b8279a8e607bb5c586e22eba174707834e|https://upload.wikimedia.org/wikipedia/commons/d/d8/Paczka_Ferenc_-_Attila_hal%C3%A1la_-_1884.jpg" "stag.jpg|31f1894a8358fd062804a85e035f82f00fedbd6a08af73a29f5af226bcbf4511|https://upload.wikimedia.org/wikipedia/commons/0/08/K%C3%A9pes_kr%C3%B3nika_-_5.oldal_-_A_csodaszarvas.jpg" "king.jpg|7c789c53452a20458b823f31b57e01148809f0d7ef37ea21f652bcd76ae29751|https://upload.wikimedia.org/wikipedia/commons/9/92/K%C3%A9pes_kr%C3%B3nika_-_11.oldal_-_Attila_kir%C3%A1ly.jpg" "enlaka.jpg|9cd02f93e240f5b93a429debffb5413c5aa5f163d18b72f6549e866aaba3ed23|https://upload.wikimedia.org/wikipedia/commons/2/25/Enlaka_rovas_inscription.jpg" "nikolsburg.gif|d7c973402ee9c5a22a0fe3fb6d6ee01fae445c8655c537a222f1475c1691d865|https://upload.wikimedia.org/wikipedia/commons/5/50/Nikolsburg.gif" "land.geojson|e874b27a51d146452be360cafb3cc50c86001074a67d534113e6534682f9826b|https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_50m_land.geojson" "rivers.geojson|f286e0ce978fde999ca2d7a78c764be08542e19b63cded52b05c12d5173ccc51|https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_50m_rivers_lake_centerlines.geojson" "lakes.geojson|d350b75978b26fe839b797c2c529b2fb8f47fb3983c03f4964e36d5df9378a52|https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_50m_lakes.geojson" ) # file in the cache | picture in the post (longest side at most 2000 px) PICTURES=( "plaque.jpg|huns-plaque.jpg" "carpet.jpg|huns-carpet.jpg" "cauldron.jpg|huns-cauldron.jpg" "coin.jpg|huns-coin.jpg" "plaquette.jpg|huns-plaquette.jpg" "feast.jpg|huns-feast.jpg" "leo.jpg|huns-leo.jpg" "aquileia.jpg|huns-aquileia.jpg" "death.jpg|huns-death.jpg" "stag.jpg|huns-stag.jpg" "king.jpg|huns-king.jpg" "enlaka.jpg|huns-enlaka.jpg" "nikolsburg.gif[0]|huns-nikolsburg.png" ) say() { printf '%s\n' "$*" >&2; } die() { say "error: $*"; exit 2; } usage() { sed -n '/^# Usage:/,/^# PYTHON/p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } run() { if ((DRY)); then printf '%q ' "$@" printf '\n' else "$@" fi } fetch() { # url file sha256 if [[ ! -f $2 ]] || ! sha256sum --status -c <<<"$3 $2"; then say "fetching ${2##*/}" run curl -fsSL --retry 5 --retry-delay 20 -A "rose-build/1.0" -o "$2" "$1" ((DRY)) || sha256sum --status -c <<<"$3 $2" || die "${2##*/} is not the expected file; the source may have been updated: $1" fi } while (($#)); do case $1 in -f | --force) FORCE=1 ;; -g | --figures-only) FIGURES=1 ;; -n | --dry-run) DRY=1 ;; -h | --help) usage; exit 0 ;; *) die "unknown option $1 (see --help)" ;; esac shift done MAGICK="$(command -v magick || command -v convert || true)" [[ -n $MAGICK ]] || die "ImageMagick is not installed" for tool in curl rsvg-convert fc-list "$PYTHON"; do command -v "$tool" >/dev/null || die "$tool is not installed" done "$PYTHON" -c 'import PIL' 2>/dev/null || die "$PYTHON lacks Pillow (set PYTHON=...)" for font in "Noto Serif" "Noto Sans Old Hungarian" "Noto Serif Devanagari" "Noto Serif CJK TC"; do [[ -n "$(fc-list ":family=$font")" ]] || die "font '$font' is not installed" done run mkdir -p "$CACHE" for entry in "${SOURCES[@]}"; do IFS='|' read -r file sha url <<<"$entry" fetch "$url" "$CACHE/$file" "$sha" done if ((!FIGURES)); then for entry in "${PICTURES[@]}"; do IFS='|' read -r from to <<<"$entry" if ((FORCE)) || [[ ! -f $HERE/$to ]]; then run "$MAGICK" "$CACHE/$from" -auto-orient -resize '2000x2000>' -strip -quality 86 "$HERE/$to" fi done fi export PYTHONDONTWRITEBYTECODE=1 run "$PYTHON" "$HERE/figures.py" --cache "$CACHE" --out "$HERE"