!#/bin/bash

INITSKIP="false"

#first init check for pure systemd, no shim
INITCHECK=$(readlink /usr/sbin/init)
echo $INITCHECK
if [ "$INITCHECK" = "/lib/systemd/systemd" ]; then
        INITSKIP="true"
fi

#second init check for system-shim configuration
INITCHECK=$(/usr/bin/ps -p 1 -o cmd -h)
echo $INITCHECK
if [ "$INITCHECK" = "/lib/systemd/systemd" ]; then 
	  INITSKIP="true"
fi

#else start them up
echo "start pipewire"

if [ "$INITSKIP" = "false" ]; then
	if [ -z "$(pgrep -x -u $USER pipewire)" ]; then 
		/usr/bin/pipewire &
	fi
	if [ -z "$(pgrep -x -u $USER pipewire-pulse)" ]; then
		/usr/bin/pipewire-pulse & 
	fi
	#wireplumber doesn't always close down
	if [ -z "$(pgrep -x -u $USER wireplumber)" ]; then
        sleep 2
        /usr/bin/wireplumber &
	else
        pkill wireplumber
        sleep 2
        /usr/bin/wireplumber &
	fi
fi




exit 0
