#!/bin/bash

# startup tests
if [ "$(getconf LONG_BIT)" != "64" ]; then
  echo 'OS is not 64bit'
  exit 1
fi

if [ "$(id -u)" -eq "0" ];then 
  echo 'Please run this script as a normal user (not root)'
  exit 1
fi

if [ "${DISPLAY}" == "" ]; then
  echo 'A running X-session is required'
  exit 1
fi

#set default parameters:
DIR_AV="${HOME}/AnisView"

# already set up?
AVVF="$DIR_AV/idl/AVversion.txt"
if [ ! -e "$AVVF" ];then 
  mkdir -p "$DIR_AV"
  cp -fr /opt/AnisView/* "$DIR_AV/"
else
 # file exist, verify if uptodate
 current=1.400
 avv=`sed -n '1p' "$AVVF"`
 avv=`echo "${avv//[!.0-9]/}"`
 update=`echo "$current > $avv" | bc -l | grep -q 1 && echo yes || echo no`
 if [ "$update" == "yes" ];then
  cp -fr /opt/AnisView/* "$DIR_AV/"
 fi
fi

# Run the application
exec "${DIR_AV}/startAnisView.sh" 

