mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-12-25 03:12:08 +01:00
On systems where the soundcard longname also contains digits, the regex added in !87552 could also match that longname. All of these issues starting surfacing now because with release 1.2.14, alsactl has gotten more strict about situations where passed sound devices are not available in kernel. For an exact description of the file format refer to: * https://www.alsa-project.org/alsa-doc/alsa-lib/control.html * https://github.com/torvalds/linux/blob/v6.12/sound/core/init.c#L943-L949
94 lines
2.5 KiB
Bash
94 lines
2.5 KiB
Bash
#!/sbin/openrc-run
|
|
# $Header: /var/cvsroot/gentoo-x86/media-sound/alsa-utils/files/alsasound.initd-r6,v 1.1 2014/06/23 21:34:42 ssuominen Exp $
|
|
# Copyright 1999-2014 Gentoo Foundation
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
|
|
description="Save/Restore Sound Card State"
|
|
|
|
alsastatedir=/var/lib/alsa
|
|
alsascrdir=/etc/alsa.d
|
|
alsahomedir=/var/run/alsasound
|
|
|
|
extra_commands="save restore"
|
|
|
|
depend() {
|
|
need localmount
|
|
after bootmisc modules isapnp coldplug hotplug
|
|
}
|
|
|
|
restore() {
|
|
ebegin "Restoring Mixer Levels"
|
|
|
|
checkpath -q -d -m 0700 -o root:root ${alsahomedir} || return 1
|
|
|
|
if [ ! -r "${alsastatedir}/asound.state" ] ; then
|
|
ewarn "No mixer config in ${alsastatedir}/asound.state, you have to unmute your card!"
|
|
eend 0
|
|
return 0
|
|
fi
|
|
|
|
# The regex extracts the card numbers from /proc/asound/cards, see:
|
|
# * https://www.alsa-project.org/alsa-doc/alsa-lib/control.html
|
|
# * https://github.com/torvalds/linux/blob/v6.12/sound/core/init.c#L943-L949
|
|
local cards="$(sed -E -n 's/^ ?([[:digit:]]+).*/\1/p' /proc/asound/cards)"
|
|
local cardnum
|
|
for cardnum in ${cards}; do
|
|
[ -e /dev/snd/controlC${cardnum} ] || sleep 2
|
|
[ -e /dev/snd/controlC${cardnum} ] || sleep 2
|
|
[ -e /dev/snd/controlC${cardnum} ] || sleep 2
|
|
[ -e /dev/snd/controlC${cardnum} ] || sleep 2
|
|
alsactl ${alsactl_opts} -E HOME="${alsahomedir}" -I -f "${alsastatedir}/asound.state" restore ${cardnum} \
|
|
|| ewarn "Errors while restoring defaults, ignoring"
|
|
done
|
|
|
|
for ossfile in "${alsastatedir}"/oss/card*_pcm* ; do
|
|
[ -e "${ossfile}" ] || continue
|
|
# We use cat because I'm not sure if cp works properly on /proc
|
|
local procfile="${ossfile##${alsastatedir}/oss}"
|
|
procfile="$(echo "${procfile}" | sed -e 's,_,/,g')"
|
|
if [ -e /proc/asound/"${procfile}"/oss ] ; then
|
|
cat "${ossfile}" > /proc/asound/"${procfile}"/oss
|
|
fi
|
|
done
|
|
|
|
eend 0
|
|
}
|
|
|
|
save() {
|
|
ebegin "Storing ALSA Mixer Levels"
|
|
|
|
checkpath -q -d -m 0700 -o root:root ${alsahomedir} || return 1
|
|
|
|
mkdir -p "${alsastatedir}"
|
|
if ! alsactl ${alsactl_opts} -E HOME="${alsahomedir}" -f "${alsastatedir}/asound.state" store; then
|
|
eerror "Error saving levels."
|
|
eend 1
|
|
return 1
|
|
fi
|
|
|
|
for ossfile in /proc/asound/card*/pcm*/oss; do
|
|
[ -e "${ossfile}" ] || continue
|
|
local device="${ossfile##/proc/asound/}" ; device="${device%%/oss}"
|
|
device="$(echo "${device}" | sed -e 's,/,_,g')"
|
|
mkdir -p "${alsastatedir}/oss/"
|
|
cp "${ossfile}" "${alsastatedir}/oss/${device}"
|
|
done
|
|
|
|
eend 0
|
|
}
|
|
|
|
start() {
|
|
if [ "${RESTORE_ON_START}" = "yes" ]; then
|
|
restore
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
stop() {
|
|
if [ "${SAVE_ON_STOP}" = "yes" ]; then
|
|
save
|
|
fi
|
|
return 0
|
|
}
|