#!/usr/bin/env bash set -euo pipefail repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) dither_dir="${repo_root}/bin/dither" cache_dir="${DITHER_CACHE_DIR:-${repo_root}/.cache/dither}" mkdir -p "${cache_dir}" pushd "${dither_dir}" >/dev/null ROOT="${repo_root}/content" KEY="${repo_root}/secret.key" DITHER_CACHE_DIR="${cache_dir}" bundle exec ruby dither.rb & dither_pid=$! popd >/dev/null cleanup() { if kill -0 "${dither_pid}" 2>/dev/null; then kill "${dither_pid}" 2>/dev/null || true wait "${dither_pid}" 2>/dev/null || true fi } trap cleanup EXIT INT TERM # Wait until the dither server is listening instead of guessing with sleep. for _ in {1..50}; do if (echo >/dev/tcp/localhost/4567) >/dev/null 2>&1; then break fi sleep 0.1 done DITHER_SERVER=http://localhost:4567 hugo server