#!/bin/sh

##
## Disable the gnome crash dialog.  Once bug buddy supports 
## Bugzilla, we will turn take this hack out.
##
GNOME_DISABLE_CRASH_DIALOG=1 ; export GNOME_DISABLE_CRASH_DIALOG

##
## Set up Mozilla environment variables for people using Debian.
##
if [ -z "$MOZILLA_FIVE_HOME" -a -f /etc/debian_version ]
then
  MOZILLA_FIVE_HOME=/usr/lib/mozilla ; export MOZILLA_FIVE_HOME
  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MOZILLA_FIVE_HOME ; export LD_LIBRARY_PATH
fi

##
## Find out if Nautilus is already running
##
ps ax|awk '{ print $5; }' | grep -w -e  "nautilus$" > /dev/null 2>&1

ps_rv=$?

if [ $ps_rv -eq 1 ]
then
  ## Do a sanity check on the nautilus RPM
  nautilus-verify-rpm.sh
  if [ $? -ne 0 ]
  then
    exit 1
  fi

  ##
  ## Start with a fresh environment
  ##
  nautilus-clean.sh -q -x

  ##
  ## Run Nautilus with optional command line arguments.
  ## This should open the first Nautilus window.
  ##
  nautilus ${1+"$@"}
  RETURN=$?

  ##
  ## End with a fresh environment
  ##
  nautilus-clean.sh -q -x
else
  ## If no arguments given, open a new new home window
  if [ $# -eq 0 ]
  then
    nautilus ~
    RETURN=$?
  ## Run Nautilus with optional command line arguments
  else
    nautilus ${1+"$@"}
    RETURN=$?
  fi
fi

exit $RETURN
