#!/bin/bash # # Build an ikiwiki of mine, incrementally, and publish it on my local # web server. # # Usage: $0 /path/to/ikiwiki.setup set -euo pipefail setup="$1" # Get local source and html directories. The source directory will get # an .ambient-script, if missing. The html directory will be used by # the build, for incremental builds, and will be updated from the VM # after the build. srcdir="$(sed -n '/^srcdir: */s///p' "$setup")" destdir="$(sed -n '/^destdir: */s///p' "$setup")" # Where this script resides. We'll get the ambient-run script and # other files from there. ambientdir="$(dirname "$0")" # A temporary directory for helper files. tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT # Create a cache, with the local html directory and the site's # .ikiwiki directory. cache="$tmp/cache" mkdir "$cache" "$cache/.ikiwiki" "$cache/html" if [ -e "$srcdir/.ikiwiki" ]; then rsync -a "$srcdir/.ikiwiki/." "$cache/.ikiwiki/." fi if [ -e "$destdir" ]; then rsync -a "$destdir/." "$cache/html/." fi # Always install an .ambient-script the source directory. We gladly # overwrite any existing one. I don't keep one in my site sources. script="$srcdir/.ambient-script" cp "$ambientdir/ikiwiki-ambient-script" "$script" # Run ikiwiki under ambient-run. The input is the local source # directory. An incremental build needs the local html directory and # the site's .ikiwiki directory, and changes to those need to persist # between runs, so we use the cache mechanism. cat <"$tmp/build.yaml" image: ~/tmp/ambient/ambient-ikiwiki.qcow2 src: $srcdir cache: $cache dependencies: ~/.ikiwiki/ EOF "$ambientdir/ambient-run" \ --log ~/tmp/ambient/log \ "$tmp/build.yaml" # Remove the script installed one. rm "$script" # Copy back .ikiwiki and html to source directory and local html # directory. install -d "$srcdir/.ikiwiki" "$destdir" # create them if missing" rsync -av --del "$cache/.ikiwiki/." "$srcdir/.ikiwiki/." rsync -av --del "$cache/html/." "$destdir/." # Update the local web server. remote=_ewww@web ssh "$remote" install -d /srv/http/web/. rsync -a --del "$cache/html/." "$remote:/srv/http/."