#!/bin/bash

# Target for application ini
APP_INI="/usr/share/evolus-pencil/application.ini"

# List of firefox binaries to search
BINARIES="xulrunner iceweasel firefox firefox-bin"

# Assembling run command
RUN=""

for BIN in $BINARIES; do
    BIN_PATH=$(which ${BIN} 2>/dev/null)

    if [ "$?" == "0" ]; then
        OPTS="${APP_INI} $@"

        if [ "${BIN}" != "xulrunner" ]; then
            OPTS="--app ${OPTS}"
        fi

        RUN="${BIN_PATH} ${OPTS}"
        break
    fi
done

if [ "${RUN}" == "" ]; then
    echo "You need to install firefox or xulrunner and have it in your PATH."
    exit 1;
fi

${RUN}
