#!/bin/sh
 #
 # This file is part of the Anotatornia suite.
 # 
 # Copyright © 2007, 2008, 2009, 2010 by Instytut Podstaw Informatyki
 # Polskiej Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 # Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 # 
 # This file may be distributed and/or modified under the terms of the
 # GNU General Public License version 3 as published by the Free Software
 # Foundation and appearing in the file COPYING included in the packaging
 # of this file.  (See http://www.gnu.org/licenses/translations.html for
 # unofficial translations.)
 # 
 # A commercial license is available from IPI PAN (contact
 # Michal.Ciesiolka.waw.pl or ipi.waw.pl for more
 # information).  Licensees holding a valid commercial license from IPI
 # PAN may use this file in accordance with that license.
 # 
 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 # THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 # PURPOSE.
 #




set -e
# przerwanie wykonania skryptu przy pierwszym błędzie: 
# żeby nie zaznaczyło, że dobrze, jeśli nie poszło.

cd
#
# 
FILES=`find ./anotatornia/ -type f  -newer .anotatornia-lasttransferred -not -name 'nohup.out' -not -name '*.db'  -not -name '*.db-journal'   -not -name '*~' -not -wholename './anotatornia/tmp/*'  -not -wholename './anotatornia/log/*' -not -wholename './anotatornia/doc/*' -not -wholename './anotatornia/testfile*' -not -wholename './anotatornia/produkcja*'  -not -name '*.zip' -not -wholename './anotatornia/wypluwka*' -not -wholename './anotatornia/PALC2009/*' -not -wholename './anotatornia/*.tgz'`


if [ -z "$FILES" ]
then
    echo Nothing to do.
    exit 0
fi

echo Files to transfer: $FILES

  
tar cjf - $FILES | ssh  natror@chopin.ipipan.waw.pl  '(cd /home/natror; tar xjvf -  ; anotatornia/anotatornia-mongrels stop )'
#    '(cd /home/natror; for i in `ps ax | grep anotatornia-keeprunning | cut -c 1-5`; do kill $i ; done; anotatornia/anotatornia-mongrels stop;  tar xjvf - ; anotatornia/anotatornia-mongrels stop )'
#    '(cd /home/natror; ./anotatornia/mongrels-anotatornia stop ; tar xjvf - ; cd anotatornia/ ; RAILS_ENV=ap rake db:migrate; RAILS_ENV=development rake db:migrate; sleep 10; ./mongrels-anotatornia start )'

# tar cjf - $FILES | ssh natror@riley.ipipan.waw.pl \
#	'(cd /home/natror;  tar xjvf - ; ./anotatornia/mongrels-anotatornia stop )'

    

echo "Anotatornia successfully transfered to Chopin."

#tar cjf - $FILES | ssh  natror@bach.ipipan.waw.pl  '(cd /home/natror; tar xjvf -  ; anotatornia/anotatornia-mongrels stop )'

touch  .anotatornia-lasttransferred 
date "+%Y-%m-%d %X"