From 9230cc1b7320786a62d0c35b3393f645fc22e06f Mon Sep 17 00:00:00 2001 From: Martin Berghaus Date: Tue, 8 Apr 2025 22:29:39 +0200 Subject: [PATCH] removed use of dirname --- core/addToCrontabEveryHour.sh | 3 +-- core/ensureUsageOfDefinitions.sh | 4 ++-- core/printCisRoot.sh | 3 +-- core/printOwnDomain.sh | 3 +-- script/check/runAllChecks.sh | 5 ++++- setupCoreOntoThisHost.sh | 2 +- updateRepositories.sh | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/addToCrontabEveryHour.sh b/core/addToCrontabEveryHour.sh index 0c35626..e7e7218 100755 --- a/core/addToCrontabEveryHour.sh +++ b/core/addToCrontabEveryHour.sh @@ -7,8 +7,7 @@ # Folders always ends with an tailing '/' _SCRIPT="$(readlink -f "${0}" 2> /dev/null)" -_CORE_SCRIPTS="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/" -_CIS_ROOT="$(dirname ${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"} 2> /dev/null)/" +_CIS_ROOT="${_SCRIPT%%/core/*}/" #Removes longest matching pattern '/core/*' from the end # Note that an unprivileged user can use this script successfully, # if no user has to be added to the host because it already exists. diff --git a/core/ensureUsageOfDefinitions.sh b/core/ensureUsageOfDefinitions.sh index 2dcdcca..05073e3 100755 --- a/core/ensureUsageOfDefinitions.sh +++ b/core/ensureUsageOfDefinitions.sh @@ -126,8 +126,8 @@ function ensureUsageOfDefinitions() { _DEFINITIONS="$(printIfEqual "${_DEFINITIONS}" "${_CIS_ROOT:?"Missing ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/")" - _CURRENT_FOLDER="$(dirname "${2:?"Missing second parameter CURRENT_FULLFILE"}")" - _CURRENT_FOLDER="${_CURRENT_FOLDER%/}/" #Removes shortest matching pattern '/' from the end + _CURRENT_FULLFILE="${2:?"Missing second parameter CURRENT_FULLFILE"}" + _CURRENT_FOLDER="${_CURRENT_FULLFILE%/*}/" #Removes shortest matching pattern '/*' from the end ! [ -d "${_CURRENT_FOLDER}" ] \ && echo "FAIL: The folder cannot be read: ("$(readlink -f ${0})")" \ && echo " - '${_CURRENT_FOLDER}'" \ diff --git a/core/printCisRoot.sh b/core/printCisRoot.sh index 456018e..67bc2db 100755 --- a/core/printCisRoot.sh +++ b/core/printCisRoot.sh @@ -1,8 +1,7 @@ #!/bin/bash _SCRIPT="$(readlink -f "${0}" 2> /dev/null)" -_SCRIPT_FOLDER="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/" -_CIS_ROOT="$(dirname ${_SCRIPT_FOLDER:?"Missing SCRIPT_FOLDER"} 2> /dev/null)/" +_CIS_ROOT="${_SCRIPT%%/core/*}/" #Removes longest matching pattern '/core/*' from the end [ -d "${_CIS_ROOT}" ] \ && [ -d "${_CIS_ROOT}definitions/" ] \ diff --git a/core/printOwnDomain.sh b/core/printOwnDomain.sh index db1ee82..a5e712d 100755 --- a/core/printOwnDomain.sh +++ b/core/printOwnDomain.sh @@ -7,8 +7,7 @@ # Folders always ends with an tailing '/' _SCRIPT="$(readlink -f "${0}" 2> /dev/null)" -_CORE_SCRIPTS="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/" -_CIS_ROOT="$(dirname ${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"} 2> /dev/null)/" +_CIS_ROOT="${_SCRIPT%%/core/*}/" #Removes longest matching pattern '/core/*' from the end _OVERRIDE_DOMAIN_FILE="${_CIS_ROOT:?"Missing CIS_ROOT"}overrideOwnDomain" # There has to be one dot at least. diff --git a/script/check/runAllChecks.sh b/script/check/runAllChecks.sh index 50e95f2..246dd9f 100755 --- a/script/check/runAllChecks.sh +++ b/script/check/runAllChecks.sh @@ -1,6 +1,9 @@ #!/bin/bash -_CIS_ROOT="$($(dirname $(readlink -f ${0}))/../../core/printCisRoot.sh)" +_SCRIPT="$(readlink -f "${0}" 2> /dev/null)" + +# Folders always ends with an tailing '/' +_CIS_ROOT="${_SCRIPT%%/script/check/*}/" #Removes longest matching pattern '/script/check/*' from the end _SCRIPT_PATH="${_CIS_ROOT:?"Missing CIS_ROOT"}script/" _OWN_DOMAIN="$(${_CIS_ROOT}core/printOwnDomain.sh)" _OWN_DEFINITIONS="${_CIS_ROOT}definitions/${_OWN_DOMAIN:?"Missing OWN_DOMAIN"}/" diff --git a/setupCoreOntoThisHost.sh b/setupCoreOntoThisHost.sh index 0675dcf..c7e5d82 100755 --- a/setupCoreOntoThisHost.sh +++ b/setupCoreOntoThisHost.sh @@ -8,7 +8,7 @@ # Folders always ends with an tailing '/' _SETUP="$(readlink -f "${0}" 2> /dev/null)" -_CIS_ROOT="$(dirname ${_SETUP:?"Missing SETUP"} 2> /dev/null)/" +_CIS_ROOT="${_SETUP%/setupCoreOntoThisHost.sh}/" #Removes shortest matching pattern '/setupCoreOntoThisHost.sh' from the end _CORE_SCRIPTS="${_CIS_ROOT:?"Missing CIS_ROOT"}core/" diff --git a/updateRepositories.sh b/updateRepositories.sh index 179800b..bbad32e 100755 --- a/updateRepositories.sh +++ b/updateRepositories.sh @@ -22,9 +22,9 @@ function update_repositories() { local _CIS_ROOT _DEFINITIONS _DOMAIN _MODE _STATES _UPDATE_REPOSITORIES _UPDATE_REPOSITORIES="$(readlink -f "${0}" 2> /dev/null)" + _CIS_ROOT="${_UPDATE_REPOSITORIES%/updateRepositories.sh}/" #Removes shortest matching pattern '/updateRepositories.sh' from the end _MODE="${1:-"--core"}" - _CIS_ROOT="$(dirname ${_UPDATE_REPOSITORIES:?"Missing UPDATE_REPOSITORIES"} 2> /dev/null || echo "/cis")/" - _DOMAIN="$(${_CIS_ROOT:?"Missing CIS_ROOT"}/core/printOwnDomain.sh)" + _DOMAIN="$(${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh)" _DEFINITIONS="${_CIS_ROOT}definitions/${_DOMAIN:?"Missing DOMAIN from file: ${_CIS_ROOT}domainOfHostOwner"}/" _STATES="${_CIS_ROOT}states/${_DOMAIN:?"Missing DOMAIN from file: ${_CIS_ROOT}domainOfHostOwner"}/" readonly _CIS_ROOT _DEFINITIONS _DOMAIN _MODE _STATES _UPDATE_REPOSITORIES