#!/usr/bin/sh
# to be sourced

if [ -f /etc/sysconfig/pulseaudio ]; then
	. /etc/sysconfig/pulseaudio
fi

if [ -n "$PULSE_SERVER_TYPE" -a "$PULSE_SERVER_TYPE" != "none" -a -e "/etc/sound/profiles/current/pulse" ]; then

	case "${SESSION##*/}" in
		GNOME|gnome-session|mate-session|cinnamon-session-cinnamon|startgnome_classic| \
		KDE*|Plasma*|startplasma-x11|startkde| \
		afterstep| \
		enlightenment_start| \
		xfce4|startxfce4)
			# XDG is supported so we don't need to do anything.
			# as XDG Autostart will "just work"(tm)
			;;
		*)
			/usr/bin/start-pulseaudio-x11
# sometimes for some reason start-pulseaudio-x11 fails, while pulseaudio --start just works
			PULSEPID=$(pidof pulseaudio)
			if [ ! -n "$PULSEPID" ]; then
				/usr/bin/pulseaudio --start
			fi			
			;;
	esac
fi
