#!/bin/sh
rm -rf grafana
GOPATH=`pwd`/grafana
export GOPATH
( mkdir -p $GOPATH/src/github.com/grafana
  cd $GOPATH/src/github.com/grafana
  git clone https://github.com/grafana/grafana.git
  cd grafana
  #git checkout develop
  dep ensure
)
# ( cd $GOPATH
  # go get -v -d ./...
# )
( cd $GOPATH/src/github.com/grafana/grafana
  sed -e '/karma-phantomjs-launcher/d' <package.json >package.json.new && mv package.json.new package.json
  npm install
  rm -rf node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/build
  rm -f vendor/phantomjs/phantomjs
  ./node_modules/grunt-cli/bin/grunt 
  npm prune --production
)
tar cvf - --exclude .git grafana | xz -9 >grafana-`date '+%Y%m%d'`.tar.xz
rm -rf grafana
