03-10-2021, 11:31 PM
(This post was last modified: 03-10-2021, 11:32 PM by moonwalkers.)
K, with some more modifications I was able to get the script working pretty well with sleep/resume cycles, with only caveat being applications that use sound may either quit/crash or lose sound until restart, or just pause playback - the exact behavior depends on a particular app. Here is the updated script:
Code:
$ cat /usr/local/sbin/sndreset
#!/bin/bash
chmod 000 /dev/snd/pcmC0D0*
for line in "$(ps -eo pid,user:32,args | grep "dbus-daemon.*--session" | grep -v grep | xargs)"
do
pid="$(echo "$line" | cut -d' ' -f 1)"
user="$(echo "$line" | cut -d' ' -f 2)"
bus_addr="$(sed -n 's/.*[\x0]DBUS_SESSION_BUS_ADDRESS=\([^\x0]*\)\x0.*/\1\n/p' /proc/$pid/environ)"
DBUS_SESSION_BUS_ADDRESS="$bus_addr" sudo -u $user -E /bin/systemctl --user stop pulseaudio.s*
done
while lsof /dev/snd/pcmC0D0* 2>/dev/null | grep -q /dev/snd/pcmC0D0
do
sleep 0.1
done
echo "1-0011" > /sys/bus/i2c/drivers/es8316/unbind
echo "1-0011" > /sys/bus/i2c/drivers/es8316/bind
for line in "$(ps -eo pid,user:32,args | grep "dbus-daemon.*--session" | grep -v grep | xargs)"
do
pid="$(echo "$line" | cut -d' ' -f 1)"
user="$(echo "$line" | cut -d' ' -f 2)"
bus_addr="$(sed -n 's/.*[\x0]DBUS_SESSION_BUS_ADDRESS=\([^\x0]*\)\x0.*/\1\n/p' /proc/$pid/environ)"
DBUS_SESSION_BUS_ADDRESS="$bus_addr" sudo -u $user -E /bin/systemctl --user start pulseaudio.socket
DBUS_SESSION_BUS_ADDRESS="$bus_addr" sudo -u $user -E /bin/systemctl --user start pulseaudio.service
done
until lsof /dev/snd/controlC0 2>/dev/null | grep -q pulse
do
sleep 0.1
done
/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore
This message was created with 100% recycled electrons