From 5310d5ae0f5a918d4e22b4ff06d4e2958a51a399 Mon Sep 17 00:00:00 2001 From: ge Date: Tue, 17 May 2022 00:25:40 +0300 Subject: [PATCH] fix: Add Path-only URI processing --- src/lib/backup.sh | 11 ++++++++++- src/lib/source.sh | 24 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/backup.sh b/src/lib/backup.sh index 304bea8..d07e3b7 100644 --- a/src/lib/backup.sh +++ b/src/lib/backup.sh @@ -27,6 +27,8 @@ process_source() { uri="$1" scheme="${uri%%:*}" + # Process Path-only URI + if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi echo -e "Processing source $uri ..." @@ -35,7 +37,7 @@ process_source() { mysql) handler='backup_mysql';; postgres) handler='backup_postgres';; sqlite) handler='backup_sqlite';; - *) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;; + *) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;; esac # Run handler function @@ -54,6 +56,8 @@ process_target() { uri="$1" scheme="${uri%%:*}" + # Process Path-only URI + if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi echo -e "Processing target $uri ..." @@ -118,6 +122,11 @@ backup_files() { exit 1 fi + if [[ "$src_path" == "$dst_path" ]]; then + echo "Error: Source and destination paths is the same: $src_path; $dst_path" >&2 + exit 1 + fi + # Exit if tar is not installed is_installed tar diff --git a/src/lib/source.sh b/src/lib/source.sh index 60e7116..9ee6cd3 100644 --- a/src/lib/source.sh +++ b/src/lib/source.sh @@ -29,9 +29,13 @@ validate_sources() { for uri in "${array[@]}"; do scheme="${uri%%:*}" + + # Process Path-only URI + if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi + case "$scheme" in file|mysql|postgres|sqlite) : ;; # do nothing, this is OK - *) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;; + *) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;; esac done } @@ -50,18 +54,22 @@ validate_targets() { for uri in "${array[@]}"; do scheme="${uri%%:*}" + + # Process Path-only URI + if [[ "$scheme" == "$uri" ]]; then scheme="file"; fi + case "$scheme" in file|ftp|sftp|rsync|s3|swift|sj|dav|davs) if [[ "$scheme" == file ]]; then file_targets+=("$uri") fi ;; - *) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;; + *) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;; esac done if [ "${#file_targets[@]}" -eq 0 ]; then - echo "Error: 'file' scheme is not set in targets." \ + echo -e "Error: $__user_script: 'file' scheme is not set in targets."\ "You must provide one or more targets with 'file' scheme." >&2 exit 1 else @@ -73,8 +81,8 @@ validate_targets() { if [ -d "$path" ]; then __main_target_path="$path" else - echo "Error: Path '$path' from URI '$__main_target'" \ - "is not directory or does not exists" >&2 + echo "Error: $__user_script: Path '$path' from URI '$__main_target'" \ + "does not exists or not a directory" >&2 exit 1 fi fi @@ -93,7 +101,7 @@ source_script() { # Dry run script, check syntax. See set(1p) if ! bash -n "$script"; then - echo Error: Please check your syntax >&2; exit 1 + echo Error: $__user_script: Please check your syntax >&2; exit 1 fi # Source script @@ -103,13 +111,13 @@ source_script() { if [[ "$sources" ]]; then validate_sources "${sources[@]}" else - echo Error: sources array is not set >&2; exit 1 + echo Error: $__user_script: sources array is not set >&2; exit 1 fi if [[ "$targets" ]]; then validate_targets "${targets[@]}" else - echo Error: targets array is not set >&2; exit 1 + echo Error: $__user_script: targets array is not set >&2; exit 1 fi }