From 340d353b78fe3060d226e3d21d3815d021a7684d Mon Sep 17 00:00:00 2001 From: ge Date: Sat, 8 Oct 2022 19:39:07 +0300 Subject: [PATCH] add make_target_dirs --- src/lib/source.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/source.sh b/src/lib/source.sh index 7c8afbc..4d696c3 100644 --- a/src/lib/source.sh +++ b/src/lib/source.sh @@ -82,9 +82,20 @@ validate_targets() { __main_target="${file_targets[0]}" # Fail if __main_target's path is not a directory parse_uri "$__main_target" + __main_target_path="$path" + + # Make dirs if `make_target_dir` is set + if [ -n "$make_target_dir" ]; then + for file_target in "${file_targets[@]}"; do + parse_uri "$file_target" + mkdir -p "$path" + done + return 0 + fi + # shellcheck disable=SC2154 if [ -d "$path" ]; then - __main_target_path="$path" + : else echo "Error: $backup_script:" \ "Path '$path' from URI '$__main_target'" \ @@ -101,6 +112,8 @@ source_script() { local script="$1" + script="$(realpath "$script")" || true + if ! test -f "$script"; then echo "Error: No such file: $script" >&2; exit 1 fi @@ -112,7 +125,7 @@ source_script() { # Source script # shellcheck disable=SC1090 - if ! . "$(realpath "$script")"; then + if ! . "$script"; then echo "Error: Cannot source script: $script" >&2; exit 1; fi