#!/bin/bash -xe
DEST=/opt/plancton/git
cd /
[[ $(whoami) == plancton ]]
[[ -d $DEST/.git ]] || git clone https://github.com/mconcas/plancton $DEST
cd $DEST
git remote update -p
BRANCH=$(git symbolic-ref HEAD 2>/dev/null) && BRANCH=${BRANCH##refs/heads/}
if [[ -z "$TRAVIS" ]] && git branch -r | grep -qE "origin/$BRANCH\$"; then
  git clean -f -d
  git clean -fX -d
  git reset --hard origin/$BRANCH
fi
export PATH=$PATH:$DEST/bin
export PYTHONPATH=$PYTHONPATH:$DEST/pylibs
set +e
planctonctl stop 
set -e
planctonctl start
