From 1a2456da05b5edd011a436e6ae7376b8aa575a95 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Thu, 13 Sep 2018 13:40:41 +0200 Subject: [PATCH] TT#37257 Structure the code inside scripts/services for further refactoring Change-Id: Iaba999afc50f9ac4588e3129d4466ac0ad9cc02e --- scripts/services | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/scripts/services b/scripts/services index d5412ed2..f8aab2c9 100755 --- a/scripts/services +++ b/scripts/services @@ -113,6 +113,28 @@ systed_daemon_reload_preset() { fi } +is_absolute_path() { + local dir=$1 + + if [[ ! "${dir}" =~ ^/ ]] ; then + log_error "${dir} is not an absolute path" + return 1 + fi + + return 0 +} + +is_non_git_folder() { + local dir=$1 + + if [[ ! -d "${dir}/.git" ]] ; then + log_info "${dir} has no support of .services" + return 1 + fi + + return 0 +} + # main script DRYRUN='false' @@ -132,15 +154,9 @@ TMPFILE="$(mktemp)" log_debug "TMPFILE = $TMPFILE" for dir in ${CONFIG_POOL} ; do - if ! [[ "${dir}" =~ ^/ ]] ; then - log_error "${dir} is not an absolute path" - continue - fi + is_absolute_path "${dir}" || continue + is_non_git_folder "${dir}" || continue pushd "${dir}" >/dev/null - if [ ! -d .git ] ; then - log_info "$dir has no support of .services" - continue - fi for file in $(git status --porcelain | sed 's/^...//') ; do if [ -r "$file" ] && [ -r "${SERVICES_POOL_BASE}/${dir}/${file}".services ] ; then log_debug "unifyer ${SERVICES_POOL_BASE}/${dir}/${file}.services"