]> Untitled Git - hvutilities.git/commitdiff
hv-rsync: use hvutilites log functions
authorHugo Villeneuve <hugo@hugovil.com>
Thu, 2 Apr 2026 21:36:45 +0000 (17:36 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 2 Apr 2026 23:34:04 +0000 (19:34 -0400)
Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
scripts/hv-rsync.sh

index 48845829a880fef9481bd3efcf962b5038c21ded..b93b654f3d7591be8145725cff45358970516208 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 
-PROG_NAME=$(basename $0)
+PROG_NAME="`readlink -e $0`"
+PROG_PATH=$(dirname ${PROG_NAME})
+source ${PROG_PATH}/hvutilities.sh
 
 HVRSYNC_CONF=${HOME}/.hv-rsync.conf
 
@@ -34,8 +36,8 @@ while getopts "l:h" flag ;do
             rsync_list="${OPTARG}"
             ;;
         ?)
-            echo "${PROG_NAME}: Invalid option: ${OPTARG}."
-            echo "Try \`${PROG_NAME} -h' for more information."
+            log_err "${PROG_NAME}: Invalid option: ${OPTARG}."
+            log_err "Try \`${PROG_NAME} -h' for more information."
             exit 1
             ;;
     esac
@@ -45,8 +47,8 @@ shift `expr "${OPTIND}" - 1`
 # `$#' now represents the number of arguments after the options.
 # `$1' is the first argument, etc.
 if [ ${#} -ne 1 ]; then
-    echo "${PROG_NAME}: mode manquant."
-    echo "Essayez \`${PROG_NAME} -h' pour plus d'informations."
+    log_err "${PROG_NAME}: mode manquant."
+    log_err "Essayez \`${PROG_NAME} -h' pour plus d'informations."
     exit 1
 fi
 
@@ -57,14 +59,14 @@ case "${mode}" in
         # Valid
         ;;
     *)
-        echo "Mode invalide"
+        log_err "Mode invalide"
         print_usage
         exit 1
         ;;
 esac
 
 if [ ! -f ${HVRSYNC_CONF} ]; then
-    echo "Fichier de configuration manquant: ${HVRSYNC_CONF}"
+    log_err "Fichier de configuration manquant: ${HVRSYNC_CONF}"
     exit 1
 fi
 
@@ -102,30 +104,30 @@ for f in ${rsync_list}; do
     if [ x"${mode}" = x"diff" ]; then
 
         if [ ! -d ${RSYNC_LOCAL_DIR}/${f} ]; then
-            echo "RĂ©pertoire local absent: ${RSYNC_LOCAL_DIR}/${f}"
+            log_err "RĂ©pertoire local absent: ${RSYNC_LOCAL_DIR}/${f}"
             exit 1
         fi
 
-        echo "Diff (push) for folder ${RSYNC_REMOTE_DIR}/${f}:"
+        log_info "Diff (push) for folder ${RSYNC_REMOTE_DIR}/${f}:"
         delete_target="REMOTE"
         rsync ${RSYNC_DIFF_OPTS} "${RSYNC_LOCAL_DIR}/${f}/" \
               ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}" | \
               rsync_itemize_parser
 
-        echo "Diff (pull) for folder ${RSYNC_REMOTE_DIR}/${f}:"
+        log_info "Diff (pull) for folder ${RSYNC_REMOTE_DIR}/${f}:"
         delete_target="LOCAL "
         rsync ${RSYNC_DIFF_OPTS} ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \
             "${RSYNC_LOCAL_DIR}/${f}" | \
             rsync_itemize_parser
 
     elif [ x"${mode}" = x"pull" ]; then
-        echo "RSYNC for folder ${RSYNC_REMOTE_DIR}/${f}:"
+        log_info "RSYNC for folder ${RSYNC_REMOTE_DIR}/${f}:"
         mkdir -p ${RSYNC_LOCAL_DIR}/${f}
         rsync -avu --delete --progress \
               ${RSYNC_USER}@${RSYNC_SERVER}:${RSYNC_REMOTE_DIR}/${f}/ \
               ${RSYNC_LOCAL_DIR}/${f}
     elif [ x"${mode}" = x"push" ]; then
-        echo "RSYNC for folder ${RSYNC_LOCAL_DIR}/${f}:"
+        log_info "RSYNC for folder ${RSYNC_LOCAL_DIR}/${f}:"
         ssh ${RSYNC_USER}@${RSYNC_SERVER} "mkdir -p ${RSYNC_REMOTE_DIR}/${f}"
         rsync -avu --delete --progress \
               ${RSYNC_LOCAL_DIR}/${f}/ \