From c95cc96a313a17c08b4292271da6cd901f8e0610 Mon Sep 17 00:00:00 2001 From: omer-musa-battal <34798379+omer-musa-battal@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:24:06 +0300 Subject: [PATCH] macOS compatibility for filesystem type checks updates #170, by introducing cases for different OSes. Also includes fixes for #172 and part of #181. --- rsync_tmbackup.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 1bc24ee..2efc89b 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -250,12 +250,24 @@ fn_test_file_exists_src() { fn_run_cmd_src "test -e '$1'" } +# Outputs 0 if given directory is not a type of FAT filesystem. +# Outputs greater than 0 otherwise. Has to be implemented for different OSes. fn_df_t_src() { - fn_run_cmd_src "df -T '${1}'" + OSTYPE_STR="$(fn_run_cmd_src 'echo ${OSTYPE}')" + case "${OSTYPE_STR}" in + linux*) fn_run_cmd_src "df -T '${1}' | awk 'NR==2' | awk '{print \$2}' | grep -c -i -e 'fat'" ;; + darwin*) fn_run_cmd_src "df -T msdos,exfat ${1} | awk 'NR==2' | grep -c -e '${1%/}'" ;; + *) echo 0 ;; # not implemented OSes, do not perform check. + esac } fn_df_t() { - fn_run_cmd "df -T '${1}'" + OSTYPE_STR="$(fn_run_cmd 'echo ${OSTYPE}')" + case "${OSTYPE_STR}" in + linux*) fn_run_cmd "df -T '${1}' | awk 'NR==2' | awk '{print \$2}' | grep -c -i -e 'fat'" ;; + darwin*) fn_run_cmd "df -T msdos,exfat ${1} | awk 'NR==2' | grep -c -e '${1%/}'" ;; + *) echo 0 ;; # not implemented OSes, do not perform check. + esac } # ----------------------------------------------------------------------------- @@ -369,7 +381,7 @@ if [ -n "$SSH_SRC_FOLDER" ]; then fi # Exit if source folder does not exist. -if ! fn_test_file_exists_src ${SRC_FOLDER}; then +if ! fn_test_file_exists_src "${SRC_FOLDER}"; then fn_log_error "Source folder \"${SRC_FOLDER}\" does not exist - aborting." exit 1 fi @@ -406,13 +418,12 @@ fi # If one of them is FAT, use the --modify-window rsync parameter # (see man rsync) with a value of 1 or 2. # -# The check is performed by taking the second row -# of the output of the first command. -if [[ "$(fn_df_t_src "${SRC_FOLDER}" | awk '{print $2}' | grep -c -i -e "fat")" -gt 0 ]]; then +# fn_df_t commands output 0 when disk is not FAT, and >0 otherwise. +if [[ "$(fn_df_t_src "${SRC_FOLDER}/")" -gt 0 ]]; then fn_log_info "Source file-system is a version of FAT." fn_log_info "Using the --modify-window rsync parameter with value 2." RSYNC_FLAGS="${RSYNC_FLAGS} --modify-window=2" -elif [[ "$(fn_df_t "${DEST_FOLDER}" | awk '{print $2}' | grep -c -i -e "fat")" -gt 0 ]]; then +elif [[ "$(fn_df_t "${DEST_FOLDER}/")" -gt 0 ]]; then fn_log_info "Destination file-system is a version of FAT." fn_log_info "Using the --modify-window rsync parameter with value 2." RSYNC_FLAGS="${RSYNC_FLAGS} --modify-window=2"