NAME=dbus-session-addr-save

SCRIPT="echo \${DBUS_SESSION_BUS_ADDRESS} > /tmp/.umf_${USER}"

if [ -d ${HOME}/.config ]; then
    if [ ! -d ${HOME}/.config/autostart ]; then
        mkdir -p ${HOME}/.config/autostart
    fi
    if [ ! -f ${HOME}/.config/autostart/${NAME}.desktop ]; then
        echo "[Desktop Entry]" > ${HOME}/.config/autostart/${NAME}.desktop
        echo "Type=Application" >> ${HOME}/.config/autostart/${NAME}.desktop
        echo "Name=umf" >> ${HOME}/.config/autostart/${NAME}.desktop
        echo "Exec=${HOME}/.config/autostart/${NAME}.sh" >> ${HOME}/.config/autostart/${NAME}.desktop
        echo "Icon=system-run" >> ${HOME}/.config/autostart/${NAME}.desktop
        echo "Comment=" >> ${HOME}/.config/autostart/${NAME}.desktop
        echo ${SCRIPT} > ${HOME}/.config/autostart/${NAME}.sh
        chmod +x ${HOME}/.config/autostart/${NAME}.sh
    fi
elif [ -d ${HOME}/.kde ]; then
    if [ ! -f ${HOME}/.kde/Autostart/${NAME} ]; then
        echo ${SCRIPT} > ${HOME}/.kde/Autostart/${NAME}
        chmod +x ${HOME}/.kde/Autostart/${NAME}
    fi
elif [ -d ${HOME}/.kde4 ]; then
    if [ ! -f ${HOME}/.kde4/Autostart/${NAME} ]; then
        echo ${SCRIPT} > ${HOME}/.kde4/Autostart/${NAME}
        chmod +x ${HOME}/.kde4/Autostart/${NAME}
    fi
fi
