--- /dev/null
+#!/bin/bash
+
+PROG_NAME=$(basename $0)
+
+HVRSYNC_CONF=${HOME}/.hv-rsync.conf
+
+print_usage()
+{
+ echo "${PROG_NAME} -- synchronisation serveur RSYNC"
+ echo "Usage: ${PROG_NAME} [OPTIONS...] MODE"
+ echo
+ echo "MODE:"
+ echo " push"
+ echo " pull"
+ echo " diff"
+ echo
+ echo "Options:"
+ echo " -h display this help and exit"
+ echo
+}
+
+while getopts "h" flag ;do
+ case ${flag} in
+ h)
+ print_usage
+ exit 0
+ ;;
+ ?)
+ echo "${PROG_NAME}: Invalid option: ${OPTARG}."
+ echo "Try \`${PROG_NAME} -h' for more information."
+ exit 1
+ ;;
+ esac
+done
+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."
+ exit 1
+fi
+
+mode="${1}"
+
+case "${mode}" in
+ push|pull|diff)
+ # Valid
+ ;;
+ *)
+ echo "Mode invalide"
+ print_usage
+ exit 1
+ ;;
+esac
+
+if [ ! -f ${HVRSYNC_CONF} ]; then
+ echo "Fichier de configuration manquant: ${HVRSYNC_CONF}"
+ exit 1
+fi
+
+source ${HVRSYNC_CONF}
+
+# rsync options:
+# -a: sync recursively and preserves symbolic links, special and device
+# files, modification times, groups, owners, and permissions.
+# -n: dry-run
+
+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}"
+ exit 1
+ fi
+
+ echo "Diff (push) for folder ${RSYNC_REMOTE_DIR}/${f}:"
+
+ rsync -avun --delete \
+ "${RSYNC_LOCAL_DIR}/${f}/" \
+ ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}" | \
+ grep "^deleting "
+
+ echo "Diff (pull) for folder ${RSYNC_REMOTE_DIR}/${f}:"
+
+ rsync -avun --delete \
+ ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \
+ "${RSYNC_LOCAL_DIR}/${f}" | \
+ grep "^deleting "
+ elif [ x"${mode}" = x"pull" ]; then
+ echo "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}:"
+ ssh ${RSYNC_USER}@${RSYNC_SERVER} "mkdir -p ${RSYNC_REMOTE_DIR}/${f}"
+ rsync -avu --delete --progress \
+ ${RSYNC_LOCAL_DIR}/${f}/ \
+ ${RSYNC_USER}@${RSYNC_SERVER}:${RSYNC_REMOTE_DIR}/${f}
+ fi
+done