#!/bin/bash

# Copyright (C) 2005 - 2015  Eric Van Dewoestine
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

BASEDIR=`dirname $(dirname $(which $0))`

function usage () {
  echo "Usage: rsync <target>"
  echo "  supported targets:"
  echo "    - site: website content"
  echo "    - dist: distributable files"
}

function site () {
  echo "rsync site"
  rsync --recursive --compress --force --whole-file --delete --delete-after \
    --stats -v --rsh="ssh -l ervandew" \
    $BASEDIR/build/doc/site/ \
    ervandew,eclim@web.sourceforge.net:/home/project-web/eclim/htdocs/
}

function dist () {
  echo "rsync dist"
  VERSION=$(git describe --abbrev=0)
  echo "eclim version: $VERSION"
  rsync --progress --whole-file \
    --stats -v --rsh="ssh -l ervandew" \
    $BASEDIR/build/dist/* \
    ervandew,eclim@frs.sourceforge.net:/home/frs/project/e/ec/eclim/eclim/$VERSION
}

if [ $# != 1 ] ; then
  usage
  exit 1
fi

TARGET=$1

if [ $TARGET != 'site' -a $TARGET != 'dist' ] ; then
  echo "abort: unsuported target '$TARGET'"
  usage
  exit 1
fi

$TARGET
