1127043Sjhb#!/bin/sh -
2127043Sjhb#
3127043Sjhb# Copyright (c) 2004  The FreeBSD Project
4127043Sjhb# All rights reserved.
5127043Sjhb#
6127043Sjhb# Redistribution and use in source and binary forms, with or without
7127043Sjhb# modification, are permitted provided that the following conditions
8127043Sjhb# are met:
9127043Sjhb# 1. Redistributions of source code must retain the above copyright
10127043Sjhb#    notice, this list of conditions and the following disclaimer.
11127043Sjhb# 2. Redistributions in binary form must reproduce the above copyright
12127043Sjhb#    notice, this list of conditions and the following disclaimer in the
13127043Sjhb#    documentation and/or other materials provided with the distribution.
14127043Sjhb#
15127043Sjhb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16127043Sjhb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17127043Sjhb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18127043Sjhb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19127043Sjhb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20127043Sjhb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21127043Sjhb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22127043Sjhb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23127043Sjhb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24127043Sjhb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25127043Sjhb# SUCH DAMAGE.
26127043Sjhb#
27127043Sjhb# $FreeBSD$
28127043Sjhb#
29127043Sjhb
30127043Sjhb# PROVIDE: mixer
31240336Sobrien# REQUIRE: FILESYSTEMS
32136224Smtm# KEYWORD: nojail shutdown
33127043Sjhb
34127043Sjhb. /etc/rc.subr
35127043Sjhb
36127043Sjhbname="mixer"
37298514Slmedesc="Save and restore soundcard mixer values"
38163063Sflzrcvar="mixer_enable"
39127043Sjhbstop_cmd="mixer_stop"
40127043Sjhbstart_cmd="mixer_start"
41127043Sjhbreload_cmd="mixer_start"
42127043Sjhbextra_commands="reload"
43127043Sjhb
44127043Sjhb#
45127043Sjhb# List current mixer devices to stdout.
46127043Sjhb#
47127043Sjhblist_mixers()
48127043Sjhb{
49127043Sjhb	( cd /dev ; ls mixer* 2>/dev/null )
50127043Sjhb}
51127043Sjhb
52127043Sjhb#
53127043Sjhb# Save state of an individual mixer specified as $1
54127043Sjhb#
55127043Sjhbmixer_save()
56127043Sjhb{
57127478Sdougb	local dev
58127043Sjhb
59127043Sjhb	dev="/dev/${1}"
60127043Sjhb	if [ -r ${dev} ]; then
61127478Sdougb		/usr/sbin/mixer -f ${dev} -s > /var/db/${1}-state 2>/dev/null
62127043Sjhb	fi
63127043Sjhb}
64127043Sjhb
65127043Sjhb#
66127043Sjhb# Restore the state of an individual mixer specified as $1
67127043Sjhb#
68127043Sjhbmixer_restore()
69127043Sjhb{
70127043Sjhb	local file dev
71127043Sjhb
72127043Sjhb	dev="/dev/${1}"
73127478Sdougb	file="/var/db/${1}-state"
74127043Sjhb	if [ -r ${dev} -a -r ${file} ]; then
75127043Sjhb		/usr/sbin/mixer -f ${dev} `cat ${file}` > /dev/null
76127043Sjhb	fi
77127043Sjhb}
78127043Sjhb
79127043Sjhb#
80127043Sjhb# Restore state of all mixers
81127043Sjhb#
82127043Sjhbmixer_start()
83127043Sjhb{
84127043Sjhb	local mixer
85127043Sjhb
86127043Sjhb	for mixer in `list_mixers`; do
87127043Sjhb		mixer_restore ${mixer}
88127043Sjhb	done
89127043Sjhb}
90127043Sjhb
91127043Sjhb#
92127043Sjhb# Save the state of all mixers
93127043Sjhb#
94127043Sjhbmixer_stop()
95127043Sjhb{
96127043Sjhb	local mixer
97127043Sjhb
98127043Sjhb	for mixer in `list_mixers`; do
99127043Sjhb		mixer_save ${mixer}
100127043Sjhb	done
101127043Sjhb}
102127043Sjhb
103127043Sjhbload_rc_config $name
104127043Sjhbrun_rc_command "$1"
105