Added composition.printRunningHost() and used it to encapsulate definition files. Changed current-host to running-host.

This commit is contained in:
m8in
2026-06-24 19:59:29 +02:00
parent 8044d776d8
commit 423d1c38e9
4 changed files with 39 additions and 20 deletions
@@ -5,14 +5,14 @@ if [ $(id -u) -ne 0 ]; then
fi
source /cis/core/base.module.sh
base.loadModule composition
function setup() {
local _COMPOSITION _COMPOSITIONS_FOLDER _CURRENT_HOST_FILE _SYNC_HOSTS_FILE
local _COMPOSITION _COMPOSITIONS_FOLDER _SYNC_HOSTS_FILE
_COMPOSITION="${1}"
_COMPOSITIONS_FOLDER="${CIS[DOMAINDEFINITIONS]}compositions/"
_CURRENT_HOST_FILE="${_COMPOSITIONS_FOLDER}${_COMPOSITION}/current-host"
_SYNC_HOSTS_FILE="${_COMPOSITIONS_FOLDER}${_COMPOSITION}/composition-sync-hosts"
readonly _COMPOSITION _COMPOSITIONS_FOLDER
@@ -20,7 +20,7 @@ function setup() {
echo
echo "No folder for your defined composition settings found: ${_COMPOSITIONS_FOLDER}"
echo "Please create it and add your custom composition settings in there, following this convention:"
echo " 1.) './NAME_OF_THE_COMPOSITION/current-host' containing one line with the FQDN of the host running the composition."
echo " 1.) './NAME_OF_THE_COMPOSITION/running-host' containing one line with the FQDN of the host running the composition."
echo " 2.) './NAME_OF_THE_COMPOSITION/composition-sync-hosts' containing a list of hosts receiving the composition, one host with its FQDN per line."
echo
@@ -29,9 +29,8 @@ function setup() {
&& echo
[ -n "${_COMPOSITION}" ] \
&& [ -f "${_CURRENT_HOST_FILE}" ] \
&& echo "Current defined host to run composition '${_COMPOSITION}' is:" \
&& cat "${_CURRENT_HOST_FILE}" \
&& composition.printRunningHost "${_COMPOSITION}" \
&& echo
[ -n "${_COMPOSITION}" ] \
+1 -2
View File
@@ -92,8 +92,7 @@ function receive() {
local _RECEIVERHOST _COMPOSITION _SOURCEHOST _SSH_PORT _SSH_COMMAND _SEND_SCRIPT _ZFS_BRANCH _ZFS
_COMPOSITION="${1:?"receive(): Missing first parameter COMPOSITION"}"
_RECEIVERHOST="${CIS[HOST]:?"Missing CIS_HOST"}"
_SOURCEHOST=$(head -n 1 "${CIS[DOMAINDEFINITIONS]:?"Missing CIS_DOMAINDEFINITIONS"}compositions/${_COMPOSITION}/current-host" 2> /dev/null)
base.set _SOURCEHOST "${_SOURCEHOST}" '^[a-zA-Z0-9][a-zA-Z0-9.-]*$'
base.set _SOURCEHOST "$(composition.printRunningHost "${_COMPOSITION}")" '^[a-zA-Z0-9][a-zA-Z0-9.-]*$'
_SSH_PORT=$(head -n 1 "${CIS[DOMAINDEFINITIONS]:?"Missing CIS_DOMAINDEFINITIONS"}compositions/${_COMPOSITION}/ssh-port" 2> /dev/null)
base.set _SSH_PORT "${_SSH_PORT:-22}" '^[1-9][0-9]{1,4}$'
_SSH_COMMAND="ssh -p ${_SSH_PORT} -o ConnectTimeout=20 -o ServerAliveInterval=15 -C composition-sync@${_SOURCEHOST}"
+5
View File
@@ -91,6 +91,11 @@ function snapshot() {
if [ -n "${_ZFS}" ]; then
(
flock -n 9 || return 1
! composition.shouldRunOnThisHost "${_COMPOSITION}" \
&& printf -- "ZFS will be skipped, because this host '%b' is not running the composition:\n" "${CIS[HOST]}" >&2 \
&& printf -- " - Composition : %b\n" "${_COMPOSITION}" >&2 \
&& printf -- " - Running host: %b\n" "$(composition.printRunningHost "${_COMPOSITION}")" >&2 \
&& continue
case "${_MODE:?"Missing MODE"}" in
MINUTELY) zfs snapshot "${_ZFS}@SNAPMINUTELY_${_MINUTE}" 2> /dev/null \