#! /bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # This is the audio_clean program. # # Following is the syntax for calling the script: # scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename] # [zonepath] # # $1: -s for standard cleanup by a user # -f for forced cleanup by an administrator # -i for boot-time initialization (when the system is booted with -r) # -I to suppress error/warning messages; the script is run in the '-i' # mode # # $2: devicename - device to be allocated/deallocated, e.g., sr0 # # $3: -A if cleanup is for allocation, or -D if cleanup is for deallocation. # # $4: username - run the script as this user, rather than as the caller. # # $5: zonename - zone in which device to be allocated/deallocated # # $6: zonepath - root path of zonename # # Unless the clean script is being called for boot-time # initialization, it may communicate with the user via stdin and # stdout. To communicate with the user via CDE dialogs, create a # script or link with the same name, but with ".windowing" appended. # For example, if the clean script specified in device_allocate is # /etc/security/xyz_clean, that script must use stdin/stdout. If a # script named /etc/security/xyz_clean.windowing exists, it must use # dialogs. To present dialogs to the user, the dtksh script # /etc/security/lib/wdwmsg may be used. # # This particular script, audio_clean, will work using stdin/stdout, or # using dialogs. A symbolic link audio_clean.windowing points to # audio_clean. trap "" INT TERM QUIT TSTP ABRT setvar USAGE = ""usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"" setvar PATH = ""/usr/bin:/usr/sbin"" setvar WDWMSG = ""/etc/security/lib/wdwmsg"" setvar MODE = ""allocate"" if test $(basename $0) != $(basename $0 .windowing) { setvar WINDOWING = ""yes"" } else { setvar WINDOWING = ""no"" } # # *** Shell Function Declarations *** # proc msg { if test $WINDOWING = "yes" { if test $MODE = "allocate" { setvar TITLE = ""Audio Device Allocation"" } else { setvar TITLE = ""Audio Device Dellocation"" } $WDWMSG "$ifsjoin(ARGV)" $TITLE OK } else { echo "$ifsjoin(ARGV)" } } proc fail_msg { if test $MODE = "allocate" { msg "$0: Allocate of $DEVICE failed." } else { msg "$0: Deallocate of $DEVICE failed." } exit 1 } # # Main program # # Check syntax, parse arguments. while getopts ifsI c { match $c { with i setvar FLAG = "$c" with f setvar FLAG = "$c" with s setvar FLAG = "$c" with I setvar FLAG = 'i' setvar silent = 'y' with \? msg $USAGE exit 1 } } shift $(expr $OPTIND - 1) setvar DEVICE = "$1" if test $2 = "-A" { setvar MODE = ""allocate"" } elif test $2 = "-D" { setvar MODE = ""deallocate"" } if test $MODE != "allocate" -a $MODE != "deallocate" { msg $USAGE exit 1 } setvar ZONENAME = "$4" setvar ZONEPATH = "$5" setvar SAVEDIR = '/etc/security/audio' setvar MAP = $(dminfo -v -n $DEVICE) setvar DEVICE = $(echo $MAP | cut -f1 -d:) setvar TYPE = $(echo $MAP | cut -f2 -d:) setvar FILES = $(echo $MAP | cut -f3 -d:) if test ! -d ${SAVEDIR} { /usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg /usr/bin/chown root:sys ${SAVEDIR} || fail_msg } for d in [$FILES] { setvar x = "$(expr $d : '/dev/mixer[0-9][0-9]*)" if test $x -ne 0 { setvar DEVNM = "$d" break } } setvar SAVEFILE = ""${SAVEDIR}/$(basename ${DEVNM})"" if test ${FLAG} = "i" -a ! -r ${SAVEFILE} { /usr/bin/audioctl save-controls -d ${DEVNM} -f ${SAVEFILE} || fail_msg } else { /usr/bin/audioctl load-controls -d ${DEVNM} ${SAVEFILE} || fail_msg } exit 0