8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / allocate / audio_clean.sh
blob2e4b10b9189e26f9ce6573bb63883fe9886af7dc
1 #! /bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
25 # This is the audio_clean program.
27 # Following is the syntax for calling the script:
28 # scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename]
29 # [zonepath]
31 # $1: -s for standard cleanup by a user
32 # -f for forced cleanup by an administrator
33 # -i for boot-time initialization (when the system is booted with -r)
34 # -I to suppress error/warning messages; the script is run in the '-i'
35 # mode
37 # $2: devicename - device to be allocated/deallocated, e.g., sr0
39 # $3: -A if cleanup is for allocation, or -D if cleanup is for deallocation.
41 # $4: username - run the script as this user, rather than as the caller.
43 # $5: zonename - zone in which device to be allocated/deallocated
45 # $6: zonepath - root path of zonename
47 # Unless the clean script is being called for boot-time
48 # initialization, it may communicate with the user via stdin and
49 # stdout. To communicate with the user via CDE dialogs, create a
50 # script or link with the same name, but with ".windowing" appended.
51 # For example, if the clean script specified in device_allocate is
52 # /etc/security/xyz_clean, that script must use stdin/stdout. If a
53 # script named /etc/security/xyz_clean.windowing exists, it must use
54 # dialogs. To present dialogs to the user, the dtksh script
55 # /etc/security/lib/wdwmsg may be used.
57 # This particular script, audio_clean, will work using stdin/stdout, or
58 # using dialogs. A symbolic link audio_clean.windowing points to
59 # audio_clean.
62 trap "" INT TERM QUIT TSTP ABRT
64 USAGE="usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"
65 PATH="/usr/bin:/usr/sbin"
66 WDWMSG="/etc/security/lib/wdwmsg"
67 MODE="allocate"
69 if [ `basename $0` != `basename $0 .windowing` ]; then
70 WINDOWING="yes"
71 else
72 WINDOWING="no"
76 # *** Shell Function Declarations ***
79 msg() {
80 if [ "$WINDOWING" = "yes" ]; then
81 if [ $MODE = "allocate" ]; then
82 TITLE="Audio Device Allocation"
83 else
84 TITLE="Audio Device Dellocation"
86 $WDWMSG "$*" "$TITLE" OK
87 else
88 echo "$*"
92 fail_msg() {
93 if [ "$MODE" = "allocate" ]; then
94 msg "$0: Allocate of $DEVICE failed."
95 else
96 msg "$0: Deallocate of $DEVICE failed."
98 exit 1
102 # Main program
105 # Check syntax, parse arguments.
107 while getopts ifsI c
109 case $c in
111 FLAG=$c;;
113 FLAG=$c;;
115 FLAG=$c;;
117 FLAG=i
118 silent=y;;
119 \?) msg $USAGE
120 exit 1;;
121 esac
122 done
124 shift `expr $OPTIND - 1`
126 DEVICE=$1
127 if [ "$2" = "-A" ]; then
128 MODE="allocate"
129 elif [ "$2" = "-D" ]; then
130 MODE="deallocate"
132 if [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then
133 msg $USAGE
134 exit 1
136 ZONENAME=$4
137 ZONEPATH=$5
138 SAVEDIR=/etc/security/audio
139 MAP=`dminfo -v -n $DEVICE`
140 DEVICE=`echo $MAP | cut -f1 -d:`
141 TYPE=`echo $MAP | cut -f2 -d:`
142 FILES=`echo $MAP | cut -f3 -d:`
144 if [ ! -d ${SAVEDIR} ]
145 then
146 /usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg
147 /usr/bin/chown root:sys ${SAVEDIR} || fail_msg
150 for d in $FILES
152 x="`expr $d : '/dev/mixer[0-9][0-9]*'`"
153 if [ "$x" -ne 0 ] ; then
154 DEVNM=$d
155 break
157 done
158 SAVEFILE="${SAVEDIR}/`basename ${DEVNM}`"
160 if [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ]
161 then
162 /usr/bin/audioctl save-controls -d ${DEVNM} -f ${SAVEFILE} || fail_msg
163 else
164 /usr/bin/audioctl load-controls -d ${DEVNM} ${SAVEFILE} || fail_msg
167 exit 0