summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-07-15 11:37:49 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-15 11:37:49 +0000
commit81f4b5698c919bea00de8969239a9ad2e837e9dd (patch)
tree78d0841477ae88ee7f347b38bee524af825242ff
parent3d7f4ef9a849465ca062f393e3ac3b5597d78b4a (diff)
parent3f61ba245fa3f03653fcecc871c5eae4f2019a1a (diff)
downloadambient-ci-81f4b5698c919bea00de8969239a9ad2e837e9dd.tar.gz
Merge branch 'liw/ikiwiki' into 'main'
feat(ikiwiki.sh): run ambient-run from dir where ikiwiki.sh is See merge request larswirzenius/ambient-ci!29
-rw-r--r--ikiwiki-ambient-script13
-rwxr-xr-xikiwiki.sh60
2 files changed, 58 insertions, 15 deletions
diff --git a/ikiwiki-ambient-script b/ikiwiki-ambient-script
index 19cc585..54fe257 100644
--- a/ikiwiki-ambient-script
+++ b/ikiwiki-ambient-script
@@ -5,8 +5,13 @@ set -xeuo pipefail
export HOME=/workspace
mkdir /workspace/html
-sed -i 's#^srcdir:.*#srcdir: /workspace/src#' ikiwiki.setup
-sed -i 's#^destdir:.*#destdir: /workspace/html#' ikiwiki.setup
+cp ikiwiki.setup /workspace
+sed -i 's#^srcdir:.*#srcdir: /workspace/src#' /workspace/ikiwiki.setup
+sed -i 's#^destdir:.*#destdir: /workspace/cache/html#' /workspace/ikiwiki.setup
-ikiwiki --setup ikiwiki.setup --libdir /workspace/deps --rebuild --verbose
-tar -cf "$1" -C /workspace/html .
+rm -rf .ikiwiki
+cp -a /workspace/cache/.ikiwiki .ikiwiki
+ikiwiki --setup /workspace/ikiwiki.setup --libdir /workspace/deps --refresh --verbose
+
+find /workspace/cache/.ikiwiki -mindepth 1 -delete
+mv .ikiwiki/* /workspace/cache/.ikiwiki
diff --git a/ikiwiki.sh b/ikiwiki.sh
index de71ea8..90e444b 100755
--- a/ikiwiki.sh
+++ b/ikiwiki.sh
@@ -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/."