xref: /titanic_44/usr/src/cmd/allocate/audio_clean.sh (revision 3ccb19668faa3e1b7734ae03b4d31a4c00da3240)
188447a05SGarrett D'Amore#! /bin/sh
288447a05SGarrett D'Amore#
388447a05SGarrett D'Amore# CDDL HEADER START
488447a05SGarrett D'Amore#
588447a05SGarrett D'Amore# The contents of this file are subject to the terms of the
688447a05SGarrett D'Amore# Common Development and Distribution License (the "License").
788447a05SGarrett D'Amore# You may not use this file except in compliance with the License.
888447a05SGarrett D'Amore#
988447a05SGarrett D'Amore# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1088447a05SGarrett D'Amore# or http://www.opensolaris.org/os/licensing.
1188447a05SGarrett D'Amore# See the License for the specific language governing permissions
1288447a05SGarrett D'Amore# and limitations under the License.
1388447a05SGarrett D'Amore#
1488447a05SGarrett D'Amore# When distributing Covered Code, include this CDDL HEADER in each
1588447a05SGarrett D'Amore# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1688447a05SGarrett D'Amore# If applicable, add the following below this CDDL HEADER, with the
1788447a05SGarrett D'Amore# fields enclosed by brackets "[]" replaced with your own identifying
1888447a05SGarrett D'Amore# information: Portions Copyright [yyyy] [name of copyright owner]
1988447a05SGarrett D'Amore#
2088447a05SGarrett D'Amore# CDDL HEADER END
2188447a05SGarrett D'Amore#
2288447a05SGarrett D'Amore# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2388447a05SGarrett D'Amore# Use is subject to license terms.
2488447a05SGarrett D'Amore#
2588447a05SGarrett D'Amore# This is the audio_clean program.
2688447a05SGarrett D'Amore#
2788447a05SGarrett D'Amore# Following is the syntax for calling the script:
2888447a05SGarrett D'Amore#	scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename]
2988447a05SGarrett D'Amore#           [zonepath]
3088447a05SGarrett D'Amore#
3188447a05SGarrett D'Amore# $1:	-s for standard cleanup by a user
3288447a05SGarrett D'Amore#	-f for forced cleanup by an administrator
3388447a05SGarrett D'Amore#	-i for boot-time initialization (when the system is booted with -r)
3488447a05SGarrett D'Amore#	-I to suppress error/warning messages; the script is run in the '-i'
3588447a05SGarrett D'Amore#	mode
3688447a05SGarrett D'Amore#
3788447a05SGarrett D'Amore# $2:	devicename - device to be allocated/deallocated, e.g., sr0
3888447a05SGarrett D'Amore#
3988447a05SGarrett D'Amore# $3:	-A if cleanup is for allocation, or -D if cleanup is for deallocation.
4088447a05SGarrett D'Amore#
4188447a05SGarrett D'Amore# $4:	username - run the script as this user, rather than as the caller.
4288447a05SGarrett D'Amore#
4388447a05SGarrett D'Amore# $5:	zonename - zone in which device to be allocated/deallocated
4488447a05SGarrett D'Amore#
4588447a05SGarrett D'Amore# $6:	zonepath - root path of zonename
4688447a05SGarrett D'Amore#
4788447a05SGarrett D'Amore# Unless the clean script is being called for boot-time
4888447a05SGarrett D'Amore# initialization, it may communicate with the user via stdin and
4988447a05SGarrett D'Amore# stdout.  To communicate with the user via CDE dialogs, create a
5088447a05SGarrett D'Amore# script or link with the same name, but with ".windowing" appended.
5188447a05SGarrett D'Amore# For example, if the clean script specified in device_allocate is
5288447a05SGarrett D'Amore# /etc/security/xyz_clean, that script must use stdin/stdout.  If a
5388447a05SGarrett D'Amore# script named /etc/security/xyz_clean.windowing exists, it must use
5488447a05SGarrett D'Amore# dialogs.  To present dialogs to the user, the dtksh script
5588447a05SGarrett D'Amore# /etc/security/lib/wdwmsg may be used.
5688447a05SGarrett D'Amore#
5788447a05SGarrett D'Amore# This particular script, audio_clean, will work using stdin/stdout, or
5888447a05SGarrett D'Amore# using dialogs.  A symbolic link audio_clean.windowing points to
5988447a05SGarrett D'Amore# audio_clean.
6088447a05SGarrett D'Amore
6188447a05SGarrett D'Amore
6288447a05SGarrett D'Amoretrap "" INT TERM QUIT TSTP ABRT
6388447a05SGarrett D'Amore
6488447a05SGarrett D'AmoreUSAGE="usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"
6588447a05SGarrett D'AmorePATH="/usr/bin:/usr/sbin"
6688447a05SGarrett D'AmoreWDWMSG="/etc/security/lib/wdwmsg"
6788447a05SGarrett D'AmoreMODE="allocate"
6888447a05SGarrett D'Amore
6988447a05SGarrett D'Amoreif [ `basename $0` != `basename $0 .windowing` ]; then
7088447a05SGarrett D'Amore  WINDOWING="yes"
7188447a05SGarrett D'Amoreelse
7288447a05SGarrett D'Amore  WINDOWING="no"
7388447a05SGarrett D'Amorefi
7488447a05SGarrett D'Amore
7588447a05SGarrett D'Amore#
7688447a05SGarrett D'Amore# 		*** Shell Function Declarations ***
7788447a05SGarrett D'Amore#
7888447a05SGarrett D'Amore
7988447a05SGarrett D'Amoremsg() {
8088447a05SGarrett D'Amore  	if [ "$WINDOWING" = "yes" ]; then
8188447a05SGarrett D'Amore	  if [ $MODE = "allocate" ]; then
8288447a05SGarrett D'Amore	    TITLE="Audio Device Allocation"
8388447a05SGarrett D'Amore	    else
8488447a05SGarrett D'Amore	    TITLE="Audio Device Dellocation"
8588447a05SGarrett D'Amore	  fi
8688447a05SGarrett D'Amore	  $WDWMSG "$*" "$TITLE" OK
8788447a05SGarrett D'Amore	else
8888447a05SGarrett D'Amore	  echo "$*"
8988447a05SGarrett D'Amore	fi
9088447a05SGarrett D'Amore}
9188447a05SGarrett D'Amore
9288447a05SGarrett D'Amorefail_msg() {
9388447a05SGarrett D'Amore	if [ "$MODE" = "allocate" ]; then
9488447a05SGarrett D'Amore		msg "$0: Allocate of $DEVICE failed."
9588447a05SGarrett D'Amore	else
9688447a05SGarrett D'Amore		msg "$0: Deallocate of $DEVICE failed."
9788447a05SGarrett D'Amore	fi
9888447a05SGarrett D'Amore	exit 1
9988447a05SGarrett D'Amore}
10088447a05SGarrett D'Amore
10188447a05SGarrett D'Amore#
10288447a05SGarrett D'Amore# 	Main program
10388447a05SGarrett D'Amore#
10488447a05SGarrett D'Amore
10588447a05SGarrett D'Amore# Check syntax, parse arguments.
10688447a05SGarrett D'Amore
10788447a05SGarrett D'Amorewhile getopts ifsI c
10888447a05SGarrett D'Amoredo
10988447a05SGarrett D'Amore	case $c in
11088447a05SGarrett D'Amore	i)
11188447a05SGarrett D'Amore		FLAG=$c;;
11288447a05SGarrett D'Amore	f)
11388447a05SGarrett D'Amore		FLAG=$c;;
11488447a05SGarrett D'Amore	s)
11588447a05SGarrett D'Amore		FLAG=$c;;
11688447a05SGarrett D'Amore	I)
11788447a05SGarrett D'Amore		FLAG=i
11888447a05SGarrett D'Amore		silent=y;;
11988447a05SGarrett D'Amore	\?)  msg $USAGE
12088447a05SGarrett D'Amore      	     exit 1;;
12188447a05SGarrett D'Amore	esac
12288447a05SGarrett D'Amoredone
12388447a05SGarrett D'Amore
12488447a05SGarrett D'Amoreshift `expr $OPTIND - 1`
12588447a05SGarrett D'Amore
12688447a05SGarrett D'AmoreDEVICE=$1
12788447a05SGarrett D'Amoreif [ "$2" = "-A" ]; then
12888447a05SGarrett D'Amore	MODE="allocate"
12988447a05SGarrett D'Amoreelif [ "$2" = "-D" ]; then
13088447a05SGarrett D'Amore	MODE="deallocate"
13188447a05SGarrett D'Amorefi
13288447a05SGarrett D'Amoreif [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then
13388447a05SGarrett D'Amore	msg $USAGE
13488447a05SGarrett D'Amore	exit 1
13588447a05SGarrett D'Amorefi
13688447a05SGarrett D'AmoreZONENAME=$4
13788447a05SGarrett D'AmoreZONEPATH=$5
13888447a05SGarrett D'AmoreSAVEDIR=/etc/security/audio
13936d41b68SNathan BushMAP=`dminfo -v -n $DEVICE`
14088447a05SGarrett D'AmoreDEVICE=`echo $MAP | cut -f1 -d:`
14188447a05SGarrett D'AmoreTYPE=`echo $MAP | cut -f2 -d:`
14288447a05SGarrett D'AmoreFILES=`echo $MAP | cut -f3 -d:`
14388447a05SGarrett D'Amore
14488447a05SGarrett D'Amoreif [ ! -d ${SAVEDIR} ]
14588447a05SGarrett D'Amorethen
14688447a05SGarrett D'Amore    /usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg
14788447a05SGarrett D'Amore    /usr/bin/chown root:sys ${SAVEDIR} || fail_msg
14888447a05SGarrett D'Amorefi
14988447a05SGarrett D'Amore
15088447a05SGarrett D'Amorefor d in $FILES
15188447a05SGarrett D'Amoredo
15288447a05SGarrett D'Amore    x="`expr $d : '/dev/mixer[0-9][0-9]*'`"
15388447a05SGarrett D'Amore    if [ "$x" -ne 0 ] ; then
15488447a05SGarrett D'Amore	DEVNM=$d
15588447a05SGarrett D'Amore	break
15688447a05SGarrett D'Amore    fi
15788447a05SGarrett D'Amoredone
15888447a05SGarrett D'AmoreSAVEFILE="${SAVEDIR}/`basename ${DEVNM}`"
15988447a05SGarrett D'Amore
16088447a05SGarrett D'Amoreif [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ]
16188447a05SGarrett D'Amorethen
162*3ccb1966SGarrett D'Amore    /usr/bin/audioctl save-controls -d ${DEVNM} -f ${SAVEFILE} || fail_msg
16388447a05SGarrett D'Amoreelse
164*3ccb1966SGarrett D'Amore    /usr/bin/audioctl load-controls -d ${DEVNM} ${SAVEFILE} || fail_msg
16588447a05SGarrett D'Amorefi
16688447a05SGarrett D'Amore
16788447a05SGarrett D'Amoreexit 0
168