#!/usr/bin/env bash # # build.sh: the historical pictures and the figures for "The Turks" # # Fetches photographs, manuscript pages and a painting from Wikimedia Commons and map data from # Natural Earth, prepares the pictures for the post, and draws the map, the yurt, 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 yurt, the charts and the cover # -n, --dry-run print what would run # -h, --help # # PYTHON=/path/to/python3 selects the interpreter. # # Output: turks-*.jpg, turks-*.png, turks-map.svg and turks-yurt.svg next to this file. # Downloads are kept in ${XDG_CACHE_HOME:-~/.cache}/rose-turks. set -Eeuo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/rose-turks" PYTHON="${PYTHON:-python3}" FORCE=0 FIGURES=0 DRY=0 # file in the cache | sha256 | source SOURCES=( "katun.jpg|09aae471fb8407624c38fe40a2ab1e5847f03d8d37023c66df9dc0e4f696e611|https://upload.wikimedia.org/wikipedia/commons/b/b2/Katun.jpg" "belukha.jpg|3a65b824257fba34b011b50695154659cbd4d14c6aabd6f1efd067f29a4e32f7|https://upload.wikimedia.org/wikipedia/commons/0/0d/Belukha.jpg" "balbal.jpg|13f361ce361f578c788b8957f8a3744f5e48687d6ce2f924836ee2c53db2e9df|https://upload.wikimedia.org/wikipedia/commons/0/06/Balbal%2C_6th-10th_cents.%2C_Burana%2C_Kyrgyzstan_%285%29.jpg" "kultigin.jpg|5dd3075bbdd282c4b7cec8f3007a1ef3f7ea41409b237bd0ebe2125fcf9c25b0|https://upload.wikimedia.org/wikipedia/commons/6/62/Kultegin_monument_Mongolia.JPG" "head.jpg|43765fa810c49d79be2340b84abffa20ab59b212b0cbb585bed9648e5f14e810|https://upload.wikimedia.org/wikipedia/commons/b/bf/Turkic_Head_of_Koltegin_Statue_%2835324303410%29.jpg" "tonyukuk.jpg|2bb6c8553bf2ae810ff9a76e5e0d6093440f63cac3f37ba65fe4f20fc6c7c81f|https://upload.wikimedia.org/wikipedia/commons/7/72/Bilge_Tonyukuk_-_Orkhon_Inscriptions.jpeg" "irkbitig.jpg|0ba52dc3ddab5705a6b231d0be6851bf2984a64f24c8b30d99b5ea649af55351|https://upload.wikimedia.org/wikipedia/commons/4/4e/Irk_Bitig_Fal_Kitab%C4%B1_page_53.jpg" "yurt.jpg|70748d591758cfc74846f9a3678afcb5c16b060e2ed9e40e426351b422810514|https://upload.wikimedia.org/wikipedia/commons/1/1f/Jurte_von_innen.jpg" "helmet.jpg|c1a06e61f1be57ed16ed3bfdc993083c300c2ec91e3a77934aa160341fcf71df|https://upload.wikimedia.org/wikipedia/commons/e/e9/0925_Kipchak_style_helmet_13th_c.JPG" "stones.jpg|a30dd1d8595903b3d93942f934ef963db92e88ff809d753be3459471cb6aa045|https://upload.wikimedia.org/wikipedia/commons/3/3a/Polovtsian_Stone_Statues_Opishnia_Museum_01_%28DSCF9537%29.jpg" "chronicle.jpg|29d568875d409fe59d5ca55122323a0a74794393b570a67f6092b93170faa61f|https://upload.wikimedia.org/wikipedia/commons/d/d1/Radzivill_Chronicle_Cumans.jpg" "codex.jpg|9ee173097989137a07c135f3776d5f77e5a722bb2738bc1583935638134cdf6a|https://upload.wikimedia.org/wikipedia/commons/9/9f/Codex_Cumanicus_58.jpg" "igor.jpg|7c8527d1e6ab734af7155dad1e0200c32b3d6ab746576ccfc999006defd352fc|https://upload.wikimedia.org/wikipedia/commons/4/43/After_the_battle_of_Igor_Svyatoslavich_with_the_Cumans_par_Victor_Mikhailovich_Vasnetsov.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=( "katun.jpg|turks-katun.jpg" "belukha.jpg|turks-belukha.jpg" "balbal.jpg|turks-balbal.jpg" "kultigin.jpg|turks-kultigin.jpg" "head.jpg|turks-head.jpg" "tonyukuk.jpg|turks-tonyukuk.jpg" "irkbitig.jpg|turks-irkbitig.jpg" "yurt.jpg|turks-yurt.jpg" "helmet.jpg|turks-helmet.jpg" "stones.jpg|turks-stones.jpg" "chronicle.jpg|turks-chronicle.jpg" "codex.jpg|turks-codex.jpg" "igor.jpg|turks-igor.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 Old Turkic"; 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"