From b0c49c37799dc4ef3b5b7c827d805807fa8762f4 Mon Sep 17 00:00:00 2001 From: Martin Berghaus Date: Sat, 22 Mar 2025 19:45:15 +0100 Subject: [PATCH] Refactoring --- core/addAndCheckGitRepository.sh | 8 ++++---- core/addNormalUser.sh | 6 +++--- core/addToCrontabEveryHour.sh | 6 +++--- core/defineAuthorizedKeysOfUser.sh | 6 +++--- core/ensureUsageOfDefinitions.sh | 4 ++-- setupCoreOntoThisHost.sh | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/addAndCheckGitRepository.sh b/core/addAndCheckGitRepository.sh index a1f0275..68d03cc 100755 --- a/core/addAndCheckGitRepository.sh +++ b/core/addAndCheckGitRepository.sh @@ -75,11 +75,11 @@ function printRepository(){ # Note that an unprivileged user can use this script successfully, # if no user has to be added to the host because it already exists. function addAndCheckGitRepository() { - local _FOLDER _REPOSITORY + local _FOLDER _REPOSITORY _RIGHTS _FOLDER="${1:?"Missing first parameter FOLDER"}" - _REPOSITORY="$(printRepository "${_FOLDER}" "${2}")" - _RIGHTS="${3:?"Missing third parameter RIGHTS: (readonly, writable) "}" - readonly _FOLDER _REPOSITORY + _RIGHTS="${2:?"Missing third parameter RIGHTS: (readonly, writable) "}" + _REPOSITORY="$(printRepository "${_FOLDER}" "${3}")" + readonly _FOLDER _REPOSITORY _RIGHTS echo \ && cloneOrPull "${_FOLDER}" "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \ diff --git a/core/addNormalUser.sh b/core/addNormalUser.sh index 752a4fa..7582033 100755 --- a/core/addNormalUser.sh +++ b/core/addNormalUser.sh @@ -29,9 +29,9 @@ function addNormalUser() { && echo " - existing home directories were taken over" \ && return 0 - echo "FAIL: The user could not be created: ("$(readlink -f ${0})")" - echo " - '${_USER}'" - echo " - due to an error or insufficient rights." + echo "FAIL: The user could not be created: ("$(readlink -f ${0})")" >&2 + echo " - '${_USER}'" >&2 + echo " - due to an error or insufficient rights." >&2 return 1 } diff --git a/core/addToCrontabEveryHour.sh b/core/addToCrontabEveryHour.sh index 89c5f47..0c35626 100755 --- a/core/addToCrontabEveryHour.sh +++ b/core/addToCrontabEveryHour.sh @@ -41,9 +41,9 @@ function addToCrontabEveryHour() { && echo " - '${_STRING}'" \ && return 0 - echo "FAIL: Entry could not be registered to crontab: ("$(readlink -f ${0})")" - echo " - '${_STRING:?"Missing CRON_STRING"}'" - echo " - due to an error or insufficient rights." + echo "FAIL: Entry could not be registered to crontab: ("$(readlink -f ${0})")" >&2 + echo " - '${_STRING:?"Missing CRON_STRING"}'" >&2 + echo " - due to an error or insufficient rights." >&2 return 1 } diff --git a/core/defineAuthorizedKeysOfUser.sh b/core/defineAuthorizedKeysOfUser.sh index 16705e7..6b9cb23 100755 --- a/core/defineAuthorizedKeysOfUser.sh +++ b/core/defineAuthorizedKeysOfUser.sh @@ -44,9 +44,9 @@ function prepareFolder() { && echo " - '${_SSH_FOLDER}'" \ && return 0 - echo "FAIL: The ssh folder could not be prepared: ("$(readlink -f ${0})")" - echo " - '${_SSH_FOLDER}'" - echo " - due to an error or insufficient rights." + echo "FAIL: The ssh folder could not be prepared: ("$(readlink -f ${0})")" >&2 + echo " - '${_SSH_FOLDER}'" >&2 + echo " - due to an error or insufficient rights." >&2 return 1 } diff --git a/core/ensureUsageOfDefinitions.sh b/core/ensureUsageOfDefinitions.sh index 6deb190..2dcdcca 100755 --- a/core/ensureUsageOfDefinitions.sh +++ b/core/ensureUsageOfDefinitions.sh @@ -196,8 +196,8 @@ function ensureUsageOfDefinitions() { && echo "- '${_DEFINED_FULLFILE}'" \ && return 0 - echo "FAIL: The definition could not be ensured: ("$(readlink -f ${0})")" - echo " - due to an error or insufficient rights." + echo "FAIL: The definition could not be ensured: ("$(readlink -f ${0})")" >&2 + echo " - due to an error or insufficient rights." >&2 return 1 } diff --git a/setupCoreOntoThisHost.sh b/setupCoreOntoThisHost.sh index dc69163..0675dcf 100755 --- a/setupCoreOntoThisHost.sh +++ b/setupCoreOntoThisHost.sh @@ -126,13 +126,13 @@ function addDefinition(){ [ "$(id -u)" == "0" ] \ && echo "Running setup as 'root' trying to add definition repository:" \ - && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" readonly \ + && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" readonly "${_REPOSITORY}" \ && echo " - definitions are usable for this host." \ && return 0 [ "$(id -u)" != "0" ] \ && echo "Running setup as 'user' trying to add definition repository:" \ - && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" writable \ + && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" writable "${_REPOSITORY}" \ && echo " - definitions are usable, as working copy." \ && return 0 @@ -148,14 +148,14 @@ function addState() { [ "$(id -u)" == "0" ] \ && echo "Running setup as 'root' trying to add state repository:" \ && echo \ - && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \ + && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" writable "${_REPOSITORY}" \ && echo " - states are usable for this host." \ && return 0 [ "$(id -u)" != "0" ] \ && echo "Running setup as 'user' trying to add state repository:" \ && echo \ - && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \ + && "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" writable "${_REPOSITORY}" \ && echo " - states are usable, as working copy." \ && return 0 @@ -208,8 +208,8 @@ function setup() { && setupCoreFunctionality "${_DEFINITIONS:?"Missing DEFINITIONS"}" \ && return 0 - echo "FAIL: setup is incomplete: ("$(readlink -f ${0})")" - echo " - due to an error or insufficient rights." + echo "FAIL: setup is incomplete: ("$(readlink -f ${0})")" >&2 + echo " - due to an error or insufficient rights." >&2 return 1 }