xref: /titanic_44/usr/src/cmd/allocate/audio_clean.sh (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
1*88447a05SGarrett D'Amore#! /bin/sh
2*88447a05SGarrett D'Amore#
3*88447a05SGarrett D'Amore# CDDL HEADER START
4*88447a05SGarrett D'Amore#
5*88447a05SGarrett D'Amore# The contents of this file are subject to the terms of the
6*88447a05SGarrett D'Amore# Common Development and Distribution License (the "License").
7*88447a05SGarrett D'Amore# You may not use this file except in compliance with the License.
8*88447a05SGarrett D'Amore#
9*88447a05SGarrett D'Amore# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*88447a05SGarrett D'Amore# or http://www.opensolaris.org/os/licensing.
11*88447a05SGarrett D'Amore# See the License for the specific language governing permissions
12*88447a05SGarrett D'Amore# and limitations under the License.
13*88447a05SGarrett D'Amore#
14*88447a05SGarrett D'Amore# When distributing Covered Code, include this CDDL HEADER in each
15*88447a05SGarrett D'Amore# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*88447a05SGarrett D'Amore# If applicable, add the following below this CDDL HEADER, with the
17*88447a05SGarrett D'Amore# fields enclosed by brackets "[]" replaced with your own identifying
18*88447a05SGarrett D'Amore# information: Portions Copyright [yyyy] [name of copyright owner]
19*88447a05SGarrett D'Amore#
20*88447a05SGarrett D'Amore# CDDL HEADER END
21*88447a05SGarrett D'Amore#
22*88447a05SGarrett D'Amore# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*88447a05SGarrett D'Amore# Use is subject to license terms.
24*88447a05SGarrett D'Amore#
25*88447a05SGarrett D'Amore# This is the audio_clean program.
26*88447a05SGarrett D'Amore#
27*88447a05SGarrett D'Amore# Following is the syntax for calling the script:
28*88447a05SGarrett D'Amore#	scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename]
29*88447a05SGarrett D'Amore#           [zonepath]
30*88447a05SGarrett D'Amore#
31*88447a05SGarrett D'Amore# $1:	-s for standard cleanup by a user
32*88447a05SGarrett D'Amore#	-f for forced cleanup by an administrator
33*88447a05SGarrett D'Amore#	-i for boot-time initialization (when the system is booted with -r)
34*88447a05SGarrett D'Amore#	-I to suppress error/warning messages; the script is run in the '-i'
35*88447a05SGarrett D'Amore#	mode
36*88447a05SGarrett D'Amore#
37*88447a05SGarrett D'Amore# $2:	devicename - device to be allocated/deallocated, e.g., sr0
38*88447a05SGarrett D'Amore#
39*88447a05SGarrett D'Amore# $3:	-A if cleanup is for allocation, or -D if cleanup is for deallocation.
40*88447a05SGarrett D'Amore#
41*88447a05SGarrett D'Amore# $4:	username - run the script as this user, rather than as the caller.
42*88447a05SGarrett D'Amore#
43*88447a05SGarrett D'Amore# $5:	zonename - zone in which device to be allocated/deallocated
44*88447a05SGarrett D'Amore#
45*88447a05SGarrett D'Amore# $6:	zonepath - root path of zonename
46*88447a05SGarrett D'Amore#
47*88447a05SGarrett D'Amore# Unless the clean script is being called for boot-time
48*88447a05SGarrett D'Amore# initialization, it may communicate with the user via stdin and
49*88447a05SGarrett D'Amore# stdout.  To communicate with the user via CDE dialogs, create a
50*88447a05SGarrett D'Amore# script or link with the same name, but with ".windowing" appended.
51*88447a05SGarrett D'Amore# For example, if the clean script specified in device_allocate is
52*88447a05SGarrett D'Amore# /etc/security/xyz_clean, that script must use stdin/stdout.  If a
53*88447a05SGarrett D'Amore# script named /etc/security/xyz_clean.windowing exists, it must use
54*88447a05SGarrett D'Amore# dialogs.  To present dialogs to the user, the dtksh script
55*88447a05SGarrett D'Amore# /etc/security/lib/wdwmsg may be used.
56*88447a05SGarrett D'Amore#
57*88447a05SGarrett D'Amore# This particular script, audio_clean, will work using stdin/stdout, or
58*88447a05SGarrett D'Amore# using dialogs.  A symbolic link audio_clean.windowing points to
59*88447a05SGarrett D'Amore# audio_clean.
60*88447a05SGarrett D'Amore
61*88447a05SGarrett D'Amore
62*88447a05SGarrett D'Amoretrap "" INT TERM QUIT TSTP ABRT
63*88447a05SGarrett D'Amore
64*88447a05SGarrett D'AmoreUSAGE="usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"
65*88447a05SGarrett D'AmorePATH="/usr/bin:/usr/sbin"
66*88447a05SGarrett D'AmoreWDWMSG="/etc/security/lib/wdwmsg"
67*88447a05SGarrett D'AmoreMODE="allocate"
68*88447a05SGarrett D'Amore
69*88447a05SGarrett D'Amoreif [ `basename $0` != `basename $0 .windowing` ]; then
70*88447a05SGarrett D'Amore  WINDOWING="yes"
71*88447a05SGarrett D'Amoreelse
72*88447a05SGarrett D'Amore  WINDOWING="no"
73*88447a05SGarrett D'Amorefi
74*88447a05SGarrett D'Amore
75*88447a05SGarrett D'Amore#
76*88447a05SGarrett D'Amore# 		*** Shell Function Declarations ***
77*88447a05SGarrett D'Amore#
78*88447a05SGarrett D'Amore
79*88447a05SGarrett D'Amoremsg() {
80*88447a05SGarrett D'Amore  	if [ "$WINDOWING" = "yes" ]; then
81*88447a05SGarrett D'Amore	  if [ $MODE = "allocate" ]; then
82*88447a05SGarrett D'Amore	    TITLE="Audio Device Allocation"
83*88447a05SGarrett D'Amore	    else
84*88447a05SGarrett D'Amore	    TITLE="Audio Device Dellocation"
85*88447a05SGarrett D'Amore	  fi
86*88447a05SGarrett D'Amore	  $WDWMSG "$*" "$TITLE" OK
87*88447a05SGarrett D'Amore	else
88*88447a05SGarrett D'Amore	  echo "$*"
89*88447a05SGarrett D'Amore	fi
90*88447a05SGarrett D'Amore}
91*88447a05SGarrett D'Amore
92*88447a05SGarrett D'Amorefail_msg() {
93*88447a05SGarrett D'Amore	if [ "$MODE" = "allocate" ]; then
94*88447a05SGarrett D'Amore		msg "$0: Allocate of $DEVICE failed."
95*88447a05SGarrett D'Amore	else
96*88447a05SGarrett D'Amore		msg "$0: Deallocate of $DEVICE failed."
97*88447a05SGarrett D'Amore	fi
98*88447a05SGarrett D'Amore	exit 1
99*88447a05SGarrett D'Amore}
100*88447a05SGarrett D'Amore
101*88447a05SGarrett D'Amore#
102*88447a05SGarrett D'Amore# 	Main program
103*88447a05SGarrett D'Amore#
104*88447a05SGarrett D'Amore
105*88447a05SGarrett D'Amore# Check syntax, parse arguments.
106*88447a05SGarrett D'Amore
107*88447a05SGarrett D'Amorewhile getopts ifsI c
108*88447a05SGarrett D'Amoredo
109*88447a05SGarrett D'Amore	case $c in
110*88447a05SGarrett D'Amore	i)
111*88447a05SGarrett D'Amore		FLAG=$c;;
112*88447a05SGarrett D'Amore	f)
113*88447a05SGarrett D'Amore		FLAG=$c;;
114*88447a05SGarrett D'Amore	s)
115*88447a05SGarrett D'Amore		FLAG=$c;;
116*88447a05SGarrett D'Amore	I)
117*88447a05SGarrett D'Amore		FLAG=i
118*88447a05SGarrett D'Amore		silent=y;;
119*88447a05SGarrett D'Amore	\?)  msg $USAGE
120*88447a05SGarrett D'Amore      	     exit 1;;
121*88447a05SGarrett D'Amore	esac
122*88447a05SGarrett D'Amoredone
123*88447a05SGarrett D'Amore
124*88447a05SGarrett D'Amoreshift `expr $OPTIND - 1`
125*88447a05SGarrett D'Amore
126*88447a05SGarrett D'AmoreDEVICE=$1
127*88447a05SGarrett D'Amoreif [ "$2" = "-A" ]; then
128*88447a05SGarrett D'Amore	MODE="allocate"
129*88447a05SGarrett D'Amoreelif [ "$2" = "-D" ]; then
130*88447a05SGarrett D'Amore	MODE="deallocate"
131*88447a05SGarrett D'Amorefi
132*88447a05SGarrett D'Amoreif [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then
133*88447a05SGarrett D'Amore	msg $USAGE
134*88447a05SGarrett D'Amore	exit 1
135*88447a05SGarrett D'Amorefi
136*88447a05SGarrett D'AmoreZONENAME=$4
137*88447a05SGarrett D'AmoreZONEPATH=$5
138*88447a05SGarrett D'AmoreSAVEDIR=/etc/security/audio
139*88447a05SGarrett D'AmoreMAP=`dminfo -v -n $AUDIO`
140*88447a05SGarrett D'AmoreDEVICE=`echo $MAP | cut -f1 -d:`
141*88447a05SGarrett D'AmoreTYPE=`echo $MAP | cut -f2 -d:`
142*88447a05SGarrett D'AmoreFILES=`echo $MAP | cut -f3 -d:`
143*88447a05SGarrett D'Amore
144*88447a05SGarrett D'Amoreif [ ! -d ${SAVEDIR} ]
145*88447a05SGarrett D'Amorethen
146*88447a05SGarrett D'Amore    /usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg
147*88447a05SGarrett D'Amore    /usr/bin/chown root:sys ${SAVEDIR} || fail_msg
148*88447a05SGarrett D'Amorefi
149*88447a05SGarrett D'Amore
150*88447a05SGarrett D'Amorefor d in $FILES
151*88447a05SGarrett D'Amoredo
152*88447a05SGarrett D'Amore    x="`expr $d : '/dev/mixer[0-9][0-9]*'`"
153*88447a05SGarrett D'Amore    if [ "$x" -ne 0 ] ; then
154*88447a05SGarrett D'Amore	DEVNM=$d
155*88447a05SGarrett D'Amore	break
156*88447a05SGarrett D'Amore    fi
157*88447a05SGarrett D'Amoredone
158*88447a05SGarrett D'AmoreSAVEFILE="${SAVEDIR}/`basename ${DEVNM}`"
159*88447a05SGarrett D'Amore
160*88447a05SGarrett D'Amoreif [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ]
161*88447a05SGarrett D'Amorethen
162*88447a05SGarrett D'Amore    /usr/sbin/mixerctl -d ${DEVNM} -f -s ${SAVEFILE} || fail_msg
163*88447a05SGarrett D'Amoreelse
164*88447a05SGarrett D'Amore    /usr/sbin/mixerctl -d ${DEVNM} -r ${SAVEFILE} || fail_msg
165*88447a05SGarrett D'Amorefi
166*88447a05SGarrett D'Amore
167*88447a05SGarrett D'Amoreexit 0
168