#!/usr/bin/env bash
set -e
if [ -d ~/tmp/blinkster_V$1 ]; then
    rm -fr ~/tmp/blinkster_V$1;
fi

hg archive -r V$1 ~/tmp/blinkster_V$1

#text2unix ~/tmp/blinkster_V$1

if [ -d ~/tmp/blinkster_V$1 ]; then
    cat <<EOT | rsync -Cvrlz --delete --filter=". -" ~/tmp/blinkster_V$1/web/ web.iri.centrepompidou.fr:/iridata/www/web/blinkster/
+ core
P .htpasswd
P .htaccess
P blinkster/.htaccess
P blinkster/config.py
P robots.txt
P env/***
P log/***
P index/***
P static/media/***
EOT
fi

if [ -d ~/tmp/blinkster_V$1 ]; then
    echo "Deleting temp export"
    rm -fr ~/tmp/blinkster_V$1;
fi

ssh web.iri.centrepompidou.fr sudo apache2ctl restart
