summaryrefslogtreecommitdiff
path: root/ikiwiki.sh
blob: 2949687c1b53118d6a37c5c7dbbfd7e69121bc82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/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 <<EOF >"$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/."