#!/bin/sh
# Use this if you don't want to install Opera to any special location,
# but execute it from the extracted package or current location.

# Location of the Opera binaries
OPERA_BINARYDIR=usr/lib/opera

die () {
    for arg
    do echo "$arg"
    done >&2
    exit 1
}

# Parse commandline parameters
toset=
_PERSONALDIR_FROM_CMDLINE_=NO

for arg
do
  if [ "$toset" ]
  then
      eval $toset='$arg'
      export $toset
      toset=
  else
      case $arg in
          --binarydir*|-binarydir*) toset=OPERA_BINARYDIR ;;
          --personaldir*|-personaldir*|--pd*|-pd*)
              _PERSONALDIR_FROM_CMDLINE_=YES
              toset=OPERA_PERSONALDIR
              ;;
          --display|-display) toset=DISPLAY ;;
      esac
  fi
done
[ -z "$toset" ] || die "Missing parameter for $arg"


[ "$PWD" ] || PWD=`/bin/pwd`
if [ "$_PERSONALDIR_FROM_CMDLINE_" = NO ]
then
  OPERA_PERSONALDIR="$PWD/profile"
  export OPERA_PERSONALDIR
fi

# Required for Session Management
case $0 in /*) OPERA_SCRIPT_PATH=$0;; *) OPERA_SCRIPT_PATH=`/bin/pwd`/$0;; esac
export OPERA_SCRIPT_PATH

OPERA_SYSTEM_UNAME=`uname -s`
export OPERA_SYSTEM_UNAME

OPERA_BINARYDIR=`echo $OPERA_BINARYDIR | sed -e 's:/*/$::'`
export OPERA_BINARYDIR
[ -f "$OPERA_BINARYDIR/opera" ] || die "The Opera binary is not located at \"$OPERA_BINARYDIR/opera\"." "Please modify the wrapper script at \"$0\"."
[ -x "$OPERA_BINARYDIR/opera" ] || die "You do not have execute rights on \"$OPERA_BINARYDIR/opera\", please ask the sysadmin to chmod +x it."

# Opera enviroment
if [ -z "$OPERA_DIR" ]
then
    OPERA_DIR="$PWD/usr/share/opera"
fi
export OPERA_DIR

# Acrobat Reader
for ACROBATBINDIR in \
	/usr/local/Adobe/Reader8/bin \
	/usr/lib64/Adobe/Reader8/bin \
	/usr/lib/Adobe/Reader8/bin \
	/usr/X11R6/lib/Adobe/Reader8/bin \
	/opt/Adobe/Reader8/bin \
	/usr/Adobe/Reader8/bin \
	/usr/local/Adobe/Acrobat7.0/bin \
	/usr/lib64/Acrobat7.0/bin \
	/usr/lib/Acrobat7.0/bin \
	/usr/X11R6/lib/Acrobat7.0/bin \
	/opt/Acrobat7.0/bin \
	/usr/Acrobat7.0/bin \
	/usr/local/Acrobat7/bin \
	/usr/lib64/Acrobat7/bin \
	/usr/lib/Acrobat7/bin \
	/usr/X11R6/lib/Acrobat7/bin \
	/opt/Acrobat7/bin \
	/usr/Acrobat7/bin \
	/usr/local/Acrobat5/bin \
	/usr/lib64/Acrobat5/bin \
	/usr/lib/Acrobat5/bin \
	/usr/X11R6/lib/Acrobat5/bin \
	/opt/Acrobat5/bin \
	/usr/Acrobat5/bin \
	/opt/acroread-5.07/bin \
	/usr/local/Acrobat4/bin \
	/usr/lib64/Acrobat4/bin \
	/usr/lib/Acrobat4/bin \
	/usr/X11R6/lib/Acrobat4/bin \
	/opt/Acrobat4/bin \
	/usr/Acrobat4/bin \
    ; do
    if [ -d "$ACROBATBINDIR" ]
    then PATH="$PATH:$ACROBATBINDIR"
    fi
done

# Setting environment relative to current working directory
# Bundled Qt will be found here unless preloaded by the stance above
LD_LIBRARY_PATH="$PWD/usr/lib/opera${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

# Run Opera:
"$OPERA_BINARYDIR/opera" "$@"
