#!/bin/bash

# check java
j=`command -v java`
if [ X"$j" = X ]; then echo "No java can be found. Quit"; exit; fi

VERSION=`java -version 2>&1 | head -n 1 | awk '{print $3}' | awk -F "." '{print $1}'`
VERSION=${VERSION:1}
if [ $VERSION -gt 8 ]; then
  echo java $VERSION is too new to run HepRApp. Quit.
  exit
fi

# download and run HepRApp.jar
JAR="HepRApp.jar"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [ ! -f $DIR/$JAR ]; then
  curl -L https://www.dropbox.com/s/xfatlu1rp7ffavv/HepRApp.jar?dl=1 -o $DIR/$JAR
fi
# https://github.com/XQuartz/XQuartz/issues/31#issuecomment-1356328281
java -Dsun.java2d.xrender=false -jar $DIR/$JAR -opt ~/.heprapprc -file $1
