#!/bin/sh
#skipstone startup script specifically for debian

dist_bin=`dirname $0`

#code from /usr/bin/mozilla in woody's mozilla deb used here to set ENV's and create ~/.mozilla if it doesn't exist

set -e
MOZILLA_DIR=/usr/lib/mozilla

# Check for a $HOME/.mozilla directory.  If it doesn't exist, create a GOOD one
if [ ! -d "$HOME"/.mozilla ]
then
    echo "Installing .mozilla directory"
    mkdir "$HOME"/.mozilla
    for file in $MOZILLA_DIR/*; 
    do
        if [ "`basename \"$file\"`" != component.reg ]; then
            ln -s "$file" "$HOME"/.mozilla/
        fi
    done
fi

# if chrome and components are not actual directories, we must
# make them so.
for dirs in chrome components defaults dtd icons locales packages \
	plugins res searchplugins
do
    if [ -L "$HOME"/.mozilla/"$dirs" ]
    then
        set +e
        rm "$HOME"/.mozilla/"$dirs"
        set -e
        mkdir "$HOME"/.mozilla/"$dirs"
	set +e
        for file in "$MOZILLA_DIR"/"$dirs"/*;
        do
            cp -sRp "$file" "$HOME"/.mozilla/"$dirs"
        done
	set -e
    fi
    if [ -L "$HOME"/.mozilla/chrome/installed-chrome.txt ]
    then
        rm "$HOME"/.mozilla/chrome/installed-chrome.txt
	cp "$MOZILLA_DIR"/chrome/installed-chrome.txt \
	        "$HOME"/.mozilla/chrome/installed-chrome.txt
    fi
done

LD_LIBRARY_PATH=$MOZILLA_DIR:$LD_LIBRARY_PATH
MOZILLA_FIVE_HOME=$HOME/.mozilla
export LD_LIBRARY_PATH  MOZILLA_FIVE_HOME

exec $dist_bin/skipstone-bin $@
