From: Hugo Villeneuve Date: Thu, 2 Apr 2026 21:36:45 +0000 (-0400) Subject: hv-rsync: use hvutilites log functions X-Git-Url: http://gitweb.hugovil.com/sitemap.xml?a=commitdiff_plain;h=bc06fd68043ab46bb57bb551e9a0652900c62715;p=hvutilities.git hv-rsync: use hvutilites log functions Signed-off-by: Hugo Villeneuve --- diff --git a/scripts/hv-rsync.sh b/scripts/hv-rsync.sh index 4884582..b93b654 100755 --- a/scripts/hv-rsync.sh +++ b/scripts/hv-rsync.sh @@ -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}/ \