#! /bin/sh
set -e

if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
fi

case "$DE" in
    gnome)
        if [ -x "`which gnome-mount 2>/dev/null`" ]; then
            exec gnome-mount -b "$@"
        fi
        echo "gnome-mount cannot be found" >&2
        exit 7
        ;;
    xfce)
        if [ -x "`which exo-mount 2>/dev/null`" ]; then
            exec exo-mount "$@"
        fi
        echo "exo-mount cannot be found" >&2
        exit 7
        ;;
    *)
        if [ -x "`which gnome-mount 2>/dev/null`" ]; then
            exec gnome-mount -b "$@"
        elif [ -x "`which exo-mount 2>/dev/null`" ]; then
            exec exo-mount "$@"
        fi
        echo "no mount utility could be found" >&2
        exit 7
        ;;
esac
