#! /bin/bash 

clink ()
{
        ln -fs $1 $2 >& /dev/null
}

# Install gnome / kde shortcuts and icons:
KDE=none
GNOME=none

if [ -d /opt/kde3/share ] ; then
        KDE=self
elif [ -d /usr/share/applications ] ; then
        KDE=shared
fi

if [ -d /opt/gnome/share ] ; then
        GNOME=self
elif [ -d /usr/share/gnome/ ] ; then
        GNOME=shared
fi

if [ $KDE = "shared" ] ; then

	if [ -d /etc/xdg/autostart ] ; then
		clink /usr/share/shodo/shortcuts/shodo.desktop /etc/xdg/autostart/shodo.desktop
	else  
		clink /usr/share/shodo/shortcuts/shodo.desktop /usr/share/autostart/shodo.desktop
	fi

    clink /usr/share/shodo/shortcuts/shodo.desktop /usr/share/applications/shodo.desktop                
    clink /usr/share/shodo/shortcuts/icons/shodo.png /usr/share/icons/shodo.png
	
	touch /usr/share/icons
fi

if [ $GNOME = "shared" ] ; then

	clink /usr/share/shodo/shortcuts/shodo.desktop /usr/share/applications/shodo.desktop

    if [ -d /etc/xdg/autostart ] ; then
    	clink /usr/share/shodo/shortcuts/shodo.desktop /etc/xdg/autostart/shodo.desktop
    elif [ -d /usr/share/gnome/autostart/ ] ; then
		clink /usr/share/shodo/shortcuts/shodo.desktop /usr/share/gnome/autostart/shodo.desktop
    fi

    if [ -d /usr/share/icons/gnome/32x32/apps ] ; then
		clink /usr/share/shodo/shortcuts/icons/shodo.png /usr/share/icons/gnome/32x32/apps/shodo.png
        touch /usr/share/icons/gnome
    fi
fi

if [ $KDE = "self" ] ; then
	
	clink /usr/share/shodo/shortcuts/shodo.desktop /opt/kde3/share/applications/shodo.desktop
	clink /usr/share/shodo/shortcuts/icons/shodo.png /opt/kde3/share/icons/shodo.png
	
	if [ -d /etc/xdg/autostart ] ; then
    	clink /usr/share/shodo/shortcuts/shodo.desktop /etc/xdg/autostart/shodo.desktop
    else 
    	clink /usr/share/shodo/shortcuts/shodo.desktop /opt/kde3/share/autostart/shodo.desktop
    fi
fi

if [ $GNOME = "self" ] ; then
        
	clink /usr/share/shodo/shortcuts/shodo.desktop /opt/gnome/share/applications/shodo.desktop
	clink /usr/share/shodo/shortcuts/icons/shodo.png /opt/gnome/share/icons/shodo.png
    clink /usr/share/shodo/shortcuts/icons/shodo.png /opt/gnome/share/pixmaps/shodo.png
    
    if [ -d /etc/xdg/autostart ] ; then
    	clink /usr/share/shodo/shortcuts/shodo.desktop /etc/xdg/autostart/shodo.desktop
    elif [ -d /opt/gnome/share/gnome/autostart ] ; then
    	clink /usr/share/shodo/shortcuts/shodo.desktop /opt/gnome/share/gnome/autostart/shodo.desktop
	elif [ -d /opt/gnome/share/autostart ] ; then
    	clink /usr/share/shodo/shortcuts/shodo.desktop /opt/gnome/share/autostart/shodo.desktop
	fi
fi