Skip to content

Commit

Permalink
fix: šŸ› get_target_file to accept 'common' or current hostname in fileā€¦
Browse files Browse the repository at this point in the history
ā€¦ path

Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Aug 31, 2022
1 parent ec2b28f commit 4511484
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 8 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ main_dir()
dirname "$(readlink -f "${BASH_SOURCE}")"
}

config_dir()
{
echo "$(main_dir)/config"
}

config_copy_dir()
{
echo "$(main_dir)/config/copy"
Expand Down Expand Up @@ -64,12 +69,9 @@ find_files()
get_target_file()
{
local sourcefile="$1"

if [[ "${sourcefile}" =~ \/common ]]; then
echo "${sourcefile/*\/common/}"
else
echo "${sourcefile/*\/${HOSTNAME}/}"
fi
local configdir="$(config_dir)"

echo "${sourcefile}" | sed -r "s/${configdir//\//\\\/}\/[^\/]+\/(common|${HOSTNAME})//"
}

ensure_parent_dir()
Expand Down
14 changes: 14 additions & 0 deletions tests/fix-get_target_file-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
. "$(main_dir)"/install.sh

##
path="$(main_dir)/config/copy/common/some/path/with/common/inside/file.config"
expected="/some/path/with/common/inside/file.config"

assert_equals "${expected}" "$(get_target_file "${path}")"

##
export HOSTNAME="hostname1"
path="$(main_dir)/config/copy/${HOSTNAME}/some/path/with/${HOSTNAME}/inside/file.config"
expected="/some/path/with/${HOSTNAME}/inside/file.config"

assert_equals "${expected}" "$(get_target_file "${path}")"

0 comments on commit 4511484

Please sign in to comment.