#!/bin/bash

# Uncomment the following line if you're having trouble with gnome-keyring lockups.
# This will cause passwords to be stored only temporarily for the session.
#WB_NO_GNOME_KEYRING=1

# force disable the Mac style single menu hack in Ubuntu Unity
UBUNTU_MENUPROXY=0

program_path="$0"

bindirname=`dirname $program_path`
basedirname=$(cd "$bindirname/..";pwd)

libdir=$(basename /usr/lib)
libexecdir=$(basename /usr/lib)
wblibdir="$basedirname/$libdir/mysql-workbench"

# if libcairo and pixman are in the wb libraries dir, force them to be preloaded
if test -f $wblibdir/libcairo.so.2; then
	if test "$LD_PRELOAD" != ""; then
		export LD_PRELOAD="$LD_PRELOAD:$wblibdir/libcairo.so.2"
	else
		export LD_PRELOAD="$wblibdir/libcairo.so.2"
	fi
fi
if test -f $wblibdir/libpixman-1.so.0; then
	if test "$LD_PRELOAD" != ""; then
		export LD_PRELOAD="$LD_PRELOAD:$wblibdir/libpixman.so.0"
	else
		export LD_PRELOAD="$wblibdir/libpixman.so.0"
	fi
fi


if test "$LD_LIBRARY_PATH" != ""; then
export LD_LIBRARY_PATH="$wblibdir:$LD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$wblibdir"
fi

export MWB_DATA_DIR="$basedirname/share/mysql-workbench"
export MWB_LIBRARY_DIR="$basedirname/share/mysql-workbench/libraries"
export MWB_MODULE_DIR="$basedirname/$libdir/mysql-workbench/modules"
export MWB_PLUGIN_DIR="$basedirname/$libdir/mysql-workbench/plugins"

export DBC_DRIVER_PATH="$basedirname/$libdir/mysql-workbench"

# List of commands provided by mysql-utilities program, used to tell the user what are the available utilities
export MYSQL_UTILITIES_COMMANDS="mysqluc mysqlserverclone mysqldiskusage mysqldiff mysqlrplshow mysqlindexcheck mysqldbimport mysqlfailover mysqluserclone mysqlserverinfo mysqldbexport mysqlreplicate mysqlprocgrep mysqlmetagrep mysqlrplcheck mysqldbcopy mysqlrpladmin mysqldbcompare"

if test "$PYTHONPATH" != ""; then
export PYTHONPATH="$PYTHONPATH:$basedirname/share/mysql-workbench/python"
else
export PYTHONPATH="$basedirname/share/mysql-workbench/python"
fi
export PATH="$PATH:$basedirname/share/mysql-workbench/python"

export MWB_BASE_DIR="$basedirname"

if type -p catchsegv > /dev/null; then
catchsegv $basedirname/$libexecdir/mysql-workbench-bin "$@"
else
$basedirname/$libexecdir/mysql-workbench-bin "$@"
fi
