#! /bin/bash

# Shell script to install KDE desktop file. I have no clue
# about GNOME. If someone does please write a shellscript
# and send it to kurre@lynxlabs.com

PATHTOKDE=
FILENAME="LinuxPhobia.desktop"

function find_kde()
{
	if [ -d "$HOME/.kde2/" ]; then PATHTOKDE="$HOME/.kde2"
	elif [ -d "$HOME/.kde/" ]; then PATHTOKDE="$HOME/.kde"
	else exit_on_error "Can't find KDE! Aborting!"
	fi
}

function exit_on_error()
{
	echo "$1"
	exit 5
}

function create_link () 
{

	cat >$FILEPATH/$FILENAME << \EOF

[Desktop Entry]
Comment=
Name=LinuxPhobia
Terminal=0
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=
EOF

#	echo "TryExec=$MYPATH/linuxphobia" >> $FILEPATH/$FILENAME
	echo "Exec=sh -c \"cd $MYPATH; ./linuxphobia\"" >> $FILEPATH/$FILENAME
	echo "Icon=$MYPATH/phobia2.ico" >> $FILEPATH/$FILENAME

}

# Main stuff

if [ ! -f "pics/console.pl" ]; then 
	exit_on_error "This script must be executed form it's location!"
fi



find_kde
MYPATH=`pwd`
FILEPATH="$PATHTOKDE/share/applnk/Games/RedLynx"
mkdir -p $FILEPATH
if [ -d "$FILEPATH" ]; then
	create_link
else
	echo "Could not create link to K-Menu"
fi

FILEPATH="$HOME/Desktop"
mkdir -p $FILEPATH
if [ -d "$FILEPATH" ]; then
	create_link
else
	echo "Could not create link to desktop"
fi

FILEPATH="$MYPATH"
create_link

if [ -f "$MYPATH/$FILENAME" ]; then
	echo "KDE desktop file successfully created"
else
	echo "Problems."
fi
