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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28#
29#  This a clean script for the floppy drive
30#
31
32PROG=`basename $0`
33PATH="/usr/sbin:/usr/bin"
34TEXTDOMAIN="SUNW_OST_OSCMD"
35export TEXTDOMAIN
36
37USAGE=`gettext "%s [-I|-s|-f|-i] device"`
38
39#
40# 		*** Shell Function Declarations ***
41#
42
43con_msg() {
44    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
45    if [ "$silent" != "y" ] ; then
46	printf "${form}\n" $PROG $DEVICE > /dev/console
47    fi
48}
49
50e_con_msg() {
51    form=`gettext "%s: Error cleaning up device %s."`
52    if [ "$silent" != "y" ] ; then
53	printf "${form}\n" $PROG $DEVICE > /dev/console
54    fi
55}
56
57user_msg() {
58    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
59    if [ "$silent" != "y" ] ; then
60	printf "${form}\n" $PROG $DEVICE > /dev/tty
61    fi
62}
63
64e_user_msg() {
65    form=`gettext "%s: Error cleaning up device %s."`
66    if [ "$silent" != "y" ] ; then
67	printf "${form}\n" $PROG $DEVICE > /dev/tty
68	gettext "Please inform system administrator.\n" > /dev/tty
69    fi
70}
71
72mk_error() {
73   chown bin /etc/security/dev/$1
74   chmod 0100 /etc/security/dev/$1
75}
76
77#
78# 		*** Begin main program ***
79#
80
81silent=n
82
83# Parse the argumnets
84
85while getopts Iifs c
86do
87   case $c in
88   I)	FLAG=i
89	silent=y;;
90   i)   FLAG=$c;;
91   f)   FLAG=$c;;
92   s)   FLAG=$c;;
93   \?)   printf "${USAGE}\n" $PROG
94      exit 1 ;;
95   esac
96done
97shift `expr $OPTIND - 1`
98
99# get the map information
100
101FLOPPY=$1
102MAP=`dminfo -v -n $FLOPPY`
103DEVICE=`echo $MAP | cut -f1 -d:`
104TYPE=`echo $MAP | cut -f2 -d:`
105FILES=`echo $MAP | cut -f3 -d:`
106DEVFILE=`echo $FILES | cut -f1 -d" "`
107
108#if init then do once and exit
109
110lform=`gettext "%s error: %s."`
111
112if [ "$FLAG" = "i" ] ; then
113   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
114   z="$?"
115
116   case $z in
117   0) 					# Media is in the drive.
118	a="`eject -f $DEVFILE 2>&1`"
119	b="$?"
120
121	case $b in
122	0)				# Media has been ejected
123		con_msg
124		exit 0;;
125	1)				# Media not ejected
126		mk_error $DEVICE
127		if [ "$silent" != "y" ] ; then
128			printf "${lform}\n" $PROG $a >/dev/tty
129		fi
130		e_con_msg
131		exit 1;;
132	2)			# Error
133		mk_error $DEVICE
134		if [ "$silent" != "y" ] ; then
135			printf "${lform}\n" $PROG $a >/dev/tty
136		fi
137		e_con_msg
138		exit 1;;
139	3)			# Error - Perhaps drive doesn't support ejection
140		mk_error $DEVICE
141		if [ "$silent" != "y" ] ; then
142			printf "${lform}\n" $PROG $a >/dev/tty
143		fi
144		e_con_msg
145		exit 1;;
146	esac;;
147   1) 		# No media in drive
148	con_msg
149	exit 0;;
150   2)			# Error
151		mk_error $DEVICE
152		if [ "$silent" != "y" ] ; then
153			printf "${lform}\n" $PROG $x >/dev/tty
154		fi
155		e_con_msg
156		exit 1;;
157   3)			# Error
158		mk_error $DEVICE
159		if [ "$silent" != "y" ] ; then
160			printf "${lform}\n" $PROG $x >/dev/tty
161		fi
162		e_con_msg
163		exit 1;;
164   esac
165else
166# interactive clean up
167   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
168   z="$?"
169
170   case $z in
171   0)					# Media is in the drive.
172	a="`eject -f $DEVFILE 2>&1`"
173	b="$?"
174	case $b in
175	0)				# Media has been ejected
176		user_msg
177		exit 0;;
178	1)				# Media didn't eject
179         	mk_error $DEVICE
180		if [ "$silent" != "y" ] ; then
181			printf "${lform}\n" $PROG $a >/dev/tty
182		fi
183         	e_user_msg
184         	exit 1;;
185	2)				# Other Error
186		mk_error $DEVICE
187		if [ "$silent" != "y" ] ; then
188			printf "${lform}\n" $PROG $a >/dev/tty
189		fi
190		e_user_msg
191         	exit 1;;
192	3)
193
194		if echo $a | grep "failed" >/dev/null ; then
195         	while true 		# Drive doesn't support eject, so loop
196         	    do
197			c="`eject -q $DEVFILE 2>&1`"	# Is floppy in drive?
198			d="$?"
199            		if [ $d -eq 0 ] ; then		# Yes, Floppy in drive
200				form=`gettext "Please remove the floppy from %s."`
201				if [ "$silent" != "y" ] ; then
202               				printf "${form}\n" $DEVICE >/dev/tty
203					/usr/5bin/echo \\007 > /dev/tty
204				fi
205               			sleep 3
206            		elif echo $c | grep "NOT" > /dev/null ; then
207							# No,Floppy NOT in drive
208               			user_msg
209               			exit 0
210			else				# Error occurred
211         			mk_error $DEVICE
212				if [ "$silent" != "y" ] ; then
213					printf "${lform}\n" $PROG $a >/dev/tty
214				fi
215				e_user_msg
216         			exit 1
217            		fi
218         	    done
219		else 					# Some other failure
220			if [ "$silent" != "y" ] ; then
221				printf "${lform}\n" $PROG $a >/dev/tty
222			fi
223         		e_user_msg
224         		mk_error $DEVICE
225         		exit 1
226		fi;;
227
228	esac;;
229   1)							# No media in the drive
230         user_msg
231         exit 0;;
232   2)
233       	mk_error $DEVICE
234	if [ "$silent" != "y" ] ; then
235		printf "${lform}\n" $PROG $x >/dev/tty
236	fi
237	e_user_msg
238       	exit 1;;
239   3)
240       	mk_error $DEVICE
241	if [ "$silent" != "y" ] ; then
242		printf "${lform}\n" $PROG $x >/dev/tty
243	fi
244	e_user_msg
245       	exit 1;;
246   esac
247fi
248exit 2
249#! /bin/sh
250#
251# CDDL HEADER START
252#
253# The contents of this file are subject to the terms of the
254# Common Development and Distribution License, Version 1.0 only
255# (the "License").  You may not use this file except in compliance
256# with the License.
257#
258# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
259# or http://www.opensolaris.org/os/licensing.
260# See the License for the specific language governing permissions
261# and limitations under the License.
262#
263# When distributing Covered Code, include this CDDL HEADER in each
264# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
265# If applicable, add the following below this CDDL HEADER, with the
266# fields enclosed by brackets "[]" replaced with your own identifying
267# information: Portions Copyright [yyyy] [name of copyright owner]
268#
269# CDDL HEADER END
270#
271#
272# Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
273# All rights reserved.
274#
275#ident	"%Z%%M%	%I%	%E% SMI"
276#
277#  This a clean script for the CD_ROM
278#
279
280PROG=`basename $0`
281PATH="/usr/sbin:/usr/bin"
282TEXTDOMAIN="SUNW_OST_OSCMD"
283export TEXTDOMAIN
284
285USAGE=`gettext "%s [-I|-s|-f|-i] device"`
286
287#
288# 			*** Shell Function Definitions ***
289#
290
291con_msg() {
292    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
293    if [ "$silent" != "y" ] ; then
294	printf "${form}\n" $PROG $DEVICE > /dev/console
295    fi
296}
297
298e_con_msg() {
299    form=`gettext "%s: Error cleaning up device %s."`
300    if [ "$silent" != "y" ] ; then
301	printf "${form}\n" `basename $0` $DEVICE > /dev/console
302    fi
303}
304
305user_msg() {
306    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
307    if [ "$silent" != "y" ] ; then
308	printf "${form}\n" $PROG $DEVICE > /dev/tty
309    fi
310}
311
312e_user_msg() {
313    form=`gettext "%s: Error cleaning up device %s."`
314    if [ "$silent" != "y" ] ; then
315	printf "${form}\n" $PROG $DEVICE > /dev/tty
316	gettext "Please inform system administrator.\n" > /dev/tty
317    fi
318}
319
320mk_error() {
321   chown bin /etc/security/dev/$1
322   chmod 0100 /etc/security/dev/$1
323}
324
325#
326#			*** Begin Main Program ***
327#
328silent=n
329
330while getopts Iifs c
331do
332   case $c in
333   I)	FLAG=i
334	silent=y;;
335   i)   FLAG=$c;;
336   f)   FLAG=$c;;
337   s)   FLAG=$c;;
338   \?)   printf "${USAGE}\n" $PROG >/dev/tty
339      exit 1 ;;
340   esac
341done
342shift `expr $OPTIND - 1`
343
344# get the map information
345
346FLOPPY=$1
347MAP=`dminfo -v -n $FLOPPY`
348DEVICE=`echo $MAP | cut -f1 -d:`
349TYPE=`echo $MAP | cut -f2 -d:`
350FILES=`echo $MAP | cut -f3 -d:`
351DEVFILE=`echo $FILES | cut -f1 -d" "`
352
353#if init then do once and exit
354
355lform=`gettext "%s error: %s."`
356
357if [ "$FLAG" = "i" ] ; then
358   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
359   z="$?"
360
361   case $z in
362   0) 					# Media is in the drive.
363	a="`eject -f $DEVFILE 2>&1`"
364	b="$?"
365
366	case $b in
367	0)				# Media has been ejected
368		con_msg
369		exit 0;;
370	1)				# Media not ejected
371		mk_error $DEVICE
372		if [ "$silent" != "y" ] ; then
373			printf "${lform}\n" $PROG $a >/dev/tty
374		fi
375		e_con_msg
376		exit 1;;
377	2)			# Error
378		mk_error $DEVICE
379		if [ "$silent" != "y" ] ; then
380			printf "${lform}\n" $PROG $a >/dev/tty
381		fi
382		e_con_msg
383		exit 1;;
384	3)			# Error - Perhaps drive doesn't support ejection
385		mk_error $DEVICE
386		if [ "$silent" != "y" ] ; then
387			printf "${lform}\n" $PROG $a >/dev/tty
388		fi
389		e_con_msg
390		exit 1;;
391	esac;;
392   1) 		# No media in drive
393	con_msg
394	exit 0;;
395   2)			# Error
396		mk_error $DEVICE
397		if [ "$silent" != "y" ] ; then
398			printf "${lform}\n" $PROG $x >/dev/tty
399		fi
400		e_con_msg
401		exit 1;;
402   3)			# Error
403		mk_error $DEVICE
404		if [ "$silent" != "y" ] ; then
405			printf "${lform}\n" $PROG $x >/dev/tty
406		fi
407		e_con_msg
408		exit 1;;
409   esac
410else
411# interactive clean up
412   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
413   z="$?"
414
415   case $z in
416   0)					# Media is in the drive.
417	a="`eject -f $DEVFILE 2>&1`"
418	b="$?"
419	case $b in
420	0)				# Media has been ejected
421		user_msg
422		exit 0;;
423	1)				# Media not ejected
424         	mk_error $DEVICE
425		if [ "$silent" != "y" ] ; then
426			printf "${lform}\n" $PROG $a >/dev/tty
427		fi
428         	e_user_msg
429         	exit 1;;
430	2)				# Other Error
431		mk_error $DEVICE
432		if [ "$silent" != "y" ] ; then
433			printf "${lform}\n" $PROG $a >/dev/tty
434		fi
435		e_user_msg
436         	exit 1;;
437	3)
438
439		if echo $a | grep "failed" >/dev/null ; then
440         	while true 		# Drive doesn't support eject, so loop
441         	    do
442			c="`eject -q $DEVFILE 2>&1`"	# Is caddy in drive?
443			d="$?"
444            		if [ $d -eq 0 ] ; then		# Yes, Caddy in drive
445				form=`gettext "Please remove the caddy from %s."`
446				if [ "$silent" != "y" ] ; then
447               				printf "${form}\n" $DEVICE  >/dev/tty
448               				/usr/5bin/echo \\007 >/dev/tty
449				fi
450               			sleep 3
451            		elif echo $c | grep "NOT" > /dev/null ; then
452							# No,Caddy NOT in drive
453               			user_msg
454               			exit 0
455			else				# Error occurred
456         			mk_error $DEVICE
457				if [ "$silent" != "y" ] ; then
458					printf "${lform}\n" $PROG $a >/dev/tty
459				fi
460				e_user_msg
461         			exit 1
462            		fi
463         	    done
464		else 					# Some other failure
465			if [ "$silent" != "y" ] ; then
466				printf "${lform}\n" $PROG $a >/dev/tty
467			fi
468         		e_user_msg
469         		mk_error $DEVICE
470         		exit 1
471		fi;;
472
473	esac;;
474   1)							# No media in the drive
475         user_msg
476         exit 0;;
477   2)
478       	mk_error $DEVICE
479	if [ "$silent" != "y" ] ; then
480		printf "${lform}\n" $PROG $x >/dev/tty
481	fi
482	e_user_msg
483       	exit 1;;
484   3)
485       	mk_error $DEVICE
486	if [ "$silent" != "y" ] ; then
487		printf "${lform}\n" $PROG $x >/dev/tty
488	fi
489	e_user_msg
490       	exit 1;;
491   esac
492fi
493exit 2
494#! /bin/sh
495#
496# CDDL HEADER START
497#
498# The contents of this file are subject to the terms of the
499# Common Development and Distribution License, Version 1.0 only
500# (the "License").  You may not use this file except in compliance
501# with the License.
502#
503# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
504# or http://www.opensolaris.org/os/licensing.
505# See the License for the specific language governing permissions
506# and limitations under the License.
507#
508# When distributing Covered Code, include this CDDL HEADER in each
509# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
510# If applicable, add the following below this CDDL HEADER, with the
511# fields enclosed by brackets "[]" replaced with your own identifying
512# information: Portions Copyright [yyyy] [name of copyright owner]
513#
514# CDDL HEADER END
515#
516#
517# Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
518# All rights reserved.
519#
520#ident	"%Z%%M%	%I%	%E% SMI"
521#
522#  This a clean script for all tape drives
523#
524
525PROG=`basename $0`
526PATH="/usr/sbin:/usr/bin"
527TEXTDOMAIN="SUNW_OST_OSCMD"
528export TEXTDOMAIN
529
530USAGE=`gettext "%s [-I|-s|-f|-i] device"`
531
532#
533# 		*** Shell Function Declarations ***
534#
535
536
537con_msg() {
538    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
539    if [ "$silent" != "y" ] ; then
540	printf "${form}\n" $PROG $DEVICE > /dev/console
541    fi
542}
543
544e_con_msg() {
545    form=`gettext "%s: Error cleaning up device %s."`
546    if [ "$silent" != "y" ] ; then
547	printf "${form}\n" $PROG $DEVICE > /dev/console
548    fi
549}
550
551user_msg() {
552    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
553    if [ "$silent" != "y" ] ; then
554	printf "${form}\n" $PROG $DEVICE > /dev/tty
555    fi
556}
557
558e_user_msg() {
559    form=`gettext "%s: Error cleaning up device %s."`
560    if [ "$silent" != "y" ] ; then
561	printf "${form}" $PROG $DEVICE > /dev/tty
562	gettext "Please inform system administrator.\n" > /dev/tty
563    fi
564}
565
566mk_error() {
567   chown bin /etc/security/dev/$1
568   chmod 0100 /etc/security/dev/$1
569}
570
571silent=n
572
573while getopts Iifs c
574do
575   case $c in
576   I)	FLAG=i
577	silent=y;;
578   i)   FLAG=$c;;
579   f)   FLAG=$c;;
580   s)   FLAG=$c;;
581   \?)   printf "${USAGE}\n" $PROG >/dev/tty
582      exit 1 ;;
583   esac
584done
585shift `expr $OPTIND - 1`
586
587# get the map information
588
589TAPE=$1
590MAP=`dminfo -v -n $TAPE`
591DEVICE=`echo $MAP | cut -f1 -d:`
592TYPE=`echo $MAP | cut -f2 -d:`
593FILES=`echo $MAP | cut -f3 -d:`
594DEVFILE=`echo $FILES | cut -f1 -d" "`
595
596#if init then do once and exit
597
598if [ "$FLAG" = "i" ] ; then
599   x="`mt -f $DEVFILE rewoffl 2>&1`"
600   z="$?"
601
602   case $z in
603   0)
604
605   # if this is a open reel tape than we a sucessful
606   # else must be a cartrige tape we failed
607
608      if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" >/dev/null ; then
609         con_msg
610         exit 0
611      else
612         e_con_msg
613         mk_error $DEVICE
614         exit 1
615      fi;;
616   1)
617
618   # only one error mesage is satisfactory
619
620      if echo $x | grep "no tape loaded" >/dev/null ; then
621         con_msg
622         exit 0
623      else
624         e_con_msg
625         mk_error $DEVICE
626         exit 1
627      fi;;
628
629   2)
630
631   # clean up failed exit with error
632
633      e_con_msg
634      mk_error $DEVICE
635      exit 1;;
636
637   esac
638else
639# interactive clean up
640   x="`mt -f $DEVFILE rewoffl 2>&1`"
641   z="$?"
642
643   case $z in
644   0)
645
646   # if this is a open reel tape than we a sucessful
647   # else must be a cartrige tape we must retry until user removes tape
648
649      if mt -f $DEVFILE status 2>&1 | grep "no tape loaded"  > /dev/null ; then
650         user_msg
651         exit 0
652      else
653         while true
654         do
655            if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" > /dev/null ; then
656                user_msg
657                exit 0
658            else
659		form=`gettext "Please remove the tape from the %s."`
660		if [ "$silent" != "y" ] ; then
661                	printf "${form}\n" $DEVICE  >/dev/tty
662                	/usr/5bin/echo \\007 >/dev/tty
663		fi
664                sleep 3
665            fi
666         done
667      fi;;
668   1)
669
670   # only one error mesage is satisfactory
671
672      if echo $x | grep "no tape loaded" > /dev/null ; then
673         user_msg
674         exit 0
675      else
676         e_user_msg
677         mk_error $DEVICE
678         exit 1
679      fi;;
680
681   2)
682
683   # clean up failed exit with error
684
685      e_user_msg
686      mk_error $DEVICE
687      exit 1;;
688
689   esac
690fi
691exit 2
692#! /bin/sh
693#
694# CDDL HEADER START
695#
696# The contents of this file are subject to the terms of the
697# Common Development and Distribution License (the "License").
698# You may not use this file except in compliance with the License.
699#
700# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
701# or http://www.opensolaris.org/os/licensing.
702# See the License for the specific language governing permissions
703# and limitations under the License.
704#
705# When distributing Covered Code, include this CDDL HEADER in each
706# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
707# If applicable, add the following below this CDDL HEADER, with the
708# fields enclosed by brackets "[]" replaced with your own identifying
709# information: Portions Copyright [yyyy] [name of copyright owner]
710#
711# CDDL HEADER END
712#
713# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
714# Use is subject to license terms.
715#
716# This is the audio_clean program.
717#
718# Following is the syntax for calling the script:
719#	scriptname [-s|-f|-i|-I] devicename [-A|-D] [username] [zonename]
720#           [zonepath]
721#
722# $1:	-s for standard cleanup by a user
723#	-f for forced cleanup by an administrator
724#	-i for boot-time initialization (when the system is booted with -r)
725#	-I to suppress error/warning messages; the script is run in the '-i'
726#	mode
727#
728# $2:	devicename - device to be allocated/deallocated, e.g., sr0
729#
730# $3:	-A if cleanup is for allocation, or -D if cleanup is for deallocation.
731#
732# $4:	username - run the script as this user, rather than as the caller.
733#
734# $5:	zonename - zone in which device to be allocated/deallocated
735#
736# $6:	zonepath - root path of zonename
737#
738# Unless the clean script is being called for boot-time
739# initialization, it may communicate with the user via stdin and
740# stdout.  To communicate with the user via CDE dialogs, create a
741# script or link with the same name, but with ".windowing" appended.
742# For example, if the clean script specified in device_allocate is
743# /etc/security/xyz_clean, that script must use stdin/stdout.  If a
744# script named /etc/security/xyz_clean.windowing exists, it must use
745# dialogs.  To present dialogs to the user, the dtksh script
746# /etc/security/lib/wdwmsg may be used.
747#
748# This particular script, audio_clean, will work using stdin/stdout, or
749# using dialogs.  A symbolic link audio_clean.windowing points to
750# audio_clean.
751
752
753trap "" INT TERM QUIT TSTP ABRT
754
755USAGE="usage: $0 [-s|-f|-i|-I] devicename [-A|-D][username][zonename][zonepath]"
756PATH="/usr/bin:/usr/sbin"
757WDWMSG="/etc/security/lib/wdwmsg"
758MODE="allocate"
759
760if [ `basename $0` != `basename $0 .windowing` ]; then
761  WINDOWING="yes"
762else
763  WINDOWING="no"
764fi
765
766#
767# 		*** Shell Function Declarations ***
768#
769
770msg() {
771  	if [ "$WINDOWING" = "yes" ]; then
772	  if [ $MODE = "allocate" ]; then
773	    TITLE="Audio Device Allocation"
774	    else
775	    TITLE="Audio Device Dellocation"
776	  fi
777	  $WDWMSG "$*" "$TITLE" OK
778	else
779	  echo "$*"
780	fi
781}
782
783fail_msg() {
784	if [ "$MODE" = "allocate" ]; then
785		msg "$0: Allocate of $DEVICE failed."
786	else
787		msg "$0: Deallocate of $DEVICE failed."
788	fi
789	exit 1
790}
791
792#
793# 	Main program
794#
795
796# Check syntax, parse arguments.
797
798while getopts ifsI c
799do
800	case $c in
801	i)
802		FLAG=$c;;
803	f)
804		FLAG=$c;;
805	s)
806		FLAG=$c;;
807	I)
808		FLAG=i
809		silent=y;;
810	\?)  msg $USAGE
811      	     exit 1;;
812	esac
813done
814
815shift `expr $OPTIND - 1`
816
817DEVICE=$1
818if [ "$2" = "-A" ]; then
819	MODE="allocate"
820elif [ "$2" = "-D" ]; then
821	MODE="deallocate"
822fi
823if [ "$MODE" != "allocate" -a "$MODE" != "deallocate" ]; then
824	msg $USAGE
825	exit 1
826fi
827ZONENAME=$4
828ZONEPATH=$5
829SAVEDIR=/etc/security/audio
830MAP=`dminfo -v -n $DEVICE`
831DEVICE=`echo $MAP | cut -f1 -d:`
832TYPE=`echo $MAP | cut -f2 -d:`
833FILES=`echo $MAP | cut -f3 -d:`
834
835if [ ! -d ${SAVEDIR} ]
836then
837    /usr/bin/mkdir -m 0755 -p ${SAVEDIR} || fail_msg
838    /usr/bin/chown root:sys ${SAVEDIR} || fail_msg
839fi
840
841for d in $FILES
842do
843    x="`expr $d : '/dev/mixer[0-9][0-9]*'`"
844    if [ "$x" -ne 0 ] ; then
845	DEVNM=$d
846	break
847    fi
848done
849SAVEFILE="${SAVEDIR}/`basename ${DEVNM}`"
850
851if [ "${FLAG}" = "i" -a ! -r "${SAVEFILE}" ]
852then
853    /usr/bin/audioctl save-controls -d ${DEVNM} -f ${SAVEFILE} || fail_msg
854else
855    /usr/bin/audioctl load-controls -d ${DEVNM} ${SAVEFILE} || fail_msg
856fi
857
858exit 0
859#! /usr/bin/sh
860#
861# CDDL HEADER START
862#
863# The contents of this file are subject to the terms of the
864# Common Development and Distribution License (the "License").
865# You may not use this file except in compliance with the License.
866#
867# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
868# or http://www.opensolaris.org/os/licensing.
869# See the License for the specific language governing permissions
870# and limitations under the License.
871#
872# When distributing Covered Code, include this CDDL HEADER in each
873# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
874# If applicable, add the following below this CDDL HEADER, with the
875# fields enclosed by brackets "[]" replaced with your own identifying
876# information: Portions Copyright [yyyy] [name of copyright owner]
877#
878# CDDL HEADER END
879#
880# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
881# Use is subject to license terms.
882#
883#
884# This is a clean script for removable disks
885#
886# Following is the syntax for calling the script:
887#	scriptname [-s|-f|-i|-I] devicename [-A|-D] username zonename zonepath
888#
889#    	-s for standard cleanup by a user
890# 	-f for forced cleanup by an administrator
891# 	-i for boot-time initialization (when the system is booted with -r)
892# 	-I to suppress error/warning messages; the script is run in the '-i'
893#	   mode
894#
895# $1:	devicename - device to be allocated/deallocated, e.g., sr0
896#
897# $2:	-A if cleanup is for allocation, or -D if cleanup is for deallocation.
898#
899# $3:	username - run the script as this user, rather than as the caller.
900#
901# $4:	zonename - zone in which device to be allocated/deallocated
902#
903# $5:	zonepath - root path of zonename
904#
905# A clean script for a removable media device should prompt the user to
906# insert correctly labeled media at allocation time, and ensure that the
907# media is ejected at deallocation time.
908#
909# Unless the clean script is being called for boot-time
910# initialization, it may communicate with the user via stdin and
911# stdout.  To communicate with the user via CDE dialogs, create a
912# script or link with the same name, but with ".windowing" appended.
913# For example, if the clean script specified in device_allocate is
914# /etc/security/xyz_clean, that script must use stdin/stdout.  If a
915# script named /etc/security/xyz_clean.windowing exists, it must use
916# dialogs.  To present dialogs to the user, the dtksh script
917# /etc/security/lib/wdwmsg may be used.
918#
919# This particular script, disk_clean, will work using stdin/stdout, or
920# using dialogs.  A symbolic link disk_clean.windowing points to
921# disk_clean.
922#
923
924# ####################################################
925# ################  Local Functions  #################
926# ####################################################
927
928#
929# Set up for windowing and non-windowing messages
930#
931msg_init()
932{
933    if [ `basename $0` != `basename $0 .windowing` ]; then
934	WINDOWING="yes"
935	case $VOLUME_MEDIATYPE in
936	  cdrom)   TITLE="CD-ROM";;
937	  rmdisk)  TITLE="Removable Disk";;
938	  floppy)  TITLE="Floppy";;
939	  *)       TITLE="Disk";;
940	esac
941
942	if [ "$MODE" = "allocate" ]; then
943	    TITLE="$TITLE Allocation"
944	else
945	    TITLE="$TITLE Deallocation"
946	fi
947    else
948	WINDOWING="no"
949    fi
950}
951
952#
953# Display a message for the user.  For windowing, user must press OK button
954# to continue. For non-windowing, no response is required.
955#
956msg() {
957    if [ "$WINDOWING" = "yes" ]; then
958	$WDWMSG "$*" "$TITLE" OK
959    elif [ "$silent" != "y" ]; then
960	echo "$*" > /dev/${MSGDEV}
961    fi
962}
963
964ok_msg() {
965	if [ "$WINDOWING" = "yes" ]; then
966		$WDWMSG "$*" "$TITLE" READY
967	else
968		form=`gettext "Media in %s is ready. Please store safely."`
969		printf "${form}\n" $PROG $DEVICE > /dev/{MSGDEV}
970	fi
971}
972
973error_msg() {
974	if [ "$WINDOWING" = "yes" ]; then
975		$WDWMSG "$*" "$TITLE" ERROR
976	else
977		form=`gettext "%s: Error cleaning up device %s."`
978		printf "${form}\n" $PROG $DEVICE > /dev/${MSGDEV}
979	fi
980}
981
982#
983# Ask the user an OK/Cancel question.  Return 0 for OK, 1 for Cancel.
984#
985okcancel() {
986    if [ "$WINDOWING" = "yes" ]; then
987	$WDWMSG "$*" "$TITLE" OK Cancel
988    elif [ "$silent" != "y" ]; then
989	get_reply "$* (y to continue, n to cancel) \c" y n
990    fi
991}
992
993#
994# Ask the user an Yes/No question.  Return 0 for Yes, 1 for No
995#
996yesno() {
997    if [ "$WINDOWING" = "yes" ]; then
998	$WDWMSG "$*" "$TITLE" Yes No
999    elif [ "$silent" != "y" ]; then
1000	get_reply "$* (y/n) \c" y n
1001    fi
1002}
1003
1004#
1005# Display an error message, put the device in the error state, and exit.
1006#
1007error_exit() {
1008	if [ "$silent" != "y" ]; then
1009		msg "$2" "$3" \
1010		    "\n\nDevice has been placed in allocation error state." \
1011		    "\nPlease inform system administrator."
1012	fi
1013	exit 1
1014}
1015
1016#
1017# get_reply prompt choice ...
1018#
1019get_reply() {
1020	prompt=$1; shift
1021	while true
1022	do
1023		echo $prompt > /dev/tty
1024		read reply
1025		i=0
1026		for choice in $*
1027		do
1028			if [ "$choice" = "$reply" ]
1029			then
1030				return $i
1031			else
1032				i=`expr $i + 1`
1033			fi
1034		done
1035	done
1036}
1037
1038#
1039# Find the first disk slice containing a file system
1040#
1041find_fs()
1042{
1043	# The list of files in device_maps(4) is in an unspecified order.
1044	# To speed up the fstyp(1M) scanning below in most cases, perform
1045	# the search for filesystems as follows:
1046	# 1) Select only block device files of the form "/dev/dsk/*".
1047	# 2) Sort the list of files in an order more likely to yield
1048	#    matches: first the fdisk(1M) partitions ("/dev/dsk/cNtNdNpN")
1049	#    then the format(1M) slices ("/dev/dsk/cNtNdNsN"), in ascending
1050	#    numeric order within each group.
1051	DEVall="`echo $FILES | \
1052	    /usr/bin/tr ' ' '\n' | \
1053	    /usr/bin/sed '/^\/dev\/dsk\//!d; s/\([sp]\)\([0-9]*\)$/ \1 \2/;' | \
1054	    /usr/bin/sort -t ' ' -k 2,2d -k 3,3n | \
1055	    /usr/bin/tr -d ' '`"
1056	for DEVn in $DEVall ; do
1057		fstyp_output="`/usr/sbin/fstyp -a $DEVn 2>&1`"
1058		if [ $? = 0 ]; then
1059			FSPATH=$DEVn
1060			gen_volume_label="`echo "$fstyp_output" | \
1061			    sed -n '/^gen_volume_label: .\(.*\).$/s//\1/p'`"
1062			if [ "$gen_volume_label" != "" ]; then
1063				FSNAME="`echo $gen_volume_label | \
1064				    /usr/xpg4/bin/tr '[:upper:] ' '[:lower:]_'`"
1065			fi
1066			# For consistency, hsfs filesystems detected at
1067			# /dev/dsk/*p0 are mounted as /dev/dsk/*s2
1068			FSTYPE=`echo "$fstyp_output" | /usr/bin/head -1`
1069			if [ "$FSTYPE" = hsfs -a \
1070			    `/usr/bin/expr $FSPATH : '.*p0'` -gt 0 ]; then
1071				FSPATH=`echo $FSPATH | /usr/bin/sed 's/p0$/s2/'`
1072			fi
1073			return
1074		fi
1075	done
1076}
1077
1078#
1079# Find all mountpoints in use for a set of device special files.
1080# Usage: findmounts devpath ...
1081#
1082
1083findmounts() {
1084	nawk -f - -v vold_root="$VOLD_ROOT" -v devs="$*" /etc/mnttab <<\
1085	    "ENDOFAWKPGM"
1086	BEGIN {
1087		split(devs, devlist, " ");
1088		for (devN in devlist) {
1089			dev = devlist[devN];
1090			realdevlist[dev] = 1;
1091			sub(/.*\//, "", dev);
1092			sub(/s[0-9]$/, "", dev);
1093			if (vold_root != "") {
1094				vold_dir[vold_root "/dev/dsk/" dev] = 1;
1095				vold_dir[vold_root "/dev/rdsk/" dev] = 1;
1096			}
1097		}
1098	}
1099
1100	{
1101		for (dev in realdevlist) {
1102			if ($1 == dev) {
1103				mountpoint = $2;
1104				print mountpoint;
1105			}
1106		}
1107		for (dev in vold_dir) {
1108			if (substr($1, 1, length(dev)) == dev) {
1109				mountpoint = $2;
1110				print mountpoint;
1111			}
1112		}
1113	}
1114ENDOFAWKPGM
1115}
1116
1117#
1118# Allocate a device.
1119# Ask the user to make sure the disk is properly labeled.
1120# Ask if the disk should be mounted.
1121#
1122do_allocate()
1123{
1124	if [ $VOLUME_MEDIATYPE = floppy ]; then
1125		# Determine if media is in drive
1126		eject_msg="`eject -q $DEVFILE 2>&1`"
1127		eject_status="$?"
1128		case $eject_status in
1129		1) # Media is not in drive
1130			okcancel "Insert disk in $DEVICE."
1131			if [ $? != 0 ]; then
1132				exit 0
1133			fi;;
1134		3) # Error
1135			error_exit $DEVICE \
1136			    "Error checking for media in drive.";;
1137		esac
1138	else
1139		okcancel "Insert disk in $DEVICE."
1140		if [ $? != 0 ]; then
1141			exit 0
1142		fi
1143	fi
1144
1145	yesno "Do you want $DEVICE mounted?"
1146	if [ $? != 0 ]; then
1147		exit 0
1148	fi
1149
1150	if [ $VOLUME_MEDIATYPE = cdrom -o $VOLUME_MEDIATYPE = rmdisk ]; then
1151		# Get the device path and volume name of a partition
1152		find_fs
1153		if [ "$FSPATH" != "" ]; then
1154			VOLUME_PATH=$FSPATH
1155		fi
1156		if [ "$FSNAME" != "" ]; then
1157			VOLUME_NAME=$FSNAME
1158		fi
1159	fi
1160	VOLUME_ACTION=insert
1161
1162	# Give ourself write permission on device file so file system gets
1163	# mounted read/write if possible.
1164	# rmmount only cares about permissions not user...
1165	chown $VOLUME_USER $VOLUME_PATH
1166	chmod 700 $VOLUME_PATH
1167
1168	# Do the actual mount.  VOLUME_* environment variables are inputs to
1169	# rmmount.
1170	rmmount_msg="`/usr/sbin/rmmount 2>&1`"
1171	rmmount_status="$?"
1172	if [ $rmmount_status -eq 0 ]; then
1173		EXIT_STATUS=$CLEAN_MOUNT
1174	elif [ $rmmount_status -gt 0 -a $VOLUME_MEDIATYPE != cdrom ]; then
1175		# Try again in readonly mode. cdrom is always mounted ro, so
1176		# no need to try again.
1177		echo "Read-write mount of $DEVICE failed. Mounting read-only."
1178		VOLUME_ACTION=remount; export VOLUME_ACTION
1179		VOLUME_MOUNT_MODE=ro; export VOLUME_MOUNT_MODE
1180		`/usr/sbin/rmmount`
1181		if [ $? -eq 0 ]; then
1182			EXIT_STATUS=$CLEAN_MOUNT
1183		fi
1184	fi
1185
1186	# Set permissions on directory used by vold, sdtvolcheck, etc.
1187	if [ -d /tmp/.removable ]; then
1188		chown root /tmp/.removable
1189		chmod 777 /tmp/.removable
1190	fi
1191}
1192
1193
1194do_deallocate()
1195{
1196	if [ $VOLUME_MEDIATYPE = cdrom -o $VOLUME_MEDIATYPE = rmdisk ]; then
1197		if [ -h /$VOLUME_MEDIATYPE/$DEVICE ]; then
1198			# Get the device path and volume name of a partition
1199			VOLUME_PATH=`ls -l /$VOLUME_MEDIATYPE/$DEVICE|\
1200			    cut -d '>' -f2`
1201			VOLUME_DEVICE=`mount -p|grep $VOLUME_PATH|\
1202			    cut -d ' ' -f1`
1203		fi
1204	fi
1205
1206	if [ -d "$VOLUME_PATH" ]; then
1207		VOLUME_ACTION=eject
1208		# Do the actual unmount.
1209		# VOLUME_* environment variables are inputs to rmmount.
1210		rmmount_msg="`/usr/sbin/rmmount 2>&1`"
1211		rmmount_status="$?"
1212
1213		# Remove symbolic links to mount point
1214		for name in /$VOLUME_MEDIATYPE/*; do
1215			if [ -h $name ]; then
1216				target=`ls -l $name | awk '{ print $NF; }'`
1217				target_dir=`dirname $target`
1218				target_device=`echo $target_dir | \
1219				    sed -e 's/^.*-\(.*\)$/\1/'`
1220				if [ "$target_device" = "$DEVICE" ]; then
1221					rm -f $name
1222				fi
1223			fi
1224		done
1225	else
1226		rmmount_status=0
1227	fi
1228
1229	case $rmmount_status in
1230	1) # still mounted
1231		error_exit $DEVICE "Error unmounting $DEVICE" "$rmmount_msg";;
1232	0) # not mounted
1233		# Eject the media
1234		if [ "$FLAG" = "f" ] ; then
1235			eject_msg="`eject -f $DEVICE 2>&1`"
1236		else
1237			eject_msg="`eject $DEVICE 2>&1`"
1238		fi
1239		eject_status="$?"
1240		case $eject_status in
1241		0|1|4) # Media has been ejected
1242			case $VOLUME_MEDIATYPE in
1243			floppy|cdrom|rmdisk)
1244				msg "Please remove the disk from $DEVICE.";;
1245			esac;;
1246		3) # Media didn't eject
1247			msg $DEVICE "Error ejecting disk from $DEVICE" \
1248			    "$eject_msg";;
1249		esac
1250	esac
1251}
1252
1253#
1254# Reclaim a device
1255#
1256do_init()
1257{
1258	eject_msg="`eject -f $DEVICE 2>&1`"
1259	eject_status="$?"
1260
1261	case $eject_status in
1262	0) # Media has been ejected
1263		if [ "$silent" != "y" ]; then
1264			ok_msg
1265		fi
1266		exit 0;;
1267	1) # Media not ejected
1268		if [ "$silent" != "y" ]; then
1269			error_msg
1270		fi
1271		exit 0;;
1272	3) # Error
1273		if [ "$silent" != "y" ]; then
1274			error_msg
1275		fi
1276		msg $DEVICE "Error ejecting disk from $DEVICE" \
1277		"$eject_msg"
1278		exit 2;;
1279	esac
1280}
1281
1282
1283# ####################################################
1284# ################ Begin main program ################
1285# ####################################################
1286
1287trap "" INT TERM QUIT TSTP ABRT
1288
1289PATH="/usr/bin:/usr/sbin"
1290MODE="allocate"
1291SILENT=n
1292WDWMSG="/etc/security/lib/wdwmsg"
1293VOLUME_ZONE_PATH="/"
1294USAGE="Usage: disk_clean [-s|-f|-i|-I] devicename -[A|D] [username] [zonename] [zonepath]"
1295EXIT_STATUS=0
1296CLEAN_MOUNT=4
1297MACH=`uname -p`
1298FLAG=i
1299#
1300# Parse the command line arguments
1301#
1302while getopts ifsI c
1303do
1304	case $c in
1305	i)
1306		FLAG=$c;;
1307	f)
1308		FLAG=$c;;
1309	s)
1310		FLAG=$c;;
1311	I)
1312		FLAG=i
1313		silent=y;;
1314	\?)
1315		echo $USAGE
1316		exit 1;;
1317      esac
1318done
1319
1320shift `expr $OPTIND - 1`
1321
1322DEVICE=$1
1323MODE="deallocate"
1324if [ "$2" = "-A" ]; then
1325	MODE="allocate"
1326elif [ "$2" = "-D" ]; then
1327	MODE="deallocate"
1328fi
1329
1330#get the device_maps information
1331MAP=`/usr/sbin/list_devices -s -l $DEVICE`
1332FILES=`echo $MAP | cut -f4 -d:`	# e.g., /dev/dsk/c0t6d0s0 /dev/dsk/c0t6d0s1 ...
1333DEVFILE=`echo $FILES | cut -f1 -d" "` 		# e.g., "/dev/dsk/c0t6d0s0"
1334
1335# Set VOLUME_ variables that are inputs to rmmount
1336
1337VOLUME_DEVICE=`echo $FILES | cut -f2 -d" "` 	# e.g., "/dev/dsk/c0t6d0s1"
1338MEDIATYPE=`echo $MAP | cut -f3 -d: | cut -f2 -d" "`
1339					 	# e.g., "cdrom" or "floppy"
1340if [ "$MEDIATYPE" = "sr" ]; then
1341	VOLUME_MEDIATYPE="cdrom"
1342elif [ "$MEDIATYPE" = "fd" ]; then
1343	VOLUME_MEDIATYPE="floppy"
1344elif [ "$MEDIATYPE" = "rmdisk" ]; then
1345	VOLUME_MEDIATYPE="rmdisk"
1346fi
1347
1348VOLUME_PATH=$DEVFILE				# e.g., "/dev/dsk/c0t6d0s0"
1349if [ "$MACH" = "i386" ] && [ "$MEDIATYPE" = "rmdisk" ]; then
1350	VOLUME_PATH=`echo $DEVFILE | sed -e 's/s0/p0/'`
1351fi
1352
1353SYMDEV=`echo $DEVICE | sed -e 's/_//'`		# e.g., "cdrom" or "floppy"
1354SYMNUM=`echo $SYMDEV | sed -e 's/[a-z]*//g'`
1355SYMDEV=`echo $SYMDEV | sed -e 's/[0-9]*//g'`
1356if [ "$SYMDEV" = "sr" ]; then
1357	VOLUME_SYMDEV="cdrom"$SYMNUM
1358elif [ "$SYMDEV" = "fd" ]; then
1359	VOLUME_SYMDEV="floppy"$SYMNUM
1360elif [ "$SYMDEV" = "rmdisk" ]; then
1361	VOLUME_SYMDEV="rmdisk"$SYMNUM
1362else
1363	VOLUME_SYMDEV=$SYMDEV$SYMNUM
1364fi
1365
1366VOLUME_ZONE_NAME=$4
1367
1368VOLUME_ZONE_PATH=$5
1369
1370if [ "$MODE" = "allocate" ]; then
1371	if [ -n "$3" ]; then			# e.g., "joeuser"
1372		VOLUME_USER=$3
1373	else
1374		VOLUME_USER=`/usr/xpg4/bin/id -u -nr`
1375	fi
1376else
1377	# If there's a directory for the device under /<mediatype>, get the
1378	# user name from there, to use in cleaning up that directory. Otherwise,
1379	# the user name isn't actually used in deallocation.
1380	if [ -d ${VOLUME_ZONE_PATH}/${VOLUME_MEDIATYPE}/*-${DEVICE} ]; then
1381		VOLUME_USER=`ls -ld ${VOLUME_ZONE_PATH}/${VOLUME_MEDIATYPE}/*-${DEVICE} | awk '/^d/{print $3}'`
1382	else
1383		if [ -n "$3" ]; then
1384			VOLUME_USER=$3
1385		else
1386			VOLUME_USER=`/usr/xpg4/bin/id -u -nr`
1387		fi
1388	fi
1389fi
1390
1391VOLUME_NAME=unnamed_${VOLUME_MEDIATYPE}
1392					# e.g., "joeuser-cdrom0/unnamed_cdrom"
1393
1394if [ "$VOLUME_MEDIATYPE" = "rmdisk" ]; then
1395	VOLUME_PCFS_ID=1
1396else
1397	VOLUME_PCFS_ID=
1398fi
1399
1400export VOLUME_ACTION VOLUME_DEVICE VOLUME_MEDIATYPE VOLUME_NAME VOLUME_PCFS_ID
1401export VOLUME_PATH VOLUME_SYMDEV VOLUME_USER VOLUME_ZONE_NAME VOLUME_ZONE_PATH
1402
1403USERDIR=${VOLUME_USER}-${DEVICE}	# e.g., "joeusr-cdrom0"
1404
1405msg_init
1406
1407if [ "$MODE" = "allocate" ]; then
1408	MSGDEV=tty
1409  	do_allocate
1410else
1411    if [ "$FLAG" = "i" ] ; then
1412	MSGDEV=console
1413	do_init
1414    else
1415	MSGDEV=tty
1416	do_deallocate
1417    fi
1418fi
1419
1420exit $EXIT_STATUS
1421#! /bin/ksh
1422#
1423# CDDL HEADER START
1424#
1425# The contents of this file are subject to the terms of the
1426# Common Development and Distribution License (the "License").
1427# You may not use this file except in compliance with the License.
1428#
1429# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1430# or http://www.opensolaris.org/os/licensing.
1431# See the License for the specific language governing permissions
1432# and limitations under the License.
1433#
1434# When distributing Covered Code, include this CDDL HEADER in each
1435# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1436# If applicable, add the following below this CDDL HEADER, with the
1437# fields enclosed by brackets "[]" replaced with your own identifying
1438# information: Portions Copyright [yyyy] [name of copyright owner]
1439#
1440# CDDL HEADER END
1441#
1442# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
1443# Use is subject to license terms.
1444#
1445#pragma ident	"%Z%%M%	%I%	%E% SMI"
1446#
1447
1448################## Check parameters #################################
1449
1450if [ $# -lt 3 -o $# -gt 4 ]; then
1451	echo "Usage: `basename $0` TITLE OKBUTTONTEXT [CANCELBUTTONTEXT]"
1452	exit 127
1453fi
1454
1455################## Create the Main UI #################################
1456
1457messageString="$1"
1458dialogTitle="$2"
1459
1460if [ $# -eq 4 -a "$4" != "" ];then
1461	type="--question"
1462else
1463	type="--info"
1464fi
1465
1466reply=$(/usr/bin/zenity $type \
1467	--title="$dialogTitle" \
1468	--height=100 \
1469	--width=200 \
1470	--text="$messageString")
1471exit $reply
1472#! /bin/ksh
1473#
1474# CDDL HEADER START
1475#
1476# The contents of this file are subject to the terms of the
1477# Common Development and Distribution License (the "License").
1478# You may not use this file except in compliance with the License.
1479#
1480# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1481# or http://www.opensolaris.org/os/licensing.
1482# See the License for the specific language governing permissions
1483# and limitations under the License.
1484#
1485# When distributing Covered Code, include this CDDL HEADER in each
1486# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1487# If applicable, add the following below this CDDL HEADER, with the
1488# fields enclosed by brackets "[]" replaced with your own identifying
1489# information: Portions Copyright [yyyy] [name of copyright owner]
1490#
1491# CDDL HEADER END
1492#
1493# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
1494# Use is subject to license terms.
1495#
1496#pragma ident	"%Z%%M%	%I%	%E% SMI"
1497#
1498
1499
1500# Script to wrap a non-windowing clean script to provide a prompt
1501# before the dtterm window closes, and to catch abnormal terminations.
1502
1503# For any abnormal termination of the clean script, kill our parent
1504# process so that our grandparent will know that the script did not
1505# terminate normally.  (We expect our parent to be dtterm, and our
1506# grandparent to be allocate.)
1507
1508# Trap any signal that would cause abnormal termination of the script,
1509# This catches use of ^C, ^Z, etc., and it also catches the HUP signal
1510# when the dtterm window is closed before the script is finished.
1511
1512PARENT_KILLED=no
1513
1514killparent() {
1515  if [ $PARENT_KILLED = "no" ]; then
1516    PARENT_KILLED=yes
1517    kill -9 $PPID
1518  fi
1519}
1520
1521trap "killparent" HUP INT TERM QUIT TSTP ABRT
1522
1523SCRIPT=$1
1524shift
1525
1526if [ ! -e $SCRIPT ]; then
1527	echo **** Clean script $SCRIPT not found ****
1528	echo "**** Press RETURN to close window ****"
1529	read
1530	kill -9 $PPID
1531fi
1532
1533echo "**** Device cleanup for $2 ****\n"
1534
1535$SCRIPT "$@"
1536STAT=$?
1537
1538echo "\n**** Press RETURN to close window ****"
1539read
1540
1541# If the script returned a non-zero exit status, kill our dtterm
1542# parent process.
1543
1544if [ $STAT != 0 ]; then
1545	killparent
1546fi
1547