diff --git a/pulseaudio/kali_pulseaudio.conf b/pulseaudio/kali_pulseaudio.conf index 3d078cb..f639a87 100644 --- a/pulseaudio/kali_pulseaudio.conf +++ b/pulseaudio/kali_pulseaudio.conf @@ -1,2 +1,5 @@ [Unit] ConditionUser= + +[Service] +ExecStartPost=/usr/bin/kali-pulseaudio-default-volume diff --git a/usr/bin/kali-pulseaudio-default-volume b/usr/bin/kali-pulseaudio-default-volume new file mode 100755 index 0000000..d68d190 --- /dev/null +++ b/usr/bin/kali-pulseaudio-default-volume @@ -0,0 +1,35 @@ +#!/bin/sh + +setup_pulseaudio() { + # Only for lightdm or sddm. Actually what really matters is + # whether pulseaudio is running. But let's err on the side + # of being too restrictive. + [ $(whoami) = lightdm ] || [ $(whoami) = sddm ] || return 0 + # Only on first boot - either the pulseaudio cookie doesn't exist, + # or it has just been created. + if [ -e $HOME/.config/pulse/cookie ]; then + if [ "$(( $(date +%s) - $(stat -c %Y $HOME/.config/pulse/cookie) ))" -gt 30 ]; then + return 0 + fi + fi + # Only if pactl (from pulseaudio-utils) is installed. + [ -x /usr/bin/pactl ] || return 0 + # + # Make sure that pulseaudio is unmuted, and volume is higher than 25%. + # + #pactl get-sink-mute @DEFAULT_SINK@ + #pactl get-sink-volume @DEFAULT_SINK@ + muted=$(pactl get-sink-mute @DEFAULT_SINK@ | grep '^Mute:' | sed 's/^Mute: //') + volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n 1) + if [ "$muted" = yes ]; then + pactl set-sink-mute @DEFAULT_SINK@ false + fi + if [ "$volume" -lt 25 ]; then + pactl set-sink-volume @DEFAULT_SINK@ 75% + fi +} + +# Workaround for the case when pulseaudio defaults to muted and volume close to +# zero. Seen in VM (QEMU and VirtualBox) on a Linux host. Probably due to a bug +# in PA or ALSA, but we handle it here, out of a better place. +setup_pulseaudio