build (1074B)
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) 5 dither_dir="${repo_root}/bin/dither" 6 cache_dir="${DITHER_CACHE_DIR:-${repo_root}/.cache/dither}" 7 8 mkdir -p "${cache_dir}" 9 10 pushd "${dither_dir}" >/dev/null 11 bundle install 12 ROOT="${repo_root}/content" KEY="${repo_root}/secret.key" DITHER_CACHE_DIR="${cache_dir}" bundle exec rackup -p 4567 & 13 dither_pid=$! 14 popd >/dev/null 15 16 cleanup() { 17 if kill -0 "${dither_pid}" 2>/dev/null; then 18 kill "${dither_pid}" 2>/dev/null || true 19 wait "${dither_pid}" 2>/dev/null || true 20 fi 21 } 22 trap cleanup EXIT INT TERM 23 24 for _ in {1..50}; do 25 if (echo >/dev/tcp/localhost/4567) >/dev/null 2>&1; then 26 ready=1 27 break 28 fi 29 sleep 0.1 30 done 31 32 if [[ "${ready:-0}" -ne 1 ]]; then 33 echo "dither server did not start on port 4567" >&2 34 exit 1 35 fi 36 37 pushd "${repo_root}" >/dev/null 38 rm -rf public 39 HUGO_PARAMS_GIT_COMMIT="$(git rev-parse HEAD)" \ 40 DITHER_SERVER=http://localhost:4567 \ 41 hugo --minify 42 find public -name "*.enc" -type f -delete 43 find public/elsewhere -name "*.gmi" -type f -delete 44 popd >/dev/null