From 0e1acdfd6dd48a3721b42cf1b168bd79f45051f2 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 22 Sep 2025 19:27:47 +0200 Subject: import s6-rc-compile wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- bin/svtree-compile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 bin/svtree-compile (limited to 'bin/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" -- cgit 1.4.1