#!/usr/bin/env bash # # build.sh: the historical pictures and the figures for "The Goths" # # Fetches paintings and photographs from Wikimedia Commons and map data from Natural Earth, # prepares the pictures for the post, and draws the map, 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 charts and the cover # -n, --dry-run print what would run # -h, --help # # PYTHON=/path/to/python3 selects the interpreter. # # Output: goths-*.jpg, goths-*.png and goths-map.svg next to this file. Downloads are kept in # ${XDG_CACHE_HOME:-~/.cache}/rose-goths. set -Eeuo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/rose-goths" PYTHON="${PYTHON:-python3}" FORCE=0 FIGURES=0 DRY=0 # file in the cache | sha256 | source SOURCES=( "luminais.jpg|42de18dfda3ea2ce205d3c2a4ca362e4d8d9b97a307d538b31ddec8a6f351195|https://upload.wikimedia.org/wikipedia/commons/2/21/Evariste-Vital_Luminais_-_Goths_traversant_une_rivi%C3%A8re.jpg" "codex.jpg|bd48925033711cdde90e28aee29513a75e34f7701da00aeb52d849021b429029|https://upload.wikimedia.org/wikipedia/commons/3/31/Codex_Argenteus_page.jpg" "domagnano.jpg|ed0057032ef84f8bc5244e032116d3b084ab147d8c52dc4b381022dd138f11d9|https://upload.wikimedia.org/wikipedia/commons/4/45/GNM_-_Adlerfibel.jpg" "ossmannstedt.jpg|9f4370470740aed2744c9a5348240f877731f86c803145c105141320690dc709|https://upload.wikimedia.org/wikipedia/commons/d/dc/Adlerfibel_O%C3%9Fmannstedt.JPG" "walters.jpg|eecd4a7e6bd8c0b89f5106eb36bc27d88057fed19af636593384077a076da645|https://upload.wikimedia.org/wikipedia/commons/7/78/Visigothic_-_Pair_of_Eagle_Fibula_-_Walters_54421%2C_54422.jpg" "attila.jpg|9992665923e898551f2291dee75c2ede7484895a4099aa4ff4ab2c5f7a786c35|https://upload.wikimedia.org/wikipedia/commons/1/14/Eugene_Ferdinand_Victor_Delacroix_Attila_fragment.jpg" "neuville.jpg|1769fe0459cb38f7fb37880becb965e9e221a4e4ec9d11f879ea89049b250a1d|https://upload.wikimedia.org/wikipedia/commons/7/7c/De_Neuville_-_The_Huns_at_the_Battle_of_Chalons.jpg" "palatium.jpg|ac306cbb6423af58b56318daea7fd7f75612b7ef9385f027908f68e8598409c7|https://upload.wikimedia.org/wikipedia/commons/e/ea/Ravenna%2C_sant%27apollinare_nuovo_palatium_%28inizio_del_VI_secolo%29.jpg" "mausoleum.jpg|787d45321d55f59ac794591bf6930171cb7b881f68615381982e7a1cc58eea24|https://upload.wikimedia.org/wikipedia/commons/f/f5/Mausoleum_of_Theodoric_%28Ravenna%29_-_Exterior.jpg" "ludovisi.jpg|077ac2456dbde3a269e790ef5b75ff33ea75ffa1324a5cd4e85fa8390e38d299|https://upload.wikimedia.org/wikipedia/commons/d/d0/Ludovisi_Battle_Sarcophagus.jpg" "crown.jpg|6b76ce4ca6006426f83a0234b01f7025db7ea68928bf1447b5e6a93879f7b2c3|https://upload.wikimedia.org/wikipedia/commons/f/f2/Corona_de_%2829049230050%29.jpg" "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=( "luminais.jpg|goths-river.jpg" "codex.jpg|goths-codex.jpg" "ludovisi.jpg|goths-sarcophagus.jpg" "attila.jpg|goths-attila.jpg" "neuville.jpg|goths-chalons.jpg" "palatium.jpg|goths-palatium.jpg" "mausoleum.jpg|goths-mausoleum.jpg" "domagnano.jpg|goths-fibula-domagnano.jpg" "walters.jpg|goths-fibula-walters.jpg" "ossmannstedt.jpg|goths-ossmannstedt.jpg" "crown.jpg|goths-crown.jpg" ) 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 Gothic"; 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"