mixer revision 127478
1101099Srwatson#!/bin/sh -
2166905Srwatson#
3126097Srwatson# Copyright (c) 2004  The FreeBSD Project
4172930Srwatson# All rights reserved.
5101099Srwatson#
6101099Srwatson# Redistribution and use in source and binary forms, with or without
7101099Srwatson# modification, are permitted provided that the following conditions
8101099Srwatson# are met:
9106393Srwatson# 1. Redistributions of source code must retain the above copyright
10106393Srwatson#    notice, this list of conditions and the following disclaimer.
11106393Srwatson# 2. Redistributions in binary form must reproduce the above copyright
12106393Srwatson#    notice, this list of conditions and the following disclaimer in the
13101099Srwatson#    documentation and/or other materials provided with the distribution.
14172930Srwatson#
15172930Srwatson# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16172930Srwatson# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17101099Srwatson# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18101099Srwatson# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19101099Srwatson# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20101099Srwatson# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21101099Srwatson# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22101099Srwatson# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23101099Srwatson# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24101099Srwatson# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25101099Srwatson# SUCH DAMAGE.
26101099Srwatson#
27101099Srwatson# $FreeBSD: head/etc/rc.d/mixer 127478 2004-03-27 09:26:22Z dougb $
28101099Srwatson#
29101099Srwatson
30101099Srwatson# PROVIDE: mixer
31101099Srwatson# REQUIRE: LOGIN usbd
32101099Srwatson# KEYWORD: FreeBSD nojail shutdown
33101099Srwatson
34101099Srwatson. /etc/rc.subr
35101099Srwatson
36101099Srwatsonname="mixer"
37101099Srwatsonstop_cmd="mixer_stop"
38101099Srwatsonstart_cmd="mixer_start"
39101099Srwatsonreload_cmd="mixer_start"
40101099Srwatsonextra_commands="reload"
41101099Srwatson
42101099Srwatson#
43172955Srwatson# List current mixer devices to stdout.
44101099Srwatson#
45101099Srwatsonlist_mixers()
46101099Srwatson{
47101099Srwatson	( cd /dev ; ls mixer* 2>/dev/null )
48101099Srwatson}
49101099Srwatson
50101099Srwatson#
51166905Srwatson# Save state of an individual mixer specified as $1
52257176Sglebius#
53101099Srwatsonmixer_save()
54101099Srwatson{
55101099Srwatson	local dev
56257176Sglebius
57257176Sglebius	dev="/dev/${1}"
58257176Sglebius	if [ -r ${dev} ]; then
59101099Srwatson		/usr/sbin/mixer -f ${dev} -s > /var/db/${1}-state 2>/dev/null
60101099Srwatson	fi
61165469Srwatson}
62101099Srwatson
63101099Srwatson#
64101099Srwatson# Restore the state of an individual mixer specified as $1
65227309Sed#
66101099Srwatsonmixer_restore()
67101099Srwatson{
68172955Srwatson	local file dev
69267992Shselasky
70172955Srwatson	dev="/dev/${1}"
71101099Srwatson	file="/var/db/${1}-state"
72172955Srwatson	if [ -r ${dev} -a -r ${file} ]; then
73267992Shselasky		/usr/sbin/mixer -f ${dev} `cat ${file}` > /dev/null
74172955Srwatson	fi
75101099Srwatson}
76172955Srwatson
77267992Shselasky#
78172955Srwatson# Restore state of all mixers
79101099Srwatson#
80172955Srwatsonmixer_start()
81267992Shselasky{
82172955Srwatson	local mixer
83101099Srwatson
84101099Srwatson	for mixer in `list_mixers`; do
85101099Srwatson		mixer_restore ${mixer}
86172930Srwatson	done
87101099Srwatson}
88101099Srwatson
89172955Srwatson#
90101099Srwatson# Save the state of all mixers
91101099Srwatson#
92172955Srwatsonmixer_stop()
93101099Srwatson{
94101099Srwatson	local mixer
95172955Srwatson
96101099Srwatson	for mixer in `list_mixers`; do
97101099Srwatson		mixer_save ${mixer}
98101099Srwatson	done
99101099Srwatson}
100101099Srwatson
101101099Srwatsonload_rc_config $name
102172930Srwatsonrun_rc_command "$1"
103101099Srwatson