#! /bin/sh

PMDKHDMI_replace_configure() {
	if [ -f /etc/pulse/daemon-PMDK-HDMI.conf ]; then
		mv /etc/pulse/daemon-PMDK-HDMI.conf /etc/pulse/daemon.conf
	fi
}

replace_configure() {
	if [ -f /etc/pulse/daemon-i2s.conf ];then
		mv /etc/pulse/daemon-i2s.conf /etc/pulse/daemon.conf
	fi
}

remove_configure() {
	if [ -f /etc/pulse/daemon-* ];then
		rm /etc/pulse/daemon-*
	fi
}

add_user_to_audio_group() {
	cat /etc/passwd |grep bash |cut -f 1 -d : > /tmp/user.txt
	while read line
	do
    		#usermod -a -G audio $line
    		gpasswd -d $line audio
		echo $line
	done < /tmp/user.txt
}

CARD_ID=$(cat /proc/asound/card0/id)
echo $CARD_ID

if [ "$CARD_ID" = "PMDKI2S" ]; then
    replace_configure
elif [ "$CARD_ID" = "PMDKHDMI" ]; then
    PMDKHDMI_replace_configure
else
    remove_configure
fi

add_user_to_audio_group
