#!/bin/sh
# $Id: push,v 1.2 2001/03/18 03:06:12 holsta Exp $
#
# An attempt at writing a push syncronization script for Dancer. Use with
# caution.
#
# This script assumes that your ~/.ssh/config contains an entry along these
# lines for each system you are running a Dancer on:
#
# Host foo
# Hostname foo.isp.com
# User bar
#
# You should also arrange for some non-interactive way of logging in, eg. an
# RSA key with no password. See 5.2 of the manual for details.

HOSTS="host1 host2 host3"       # remote hosts as listed in ~/.ssh/config
DIR="~/bot"                       # Dancer install dir
REMOTE_DIR="\~/bot"               # If you use variables, you must escape them.

CURRENT=dancer.users
REMOTE=dancer.users-remote

# You shouldn't need to edit below here.

cd $DIR
# Make sure we have what we need.
if [ ! -s $REMOTE ] ; then
        cp $CURRENT $REMOTE
        echo Creating initial backup config and exiting.
        exit
fi

# Did the configuration change since we were last called?
diff $CURRENT $REMOTE > $OUT
if [ -s $OUT ] ; then
        for HOST in $HOSTS; do
                # This is where it gets tricky. We can not use the local
                # variables on a remote machines, but we do need to account for
                # different user name on the local and remote machine.
                echo -n Copying $CURRENT to $HOST:$REMOTE_DIR ...
                scp $CURRENT $HOST:$REMOTE_DIR
                echo ok!
        
                echo -n Restarting Dancer on $HOST
                ssh $HOST kill -HUP \`cat $REMOTE_DIR/.pid\`
                echo ok!
                # Prevent pointless sync attempts
                cp $CURRENT $REMOTE;
        done
fi



syntax highlighted by Code2HTML, v. 0.9.1