about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-09-22 19:27:47 +0200
committerRobert Günzler <r@gnzler.io>2025-09-22 19:53:59 +0200
commit0e1acdfd6dd48a3721b42cf1b168bd79f45051f2 (patch)
tree1724bb7fb131a68a178acc9b376a89501b5c14c6
parent6acb361b5cf0355e70638840b3e9f69091e87cc8 (diff)
import s6-rc-compile wrapper
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rwxr-xr-xbin/sv8
-rwxr-xr-xbin/svtree-compile30
-rwxr-xr-xbin/svtree-run2
3 files changed, 35 insertions, 5 deletions
diff --git a/bin/sv b/bin/sv
index 868125f..9fa01ff 100755
--- a/bin/sv
+++ b/bin/sv
@@ -30,10 +30,10 @@ main() {
 	## db
 	##
 	reload | recompile)
-		export LIVEDIR="$l"
-		export STATEDIR="$confdir"
-		export SRCDIR="$confdir/src"
-		exec s6-rc-recompile
+		export LIVE_DIR="$l"
+		export STATE_DIR="$confdir"
+		export SOURCE_DIR="$confdir/src"
+		exec svtree-compile
 		;;
 
 	##
diff --git a/bin/svtree-compile b/bin/svtree-compile
new file mode 100755
index 0000000..3e8e63c
--- /dev/null
+++ b/bin/svtree-compile
@@ -0,0 +1,30 @@
+#!/bin/sh
+set -eu
+
+LIVE_DIR=${LIVE_DIR:-/run/s6-rc}
+STATE_DIR=${STATE_DIR:-/etc/s6-rc}
+SOURCE_DIR=${SOURCE_DIR:-/etc/s6-rc/src}
+
+new_dir="$STATE_DIR"/"_$(date +%s)"
+
+main() {
+        local old
+        old="$(find "$STATE_DIR" -maxdepth 1 -name '_[0-9]*' -print)"
+
+        # compile new db
+        s6-rc-compile "$new_dir" "$SOURCE_DIR"
+
+        # switch to new db (if there's an active tree)
+        test -e "$LIVE_DIR" && s6-rc-update -v2 -l "$LIVE_DIR" -b "$new_dir"
+
+        # swap current db
+        s6-ln -snf "$new_dir" "$STATE_DIR"/compiled
+
+        # cleanup old db
+        # NOTE: needs to be unquoted for expansion to work
+        rm -rf -- $old
+}
+
+command -v s6-ln >/dev/null 2>&1 || exit 1
+
+main || rm -rf "$new_dir"
diff --git a/bin/svtree-run b/bin/svtree-run
index 9424f39..521a2bc 100755
--- a/bin/svtree-run
+++ b/bin/svtree-run
@@ -6,7 +6,7 @@ importas -D "/run" -S XDG_RUNTIME_DIR
 envfile -I /opt/svtree/dirs.conf
 
 # compile s6-rc db
-foreground { s6-rc-recompile }
+foreground { /opt/svtree/bin/svtree-compile }
 
 # check that we have the db
 if { eltest -e ${COMPILED_DIR} }