#!/bin/sh
# SFLphone bin launcher script v 3
# Setup ld's environment

prefix=/usr
exec_prefix=/usr

LD_LIBRARY_PATH=/usr/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

message="Warning, you probably did not extract the archive in the / directory,
you must edit this script ($0) and change SFLPHONE_DIR to the correct location.
/usr/lib must contain the provided libraries."
if [ ! -d ${SFLPHONE_DIR} ]; then
  echo $message
  exit 1
else
  if [ ! -d /usr/lib ]; then
    echo $message
    exit 1
  fi
fi

# Let's try to go..
PATH=/usr/lib:${PATH}
binaryqtname=sflphone-qt
binaryqt=/usr/lib/${binaryqtname}
binarycliname=sflphone-cli
binarycli=/usr/lib/${binarycliname}
if [ "$1" != "--text" ]; then
  if [ -x ${binaryqt} ]; then
    exec $binaryqt $1
  else
    echo "Could not find the ${binaryqtname} executable in /usr/lib !"
    exit 1
  fi
else 
  if [ -x ${binarycli} ]; then
    SFLPHONE_CORE_DIR=/usr/lib exec $binarycli $2
  else
    echo "Could not find the ${binarycliname} executable in /usr/lib !"
    exit 1
  fi
fi

# EOF
