usage of printf improved, format and ensuring root privileges for setup scripts now is more reliable

This commit is contained in:
m8in
2026-05-08 00:13:12 +02:00
parent 1c94a26710
commit ee114ee732
7 changed files with 40 additions and 52 deletions
+3 -3
View File
@@ -161,8 +161,8 @@ function prepare.setPATH() {
function base.abort() {
# Minimalmode in case of emergency
[[ "${COLOR[SET]:+isset}" != "isset" ]] \
&& printf %b "\nScript aborted during preparation (State: '${CIS[SET]:-""}')!\n" >&2 \
&& printf %b " ${@}\n\n" >&2 \
&& printf "\n%b\n" "Script aborted during preparation (State: '${CIS[SET]:-""}')!" >&2 \
&& printf " %b\n\n" "${@}" >&2 \
&& exit 1
local _FULLSCRIPTNAME=$(readlink -e "${0}" 2> /dev/null)
@@ -269,7 +269,7 @@ function base.printEnvironment() {
echo "Content of array CIS: (all folders end with an tailing '/')"
echo "-----------------------------------------------------------"
for _KEY in "${!CIS[@]}"; do
printf " %s\n" "CIS[${_KEY}]: ${CIS[${_KEY}]}"
printf " %s: %s\n" "CIS[${_KEY}]" "${CIS[${_KEY}]}"
done
return 0
}
@@ -1,8 +1,8 @@
#!/bin/bash
[ "$(id -u)" != "0" ] \
&& sudo "${0}" \
&& exit 0
if [ $(id -u) -ne 0 ]; then
sudo "${0}" && exit 0
exit 1
fi
source /cis/core/base.module.sh
@@ -1,8 +1,8 @@
#!/bin/bash
[ "$(id -u)" != "0" ] \
&& sudo "${0}" \
&& exit 0
if [ $(id -u) -ne 0 ]; then
sudo "${0}" && exit 0
exit 1
fi
source /cis/core/base.module.sh
-1
View File
@@ -1,5 +1,4 @@
#!/bin/bash
source /cis/core/base.module.sh
+17 -19
View File
@@ -1,25 +1,22 @@
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
sudo "${0}" && exit 0
exit 1
fi
[ "$(id -u)" != "0" ] \
&& sudo "${0}" \
&& exit 0
_SETUP="$(readlink -f "${0}" 2> /dev/null)"
# Folders always ends with an tailing '/'
_CIS_ROOT="${_SETUP%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
_DOMAIN="$("${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh")"
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/"
source /cis/core/base.module.sh
function checkPreconditions() {
[ -d "${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/checks" ] \
local _MONITOR_DIR
_MONITOR_DIR="${CIS[DOMAINDEFINITIONS]?"Missing CIS_DOMAINDEFINITIONS"}monitor/"
readonly _MONITOR_DIR
[ -d "${_MONITOR_DIR:?"Missing MONITOR_DIR"}checks" ] \
&& return 0
echo "No folder for your defined checks found: ${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/checks"
echo "No folder for your defined checks found: ${_MONITOR_DIR:?"Missing MONITOR_DIR"}checks"
echo "Please create it and add all your custom monitoring checks there, following this convention: 'NAME_OF_THE_CHECK.on'"
echo "A check has to be switched 'on' to be executed, so you can rename a check to 'NAME_OF_THE_CHECK.off' and it will be ignored."
echo
@@ -30,11 +27,12 @@ function checkPreconditions() {
function printSelectedDefinition() {
local _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
_FILE_DEFINED_DOMAIN="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/${1:?"Missing CURRENT_FULLFILE"}"
_FILE_DEFINED_DEFAULT="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/default/monitor/${1:?"Missing CURRENT_FULLFILE"}"
_SCRIPT_DEFINED_DEFAULT="${_CIS_ROOT:?"Missing CIS_ROOT"}script/monitor/${1:?"Missing CURRENT_FULLFILE"}"
readonly _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
local _MONITOR_DIR _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
_MONITOR_DIR="${CIS[DOMAINDEFINITIONS]?"Missing CIS_DOMAINDEFINITIONS"}monitor/"
_FILE_DEFINED_DOMAIN="${_MONITOR_DIR:?"Missing MONITOR_DIR"}${1:?"Missing CURRENT_FULLFILE"}"
_FILE_DEFINED_DEFAULT="${CIS[DEFAULTDEFINITIONS]}monitor/${1:?"Missing CURRENT_FULLFILE"}"
_SCRIPT_DEFINED_DEFAULT="${CIS[SCRIPTSROOT]}monitor/${1:?"Missing CURRENT_FULLFILE"}"
readonly _MONITOR_DIR _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
[ -s "${_FILE_DEFINED_DOMAIN}" ] \
&& echo "${_FILE_DEFINED_DOMAIN}" \
+7 -15
View File
@@ -1,25 +1,17 @@
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
sudo "${0}" && exit 0
exit 1
fi
[ "$(id -u)" != "0" ] \
&& sudo "${0}" \
&& exit 0
_SETUP="$(readlink -f "${0}" 2> /dev/null)"
# Folders always ends with an tailing '/'
_CIS_ROOT="${_SETUP%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
_CORE_SCRIPTS="${_CIS_ROOT:?"Missing CIS_ROOT"}core/"
_DOMAIN="$("${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh")"
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/"
source /cis/core/base.module.sh
echo "Setup the user and permission to enable the monitoring this host ... " \
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addNormalUser.sh" monitoring \
&& "${CIS[COREROOT]:?"Missing CIS_COREROOT"}addNormalUser.sh" monitoring \
&& echo \
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}defineAuthorizedKeysOfUser.sh" "${_DEFINITIONS}" monitoring \
&& "${CIS[COREROOT]:?"Missing CIS_COREROOT"}defineAuthorizedKeysOfUser.sh" "${CIS[DOMAINDEFINITIONS]}" monitoring \
&& exit 0
exit 1
+5 -6
View File
@@ -1,11 +1,10 @@
#!/bin/bash
source ${CUSTOM_CIS_ROOT:-/}./cis/core/base.module.sh
if [ $(id -u) -ne 0 ]; then
sudo "${0}" "${1}" && exit 0
exit 1
fi
[ "$(id -u)" != "0" ] \
&& sudo "${0}" "${1}" \
&& exit 0
source /cis/core/base.module.sh