Checks extended to define own checks for all own hosts or a specific one.

This commit is contained in:
Martin Berghaus
2025-03-12 22:27:13 +01:00
parent 4943625351
commit 3d1ecf6fa8
26 changed files with 56 additions and 59 deletions

View File

@@ -1,12 +0,0 @@
#!/bin/bash
_CURRENT_ZFS='zpool1/persistent'
#Check if the tool 'zfs' is available, then
#retrieve the property 'mountpoint' from 'zpool1/persistent', without header and compare the result with 'none'
#Set with: 'zfs set mountpoint=none zpool1/persistent'
zfs version &> /dev/null \
&& [ "$(zfs get mountpoint -Ho value ${_CURRENT_ZFS})" == "none" ] \
&& exit 0
exit 1

View File

@@ -1,14 +0,0 @@
#!/bin/bash
_CURRENT_POOL='zpool1/persistent'
#Check if the tool 'zfs' is available, then
#retrieve the property 'recordsize' from 'zpool1/persistent', without header and compare the result with '16K'
#because this a 'recordsize' of '16K' matches to the needs of 'mariadb'.
#Set with: 'zfs set recordsize=16K zpool1/persistent'
zfs version &> /dev/null \
&& [ "$(zfs get recordsize -Ho value ${_CURRENT_POOL})" == "16K" ] \
&& exit 0
exit 1

View File

@@ -1,33 +0,0 @@
#!/bin/bash
_OWN_PATH="$(dirname $(readlink -f $0))"
function run_as_root() {
[ "0" == "$(id -u)" ] \
&& echo OK \
&& return 0
echo FAIL
return 1
}
function scripts_are_updateable_by_git() {
git -C "${_OWN_PATH:?"Missing OWN_PATH"}" pull > /dev/null 2>&1 \
&& echo OK \
&& return 0
echo FAIL
return 1
}
echo "PRECONDITION run as root: $(run_as_root)"
echo "PRECONDITION scripts are updateable by git: $(scripts_are_updateable_by_git)"
echo
echo "Check all:"
for _CURRENT_CHECK in ${_OWN_PATH}/checks/*.check.sh; do
_NAME="$(basename ${_CURRENT_CHECK} | cut -d'.' -f1)"
_CONTEXT="$(echo ${_NAME} | cut -d'_' -f1)"
_CHECK="$(echo ${_NAME} | cut -d'_' -f2- | tr '_' ' ')"
_RESULT="$("${_CURRENT_CHECK}" && echo OK || echo FAIL)"
echo " ${_CONTEXT^^} ${_CHECK}: ${_RESULT}"
done

56
script/check/runAllChecks.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/bash
_CIS_ROOT="$(../../core/printCisRoot.sh)"
_SCRIPT_PATH="${_CIS_ROOT:?"Missing CIS_ROOT"}script/"
_OWN_DOMAIN="$(../../core/printOwnDomain.sh)"
_OWN_DEFINITIONS="${_CIS_ROOT}definitions/${_OWN_DOMAIN:?"Missing OWN_DOMAIN"}/"
function run_as_root() {
[ "0" == "$(id -u)" ] \
&& echo OK \
&& return 0
echo FAIL
return 1
}
function scripts_are_updateable_by_git() {
git -C "${_SCRIPT_PATH:?"Missing SCRIPT_PATH"}" pull > /dev/null 2>&1 \
&& echo OK \
&& return 0
echo FAIL
return 1
}
function allChecks() {
local _CHECK_PATH _MODE_PATH
_CHECK_PATH="${1:?"allChecks(): Missing first parameter CHECK_PATH"}check/"
_MODE_PATH="${2:-all}/"
readonly _CHECK_PATH _MODE_PATH
echo " - ${_CHECK_PATH}host/${_MODE_PATH}*.check.sh"
[ "$(ls -1 ${_CHECK_PATH}host/${_MODE_PATH}*.check.sh 2> /dev/null | grep -cE '.*')" == "0" ] \
&& echo " nothing to do" \
&& return 0
for _CURRENT_CHECK in ${_CHECK_PATH}host/${_MODE_PATH}*.check.sh; do
_NAME="$(basename ${_CURRENT_CHECK} | cut -d'.' -f1)"
_CONTEXT="$(echo ${_NAME} | cut -d'_' -f1)"
_CHECK="$(echo ${_NAME} | cut -d'_' -f2- | tr '_' ' ')"
_RESULT="$("${_CURRENT_CHECK}" && echo OK || echo FAIL)"
echo " ${_CONTEXT^^} ${_CHECK}: ${_RESULT}"
done
}
echo "PRECONDITION run as root: $(run_as_root)"
echo "PRECONDITION scripts are updateable by git: $(scripts_are_updateable_by_git)"
echo
echo "Check all (common):"
allChecks "${_SCRIPT_PATH}"
echo "Check all (own):"
allChecks "${_OWN_DEFINITIONS}"
echo "Check this host:"
allChecks "${_OWN_DEFINITIONS}" "$(hostname -s)"