#!/bin/sh -e

which=""

PREFIX=$(dirname $(dirname $0))

if echo $0 | grep 'calendar' >/dev/null; then
    which=netscape-calendar
else
    echo "You don't seem to have netscape calendar installed."
    exit 1
fi

###
# User Configurable Defaults
###

nscal="$PREFIX/lib/netscape/$which"
prefdir=$HOME/.NetscapeCalendar

MOZILLA_HOME=$PREFIX/lib/netscape
NPX_PLUGIN_PATH=$HOME/.netscape/plugins:$PREFIX/lib/netscape/plugins
display=$DISPLAY

###
# End
###

MOZILLA_ALLOWROOT=${MOZILLA_ALLOWROOT:=0}

export MOZILLA_HOME NPX_PLUGIN_PATH display MOZILLA_ALLOWROOT


# Check if root is allowed to run netscape
if [ ${UID:-`id | sed 's/uid=\([^(]*\).*/\1/'`} -eq 0 ] && [ $MOZILLA_ALLOWROOT -ne 1 ]; then
    echo "Netscape Calendar should not be run as root for security reasons."
    echo "Override by setting: MOZILLA_ALLOWROOT=1"
    exit 1
fi

exec $nscal $*
