#!/bin/sh #----------------------------------------------------------------------------- # /var/install/bin/unison-tools-manual # # Copyright (c) 2005 Daniel Vogel # # Creation: 05.07.2005 dv # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #----------------------------------------------------------------------------- #include eislib . /var/install/include/eislib . /etc/config.d/unison PROG=/usr/bin/unison INDEX=$1 MANUAL="false" export UNISON=/var/lib/unison mail_result() { if [ -f /usr/sbin/sendmail ] then if [ -f /etc/config.d/mail ] then . /etc/config.d/mail smtp_qualify_domain="$SMTP_QUALIFY_DOMAIN" elif [ -f /var/install/config.d/vmail.sh ] then smtp_qualify_domain=$(/var/install/config.d/vmail.sh getdomain) else smtp_qualify_domain="$HOSTNAME" fi { echo "From: Unison " echo "To: Unison admin <$3>" echo "Subject: Unison: $1 of \"$2\" on \"$(hostname)\"" echo if [ -f /tmp/unison-pre-$$.log ] then cat /tmp/unison-pre-$$.log fi if [ -f /tmp/unison-$$.log ] then cat /tmp/unison-$$.log fi if [ -f /tmp/unison-post-$$.log ] then cat /tmp/unison-post-$$.log fi echo "." } | \ /usr/sbin/sendmail "$3" fi } if [ "$INDEX" == "" ] then if [ "$UNISON_DIR_N" == '0' ] then mecho "" mecho -error "Error: No replication directory configured!" mecho "" exit 1 fi mecho "" mecho -info "Select directory to synchronize" mecho "" techo begin 4 22 25 25 techo row -info No -info Host -info Local-Dir -info Remote-Dir idx="1" while [ "$idx" -le "$UNISON_DIR_N" ] do eval netsync='$UNISON_DIR_'$idx'_NETSYNC' eval host='$UNISON_DIR_'$idx'_HOST' eval localdir='$UNISON_DIR_'$idx'_LOCAL' eval remotedir='$UNISON_DIR_'$idx'_REMOTE' remotedir=$(echo "$remotedir" | sed 's/\\/\\\\/g') if [ "$netsync" == "yes" ] then techo row "$idx" "$host" "$localdir" "$remotedir" else techo row "$idx" "(local)" "$localdir" "$remotedir" fi idx=`/usr/bin/expr $idx + 1` done techo end idx="1" mecho idx=`/var/install/bin/ask "Select (0 = cancel)" "$idx" "0-$UNISON_DIR_N"` if [ "$idx" -eq 0 ] then mecho "" mecho -info "Selection canceled!" mecho "" exit 0 fi PROFILE="replica$idx" RUN="$PROG $PROFILE -auto" eval PRESCRIPT='$UNISON_DIR_'$idx'_PRERUN' eval POSTSCRIPT='$UNISON_DIR_'$idx'_POSTRUN' MANUAL="true" mecho "" mecho -info "Manual synchronisation started..." else PROFILE="replica$INDEX" eval PRESCRIPT='$UNISON_DIR_'$INDEX'_PRERUN' eval POSTSCRIPT='$UNISON_DIR_'$INDEX'_POSTRUN' RUN="$PROG $PROFILE -batch" fi if [ "$MANUAL" == "true" ] then { echo "" echo "-----------------------------------------------------------------------" echo "Unison manual synchronisation started $(date)" echo "-----------------------------------------------------------------------" } > /tmp/unison-header-$$.log # execute pre script if [ ! -z "$PRESCRIPT" ] then ${PRESCRIPT} 2>> /tmp/unison-header-$$.log >> /tmp/unison-header-$$.log if [ "$?" != "0" ] then echo "failed to execute: ${PRESCRIPT}" echo "failed to execute: ${PRESCRIPT}" >> /tmp/unison-header-$$.log exit 1 fi fi $RUN -logfile /tmp/unison-$$.log unison_err="$?" if [ -f /tmp/unison-header-$$.log ] then cat /tmp/unison-header-$$.log >> /var/log/unison.log rm -f /tmp/unison-header-$$.log fi if [ "$unison_err" == "0" ] then if [ -f "/tmp/unison-$$.log" ] then cat /tmp/unison-$$.log >> /var/log/unison.log rm -f /tmp/unison-$$.log else { echo "" echo "No differences where found. Directories are identical!" echo "" } >> /var/log/unison.log fi result='0' else echo "Unison terminated with exit code \"$?\"!" >> /var/log/unison.log if [ -f "/tmp/unison-$$.log" ] then cat /tmp/unison-$$.log >> /var/log/unison.log rm -f /tmp/unison-$$.log fi result='1' fi # execute post script if [ ! -z "$POSTSCRIPT" ] then ${POSTSCRIPT} 2>> /var/log/unison.log >> /var/log/unison.log if [ "$?" != "0" ] then echo "failed to execute: $POSTSCRIPT" echo "failed to execute: $POSTSCRIPT" >> /var/log/unison.log fi fi anykey exit "$result" else error='0' unison_err='0' { echo "" echo "-----------------------------------------------------------------------" echo "Unison automatic synchronisation started $(date)" echo "-----------------------------------------------------------------------" } > /tmp/unison-header-$$.log if [ ! -z "$PRESCRIPT" ] then echo "" > /tmp/unison-pre-$$.log ${PRESCRIPT} 2>> /tmp/unison-pre-$$.log >> /tmp/unison-pre-$$.log if [ "$?" != "0" ] then echo "failed to execute: $PRESCRIPT" >> /tmp/unison-pre-$$.log error='1' fi fi if [ "$error" == "0" ] then $RUN -silent -logfile /tmp/unison-$$.log > /dev/null 2> /dev/null if [ "$?" != "0" ] then unison_err="$?" error='1' fi # execute post script if [ ! -z "$POSTSCRIPT" ] then echo "" > /tmp/unison-post-$$.log ${POSTSCRIPT} 2>> /tmp/unison-post-$$.log >> /tmp/unison-post-$$.log if [ "$?" != "0" ] then echo "failed to execute: $POSTSCRIPT" >> /tmp/unison-post-$$.log error='1' fi fi fi if [ -f /tmp/unison-header-$$.log ] then cat /tmp/unison-header-$$.log >> /var/log/unison.log fi if [ -f /tmp/unison-pre-$$.log ] then cat /tmp/unison-pre-$$.log >> /var/log/unison.log fi if [ "$error" == "0" ] then if [ -f "/tmp/unison-$$.log" ] then if [ "$UNISON_MAIL_NOTIFY" == "yes" -a "$UNISON_MAIL_ONERROR" == "no" ] then mail_result "SUCCESS" "$PROFILE.prf" "$UNISON_MAIL_ADDR" fi cat /tmp/unison-$$.log >> /var/log/unison.log else { echo "" echo "No differences where found. Directories are identical!" echo "" } >> /var/log/unison.log fi if [ -f /tmp/unison-post-$$.log ] then cat /tmp/unison-post-$$.log >> /var/log/unison.log fi rm -f /tmp/unison-$$.log rm -f /tmp/unison-pre-$$.log rm -f /tmp/unison-post-$$.log rm -f /tmp/unison-header-$$.log exit 0 else if [ "$unison_err" != '0' ] then echo "Unison terminated with exit code \"$unison_err\"!" >> /var/log/unison.log fi if [ -f "/tmp/unison-$$.log" ] then if [ "$UNISON_MAIL_NOTIFY" == "yes" ] then mail_result "ERROR" "$PROFILE.prf" "$UNISON_MAIL_ADDR" fi cat /tmp/unison-$$.log >> /var/log/unison.log fi if [ -f /tmp/unison-post-$$.log ] then cat /tmp/unison-post-$$.log >> /var/log/unison.log fi rm -f /tmp/unison-$$.log rm -f /tmp/unison-pre-$$.log rm -f /tmp/unison-post-$$.log rm -f /tmp/unison-header-$$.log # return exit code 0 to prevent cron from mailing it's output # since we already did the user notification ourselfs exit 0 fi fi