#!/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