diff options
Diffstat (limited to 'ikiwiki.sh')
-rwxr-xr-x | ikiwiki.sh | 60 |
1 files changed, 49 insertions, 11 deletions
@@ -1,28 +1,66 @@ #!/bin/bash +# +# Build an ikiwiki of mine, incrementally, and publish it on my local +# web server. +# +# Usage: $0 /path/to/ikiwiki.setup -set -xeuo pipefail +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")" -artifact="$(mktemp)" -artifactdir="$(mktemp -d)" -trap 'rm -rf "$artifact $artifactdir"' EXIT +# Where this script resides. We'll get the ambient-run script and +# other files from there. +ambientdir="$(dirname "$0")" -if [ ! -e "$srcdir/.ambient-script" ]; then - cp ikiwiki-ambient-script "$srcdir/.ambient-script" +# 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 -./ambient-run \ + +# 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. +"$ambientdir/ambient-run" \ --image ~/tmp/ambient/ambient-ikiwiki.qcow2 \ - --artifact "$artifact" \ --dependencies ~/.ikiwiki/ \ + --cache "$cache" \ --log ~/tmp/ambient/log \ "$srcdir" +# 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/. - -tar -C "$artifactdir" -xf "$artifact" -rsync -a --del "$artifactdir/." "$remote:/srv/http/." +rsync -a --del "$cache/html/." "$remote:/srv/http/." |