#!/bin/bash

WEB=/srv/chiedi.ubuntu-it.org
WWW=$WEB/www/osqa/
BZR=/srv/shared-branches
BZRWWW=$BZR/ubuntu-it-ask/
TMP_FILE=/tmp/askrepo_version

function set_own_perm {
    chown -R :ubuntu-it $WWW
    chmod -R ug+rw $WWW
}

trap set_own_perm EXIT HUP QUIT TERM KILL

if [ ! -f $TMP_FILE ]
then
        touch $TMP_FILE
fi

cd $BZRWWW
OLD_VERSION=`cat $TMP_FILE`
NEW_VERSION=`bzr up 2>&1 | tail -n1`

if [ ! "$NEW_VERSION" == "$OLD_VERSION" ]
then
        echo "$NEW_VERSION" > $TMP_FILE
        cp -ax $BZRWWW/* $WWW/
fi
