#!/bin/bash

if [ -z $SW_HOME ]; then
  if [ -z $SW_HOME ]; then
      echo "The \$SW_HOME environment variable is not set, please set it to the directory you installed Silent Wings!"
      exit 1;
  else
      # Check if we have installed in the Simulator dir
      if [ -x $SW_HOME/bin/sv_gui ]; then
	  export SW_HOME=${SW_HOME}
      fi
  fi
fi

export SV2_HOME=${SW_HOME}
export SV2_DATA=${SW_HOME}/data
export LD_LIBRARY_PATH=${SW_HOME}/lib

missing_sv_gui_libs=`ldd $SW_HOME/bin/sv_gui | grep "not found"`
if [ ! -z "$missing_sv_gui_libs" ]; then
  cat << !
ERROR!
  
You are missing some important system libraries.
See the following list for details:

$missing_sv_gui_libs

Check your linux distribution and ensure that at least the following packages are installed:

 - Qt (installed automatically with the KDE desktop)
 - OpenAL (must often be installed separately)

Please contact support@silentwings.no if you have any questions about this error message.
!
  exit 1
fi

missing_sview_libs=`ldd $SW_HOME/bin/sview | grep "not found"`
if [ ! -z "$missing_sview_libs" ]; then
    cat << !
ERROR!
    
You are missing some important system libraries.
See the following list for details:

$missing_sview_libs

Check your linux distribution and ensure that at least the following packages are installed:

 - Qt (installed automatically with the KDE desktop)
 - OpenAL (must often be installed separately)
 
Please contact support@silentwings.no if you have any questions about this error message.
!
  exit 1
fi

#ldd $SW_HOME/bin/sv_gui
#echo "SW_HOME=$SW_HOME";
#echo "SV2_DATA=$SV2_DATA";

exec $SW_HOME/bin/sv_gui
