mirror of
https://github.com/m8tin/cis.git
synced 2026-06-02 14:56:58 +02:00
usage of printf improved, format and ensuring root privileges for setup scripts now is more reliable
This commit is contained in:
+3
-3
@@ -161,8 +161,8 @@ function prepare.setPATH() {
|
|||||||
function base.abort() {
|
function base.abort() {
|
||||||
# Minimalmode in case of emergency
|
# Minimalmode in case of emergency
|
||||||
[[ "${COLOR[SET]:+isset}" != "isset" ]] \
|
[[ "${COLOR[SET]:+isset}" != "isset" ]] \
|
||||||
&& printf %b "\nScript aborted during preparation (State: '${CIS[SET]:-""}')!\n" >&2 \
|
&& printf "\n%b\n" "Script aborted during preparation (State: '${CIS[SET]:-""}')!" >&2 \
|
||||||
&& printf %b " ${@}\n\n" >&2 \
|
&& printf " %b\n\n" "${@}" >&2 \
|
||||||
&& exit 1
|
&& exit 1
|
||||||
|
|
||||||
local _FULLSCRIPTNAME=$(readlink -e "${0}" 2> /dev/null)
|
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 "Content of array CIS: (all folders end with an tailing '/')"
|
||||||
echo "-----------------------------------------------------------"
|
echo "-----------------------------------------------------------"
|
||||||
for _KEY in "${!CIS[@]}"; do
|
for _KEY in "${!CIS[@]}"; do
|
||||||
printf " %s\n" "CIS[${_KEY}]: ${CIS[${_KEY}]}"
|
printf " %s: %s\n" "CIS[${_KEY}]" "${CIS[${_KEY}]}"
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
[ "$(id -u)" != "0" ] \
|
sudo "${0}" && exit 0
|
||||||
&& sudo "${0}" \
|
exit 1
|
||||||
&& exit 0
|
fi
|
||||||
|
|
||||||
source /cis/core/base.module.sh
|
source /cis/core/base.module.sh
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
[ "$(id -u)" != "0" ] \
|
sudo "${0}" && exit 0
|
||||||
&& sudo "${0}" \
|
exit 1
|
||||||
&& exit 0
|
fi
|
||||||
|
|
||||||
source /cis/core/base.module.sh
|
source /cis/core/base.module.sh
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source /cis/core/base.module.sh
|
source /cis/core/base.module.sh
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
sudo "${0}" && exit 0
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
[ "$(id -u)" != "0" ] \
|
source /cis/core/base.module.sh
|
||||||
&& 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"}/"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function checkPreconditions() {
|
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
|
&& 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 "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 "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
|
echo
|
||||||
@@ -30,11 +27,12 @@ function checkPreconditions() {
|
|||||||
|
|
||||||
|
|
||||||
function printSelectedDefinition() {
|
function printSelectedDefinition() {
|
||||||
local _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
|
local _MONITOR_DIR _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
|
||||||
_FILE_DEFINED_DOMAIN="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/${1:?"Missing CURRENT_FULLFILE"}"
|
_MONITOR_DIR="${CIS[DOMAINDEFINITIONS]?"Missing CIS_DOMAINDEFINITIONS"}monitor/"
|
||||||
_FILE_DEFINED_DEFAULT="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/default/monitor/${1:?"Missing CURRENT_FULLFILE"}"
|
_FILE_DEFINED_DOMAIN="${_MONITOR_DIR:?"Missing MONITOR_DIR"}${1:?"Missing CURRENT_FULLFILE"}"
|
||||||
_SCRIPT_DEFINED_DEFAULT="${_CIS_ROOT:?"Missing CIS_ROOT"}script/monitor/${1:?"Missing CURRENT_FULLFILE"}"
|
_FILE_DEFINED_DEFAULT="${CIS[DEFAULTDEFINITIONS]}monitor/${1:?"Missing CURRENT_FULLFILE"}"
|
||||||
readonly _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT _SCRIPT_DEFINED_DEFAULT
|
_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}" ] \
|
[ -s "${_FILE_DEFINED_DOMAIN}" ] \
|
||||||
&& echo "${_FILE_DEFINED_DOMAIN}" \
|
&& echo "${_FILE_DEFINED_DOMAIN}" \
|
||||||
|
|||||||
@@ -1,25 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
sudo "${0}" && exit 0
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
[ "$(id -u)" != "0" ] \
|
source /cis/core/base.module.sh
|
||||||
&& 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"}/"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "Setup the user and permission to enable the monitoring this host ... " \
|
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 \
|
&& echo \
|
||||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}defineAuthorizedKeysOfUser.sh" "${_DEFINITIONS}" monitoring \
|
&& "${CIS[COREROOT]:?"Missing CIS_COREROOT"}defineAuthorizedKeysOfUser.sh" "${CIS[DOMAINDEFINITIONS]}" monitoring \
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
||||||
|
source /cis/core/base.module.sh
|
||||||
|
|
||||||
[ "$(id -u)" != "0" ] \
|
|
||||||
&& sudo "${0}" "${1}" \
|
|
||||||
&& exit 0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user