mirror of
https://github.com/m8tin/cis.git
synced 2026-08-01 11:47:31 +02:00
Module composition improved
This commit is contained in:
@@ -9,13 +9,11 @@ function composition.printAll() {
|
|||||||
_CURRENTHOST_FILE="current-host"
|
_CURRENTHOST_FILE="current-host"
|
||||||
readonly _COMPOSITIONS _CURRENTHOST_FILE
|
readonly _COMPOSITIONS _CURRENTHOST_FILE
|
||||||
|
|
||||||
local _composition
|
ls -1 "${_COMPOSITIONS}"*/"${_CURRENTHOST_FILE}" | while read -r _CURRENTHOST_FILE_PATH; do
|
||||||
for _composition in "${_COMPOSITIONS}"*/; do
|
# Like dirname: removes tailing '/${_CURRENTHOST_FILE}'
|
||||||
if [ -f "${_composition}${_CURRENTHOST_FILE}" ]; then
|
local _COMPOSITION="${_CURRENTHOST_FILE_PATH%/${_CURRENTHOST_FILE}}"
|
||||||
_composition="${_composition%/}"
|
# Like basename
|
||||||
_composition="${_composition##*/}"
|
echo "${_COMPOSITION##*/}"
|
||||||
echo "${_composition}"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,33 +23,52 @@ function composition.printAllRunningOnThisHost() {
|
|||||||
_CURRENTHOST_FILE="current-host"
|
_CURRENTHOST_FILE="current-host"
|
||||||
readonly _COMPOSITIONS _CURRENTHOST_FILE
|
readonly _COMPOSITIONS _CURRENTHOST_FILE
|
||||||
|
|
||||||
local _composition
|
grep -l -F "${CIS[HOST]}" "${_COMPOSITIONS}"*/"${_CURRENTHOST_FILE}" | while read -r _CURRENTHOST_FILE_PATH; do
|
||||||
for _composition in "${_COMPOSITIONS}"*/; do
|
# Like dirname: removes tailing '/${_CURRENTHOST_FILE}'
|
||||||
if grep -q -F "${CIS[HOST]}" "${_composition}${_CURRENTHOST_FILE}"; then
|
local _COMPOSITION="${_CURRENTHOST_FILE_PATH%/${_CURRENTHOST_FILE}}"
|
||||||
_composition="${_composition%/}"
|
# Like basename
|
||||||
_composition="${_composition##*/}"
|
echo "${_COMPOSITION##*/}"
|
||||||
echo "${_composition}"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function composition.printAllWhereThisHostSyncs() {
|
function composition.printAllWhereThisHostSyncs() {
|
||||||
local _COMPOSITIONS _CURRENTHOST_FILE _SYNCHOST_FILE
|
local _COMPOSITIONS _CURRENTHOST_FILE _SYNCHOSTS_FILE
|
||||||
_COMPOSITIONS="${CIS[DOMAINDEFINITIONS]:?"Missing CIS_DOMAINDEFINITIONS"}compositions/"
|
_COMPOSITIONS="${CIS[DOMAINDEFINITIONS]:?"Missing CIS_DOMAINDEFINITIONS"}compositions/"
|
||||||
_CURRENTHOST_FILE="current-host"
|
_CURRENTHOST_FILE="current-host"
|
||||||
_SYNCHOST_FILE="composition-sync-hosts"
|
_SYNCHOSTS_FILE="composition-sync-hosts"
|
||||||
readonly _COMPOSITIONS _CURRENTHOST_FILE _SYNCHOST_FILE
|
readonly _COMPOSITIONS _CURRENTHOST_FILE _SYNCHOSTS_FILE
|
||||||
|
|
||||||
|
grep -lF "${CIS[HOST]}" "${_COMPOSITIONS}"*/"${_SYNCHOSTS_FILE}" | while read -r _SYNCHOSTS_FILE_PATH; do
|
||||||
|
|
||||||
|
# Like dirname: removes tailing '/${_SYNCHOSTS_FILE}'
|
||||||
|
local _COMPOSITION="${_SYNCHOSTS_FILE_PATH%/${_SYNCHOSTS_FILE}}"
|
||||||
|
|
||||||
local _composition
|
|
||||||
for _composition in "${_COMPOSITIONS}"*/; do
|
|
||||||
if grep -q -F "${CIS[HOST]}" "${_composition}${_CURRENTHOST_FILE}"; then
|
|
||||||
# This host either runs the composition or syncs it.
|
# This host either runs the composition or syncs it.
|
||||||
continue
|
# If there is no CURRENTHOST_FILE than the definition is invalid and should not be synced.
|
||||||
fi
|
[ -f "${_COMPOSITION}/${_CURRENTHOST_FILE}" ] \
|
||||||
if grep -q -F "${CIS[HOST]}" "${_composition}${_SYNCHOST_FILE}"; then
|
&& grep -q -v -F "${CIS[HOST]}" "${_COMPOSITION}/${_CURRENTHOST_FILE}" \
|
||||||
_composition="${_composition%/}"
|
&& echo "${_COMPOSITION##*/}"
|
||||||
_composition="${_composition##*/}"
|
|
||||||
echo "${_composition}"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Check if this module was started correctly using source
|
||||||
|
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
|
||||||
|
# Script was executed directly
|
||||||
|
echo "FAILURE: you are using this module 'composition.module.sh' in a wrong way."
|
||||||
|
echo " It is intended as a utility library and should not be called directly."
|
||||||
|
echo
|
||||||
|
echo "Usage: Call this module at the beginning of your script e.g. like this:"
|
||||||
|
echo
|
||||||
|
echo ' #!/bin/bash'
|
||||||
|
echo ' source /cis/core/base.module.sh'
|
||||||
|
echo
|
||||||
|
echo ' #Loads this module'
|
||||||
|
echo ' base.loadModule composition'
|
||||||
|
echo
|
||||||
|
echo "Now you can use the functions provided by this module inside your script:"
|
||||||
|
echo "-------------------------------------------------------------------------"
|
||||||
|
declare -F | grep "composition." | cut -d" " -f3
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user