1 #! /bin/sh 2 # 3 # CDDL HEADER START 4 # 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. 8 # 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. 13 # 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] 19 # 20 # CDDL HEADER END 21 # 22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 # Use is subject to license terms. 24 # 25 # This is the audio_clean program. 26 # 27 # Following is the syntax for calling the script: 28 # scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename] 29 # [zonepath] 30 # 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 36 # 37 # $2: devicename - device to be allocated/deallocated, e.g., sr0 38 # 39 # $3: -A if cleanup is for allocation, or -D if cleanup is for deallocation. 40 # 41 # $4: username - run the script as this user, rather than as the caller. 42 # 43 # $5: zonename - zone in which device to be allocated/deallocated 44 # 45 # $6: zonepath - root path of zonename 46 # 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. 56 # 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. 60 61 62 trap "" INT TERM QUIT TSTP ABRT 63 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" 68 69 if [ `basename $0` != `basename $0 .windowing` ]; then 70 WINDOWING="yes" 71 else 72 WINDOWING="no" 73 fi 74 75 # 76 # *** Shell Function Declarations *** 77 # 78 79 msg() { 80 if [ "$WINDOWING" = "yes" ]; then 81 if [ $MODE = "allocate" ]; then 82 TITLE="Audio Device Allocation" 83 else 84 TITLE="Audio Device Dellocation" 85 fi 86 $WDWMSG "$*" "$TITLE" OK 87 else 88 echo "$*" 89 fi 90 } 91 92 fail_msg() { 93 if [ "$MODE" = "allocate" ]; then 94 msg "$0: Allocate of $DEVICE failed." 95 else 96 msg "$0: Deallocate of $DEVICE failed." 97 fi 98 exit 1 99 } 100 101 # 102 # Main program 103 # 104 105 # Check syntax, parse arguments. 106 107 while getopts ifsI c 108 do 109 case $c in 110 i) 111 FLAG=$c;; 112 f) 113 FLAG=$c;; 114 s) 115 FLAG=$c;; 116 I) 117 FLAG=i 118 silent=y;; 119 \?) msg $USAGE 120 exit 1;; 121 esac 122 done 123 124 shift `expr $OPTIND - 1` 125 126 DEVICE=$1 127 if [ "$2" = "-A" ]; then 128 MODE="allocate" 129 elif [ "$2" = "-D" ]; then 130 MODE="deallocate" 131 fi 132 if [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then 133 msg $USAGE 134 exit 1 135 fi 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:` 143 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 148 fi 149 150 for d in $FILES 151 do 152 x="`expr $d : '/dev/mixer[0-9][0-9]*'`" 153 if [ "$x" -ne 0 ] ; then 154 DEVNM=$d 155 break 156 fi 157 done 158 SAVEFILE="${SAVEDIR}/`basename ${DEVNM}`" 159 160 if [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ] 161 then 162 /usr/sbin/mixerctl -d ${DEVNM} -f -s ${SAVEFILE} || fail_msg 163 else 164 /usr/sbin/mixerctl -d ${DEVNM} -r ${SAVEFILE} || fail_msg 165 fi 166 167 exit 0 168