#!/bin/sh
# Wrapper around xulrunner/firefox to start the xulrunner application conkeror
# Written by Axel Beckert <abe@deuxchevaux.org> for the Debian Project

# Find an appropriate xulrunner binary
XULRUNNER=''
for version in 24.0 17.0 `LC_ALL=C seq 5.0 13.0 | tac` 2.0 1.9.2 1.9.1; do
    XRTMP=`which xulrunner-$version`
    if [ -n "$XRTMP" -a -x "$XRTMP" ]; then
	XULRUNNER=$XRTMP
	break
    fi
done

# Try firefox if no xulrunner can be found
if [ -z "$XULRUNNER" ]; then
    FFTMP=`which firefox`
    if [ -n "$FFTMP" -a -x "$FFTMP" ]; then
	echo "xulrunner not found, trying firefox instead." 1>&2
	XULRUNNER="$FFTMP -app"
    fi
fi

if [ -z "$XULRUNNER" ]; then
    echo "xulrunner version 1.9.1 (or firefox version 3.5) or newer required, but not found. Bailing out." 1>&2
    exit 1;
fi

if [ "$*" = "--help" ]; then
    errormsg="`exec $XULRUNNER /usr/share/conkeror/application.ini \"$@\" 2>&1`"
    echo "$errormsg" | sed -e "s:/[^ ]*/xulrunner-bin:$0:; /-\(width\|height\)/d" 1>&2
else
    exec $XULRUNNER /usr/share/conkeror/application.ini "$@"
fi
