xref: /illumos-gate/usr/src/cmd/allocate/sr_clean.sh (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate#! /bin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
25*7c478bd9Sstevel@tonic-gate# All rights reserved.
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gate#  This a clean script for the CD_ROM
30*7c478bd9Sstevel@tonic-gate#
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gatePROG=`basename $0`
33*7c478bd9Sstevel@tonic-gatePATH="/usr/sbin:/usr/bin"
34*7c478bd9Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
35*7c478bd9Sstevel@tonic-gateexport TEXTDOMAIN
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gateUSAGE=`gettext "%s [-I|-s|-f|-i] device"`
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate#
40*7c478bd9Sstevel@tonic-gate# 			*** Shell Function Definitions ***
41*7c478bd9Sstevel@tonic-gate#
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gatecon_msg() {
44*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
45*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
46*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/console
47*7c478bd9Sstevel@tonic-gate    fi
48*7c478bd9Sstevel@tonic-gate}
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gatee_con_msg() {
51*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Error cleaning up device %s."`
52*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
53*7c478bd9Sstevel@tonic-gate	printf "${form}\n" `basename $0` $DEVICE > /dev/console
54*7c478bd9Sstevel@tonic-gate    fi
55*7c478bd9Sstevel@tonic-gate}
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gateuser_msg() {
58*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
59*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
60*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/tty
61*7c478bd9Sstevel@tonic-gate    fi
62*7c478bd9Sstevel@tonic-gate}
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gatee_user_msg() {
65*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Error cleaning up device %s."`
66*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
67*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/tty
68*7c478bd9Sstevel@tonic-gate	gettext "Please inform system administrator.\n" > /dev/tty
69*7c478bd9Sstevel@tonic-gate    fi
70*7c478bd9Sstevel@tonic-gate}
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gatemk_error() {
73*7c478bd9Sstevel@tonic-gate   chown bin /etc/security/dev/$1
74*7c478bd9Sstevel@tonic-gate   chmod 0100 /etc/security/dev/$1
75*7c478bd9Sstevel@tonic-gate}
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate#
78*7c478bd9Sstevel@tonic-gate#			*** Begin Main Program ***
79*7c478bd9Sstevel@tonic-gate#
80*7c478bd9Sstevel@tonic-gatesilent=n
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gatewhile getopts Iifs c
83*7c478bd9Sstevel@tonic-gatedo
84*7c478bd9Sstevel@tonic-gate   case $c in
85*7c478bd9Sstevel@tonic-gate   I)	FLAG=i
86*7c478bd9Sstevel@tonic-gate	silent=y;;
87*7c478bd9Sstevel@tonic-gate   i)   FLAG=$c;;
88*7c478bd9Sstevel@tonic-gate   f)   FLAG=$c;;
89*7c478bd9Sstevel@tonic-gate   s)   FLAG=$c;;
90*7c478bd9Sstevel@tonic-gate   \?)   printf "${USAGE}\n" $PROG >/dev/tty
91*7c478bd9Sstevel@tonic-gate      exit 1 ;;
92*7c478bd9Sstevel@tonic-gate   esac
93*7c478bd9Sstevel@tonic-gatedone
94*7c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate# get the map information
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gateFLOPPY=$1
99*7c478bd9Sstevel@tonic-gateMAP=`dminfo -v -n $FLOPPY`
100*7c478bd9Sstevel@tonic-gateDEVICE=`echo $MAP | cut -f1 -d:`
101*7c478bd9Sstevel@tonic-gateTYPE=`echo $MAP | cut -f2 -d:`
102*7c478bd9Sstevel@tonic-gateFILES=`echo $MAP | cut -f3 -d:`
103*7c478bd9Sstevel@tonic-gateDEVFILE=`echo $FILES | cut -f1 -d" "`
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate#if init then do once and exit
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gatelform=`gettext "%s error: %s."`
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gateif [ "$FLAG" = "i" ] ; then
110*7c478bd9Sstevel@tonic-gate   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
111*7c478bd9Sstevel@tonic-gate   z="$?"
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate   case $z in
114*7c478bd9Sstevel@tonic-gate   0) 					# Media is in the drive.
115*7c478bd9Sstevel@tonic-gate	a="`eject -f $DEVFILE 2>&1`"
116*7c478bd9Sstevel@tonic-gate	b="$?"
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate	case $b in
119*7c478bd9Sstevel@tonic-gate	0)				# Media has been ejected
120*7c478bd9Sstevel@tonic-gate		con_msg
121*7c478bd9Sstevel@tonic-gate		exit 0;;
122*7c478bd9Sstevel@tonic-gate	1)				# Media not ejected
123*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
124*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
125*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
126*7c478bd9Sstevel@tonic-gate		fi
127*7c478bd9Sstevel@tonic-gate		e_con_msg
128*7c478bd9Sstevel@tonic-gate		exit 1;;
129*7c478bd9Sstevel@tonic-gate	2)			# Error
130*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
131*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
132*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
133*7c478bd9Sstevel@tonic-gate		fi
134*7c478bd9Sstevel@tonic-gate		e_con_msg
135*7c478bd9Sstevel@tonic-gate		exit 1;;
136*7c478bd9Sstevel@tonic-gate	3)			# Error - Perhaps drive doesn't support ejection
137*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
138*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
139*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
140*7c478bd9Sstevel@tonic-gate		fi
141*7c478bd9Sstevel@tonic-gate		e_con_msg
142*7c478bd9Sstevel@tonic-gate		exit 1;;
143*7c478bd9Sstevel@tonic-gate	esac;;
144*7c478bd9Sstevel@tonic-gate   1) 		# No media in drive
145*7c478bd9Sstevel@tonic-gate	con_msg
146*7c478bd9Sstevel@tonic-gate	exit 0;;
147*7c478bd9Sstevel@tonic-gate   2)			# Error
148*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
149*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
150*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $x >/dev/tty
151*7c478bd9Sstevel@tonic-gate		fi
152*7c478bd9Sstevel@tonic-gate		e_con_msg
153*7c478bd9Sstevel@tonic-gate		exit 1;;
154*7c478bd9Sstevel@tonic-gate   3)			# Error
155*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
156*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
157*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $x >/dev/tty
158*7c478bd9Sstevel@tonic-gate		fi
159*7c478bd9Sstevel@tonic-gate		e_con_msg
160*7c478bd9Sstevel@tonic-gate		exit 1;;
161*7c478bd9Sstevel@tonic-gate   esac
162*7c478bd9Sstevel@tonic-gateelse
163*7c478bd9Sstevel@tonic-gate# interactive clean up
164*7c478bd9Sstevel@tonic-gate   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
165*7c478bd9Sstevel@tonic-gate   z="$?"
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate   case $z in
168*7c478bd9Sstevel@tonic-gate   0)					# Media is in the drive.
169*7c478bd9Sstevel@tonic-gate	a="`eject -f $DEVFILE 2>&1`"
170*7c478bd9Sstevel@tonic-gate	b="$?"
171*7c478bd9Sstevel@tonic-gate	case $b in
172*7c478bd9Sstevel@tonic-gate	0)				# Media has been ejected
173*7c478bd9Sstevel@tonic-gate		user_msg
174*7c478bd9Sstevel@tonic-gate		exit 0;;
175*7c478bd9Sstevel@tonic-gate	1)				# Media not ejected
176*7c478bd9Sstevel@tonic-gate         	mk_error $DEVICE
177*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
178*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
179*7c478bd9Sstevel@tonic-gate		fi
180*7c478bd9Sstevel@tonic-gate         	e_user_msg
181*7c478bd9Sstevel@tonic-gate         	exit 1;;
182*7c478bd9Sstevel@tonic-gate	2)				# Other Error
183*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
184*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
185*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
186*7c478bd9Sstevel@tonic-gate		fi
187*7c478bd9Sstevel@tonic-gate		e_user_msg
188*7c478bd9Sstevel@tonic-gate         	exit 1;;
189*7c478bd9Sstevel@tonic-gate	3)
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate		if echo $a | grep "failed" >/dev/null ; then
192*7c478bd9Sstevel@tonic-gate         	while true 		# Drive doesn't support eject, so loop
193*7c478bd9Sstevel@tonic-gate         	    do
194*7c478bd9Sstevel@tonic-gate			c="`eject -q $DEVFILE 2>&1`"	# Is caddy in drive?
195*7c478bd9Sstevel@tonic-gate			d="$?"
196*7c478bd9Sstevel@tonic-gate            		if [ $d -eq 0 ] ; then		# Yes, Caddy in drive
197*7c478bd9Sstevel@tonic-gate				form=`gettext "Please remove the caddy from %s."`
198*7c478bd9Sstevel@tonic-gate				if [ "$silent" != "y" ] ; then
199*7c478bd9Sstevel@tonic-gate               				printf "${form}\n" $DEVICE  >/dev/tty
200*7c478bd9Sstevel@tonic-gate               				/usr/5bin/echo \\007 >/dev/tty
201*7c478bd9Sstevel@tonic-gate				fi
202*7c478bd9Sstevel@tonic-gate               			sleep 3
203*7c478bd9Sstevel@tonic-gate            		elif echo $c | grep "NOT" > /dev/null ; then
204*7c478bd9Sstevel@tonic-gate							# No,Caddy NOT in drive
205*7c478bd9Sstevel@tonic-gate               			user_msg
206*7c478bd9Sstevel@tonic-gate               			exit 0
207*7c478bd9Sstevel@tonic-gate			else				# Error occurred
208*7c478bd9Sstevel@tonic-gate         			mk_error $DEVICE
209*7c478bd9Sstevel@tonic-gate				if [ "$silent" != "y" ] ; then
210*7c478bd9Sstevel@tonic-gate					printf "${lform}\n" $PROG $a >/dev/tty
211*7c478bd9Sstevel@tonic-gate				fi
212*7c478bd9Sstevel@tonic-gate				e_user_msg
213*7c478bd9Sstevel@tonic-gate         			exit 1
214*7c478bd9Sstevel@tonic-gate            		fi
215*7c478bd9Sstevel@tonic-gate         	    done
216*7c478bd9Sstevel@tonic-gate		else 					# Some other failure
217*7c478bd9Sstevel@tonic-gate			if [ "$silent" != "y" ] ; then
218*7c478bd9Sstevel@tonic-gate				printf "${lform}\n" $PROG $a >/dev/tty
219*7c478bd9Sstevel@tonic-gate			fi
220*7c478bd9Sstevel@tonic-gate         		e_user_msg
221*7c478bd9Sstevel@tonic-gate         		mk_error $DEVICE
222*7c478bd9Sstevel@tonic-gate         		exit 1
223*7c478bd9Sstevel@tonic-gate		fi;;
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate	esac;;
226*7c478bd9Sstevel@tonic-gate   1)							# No media in the drive
227*7c478bd9Sstevel@tonic-gate         user_msg
228*7c478bd9Sstevel@tonic-gate         exit 0;;
229*7c478bd9Sstevel@tonic-gate   2)
230*7c478bd9Sstevel@tonic-gate       	mk_error $DEVICE
231*7c478bd9Sstevel@tonic-gate	if [ "$silent" != "y" ] ; then
232*7c478bd9Sstevel@tonic-gate		printf "${lform}\n" $PROG $x >/dev/tty
233*7c478bd9Sstevel@tonic-gate	fi
234*7c478bd9Sstevel@tonic-gate	e_user_msg
235*7c478bd9Sstevel@tonic-gate       	exit 1;;
236*7c478bd9Sstevel@tonic-gate   3)
237*7c478bd9Sstevel@tonic-gate       	mk_error $DEVICE
238*7c478bd9Sstevel@tonic-gate	if [ "$silent" != "y" ] ; then
239*7c478bd9Sstevel@tonic-gate		printf "${lform}\n" $PROG $x >/dev/tty
240*7c478bd9Sstevel@tonic-gate	fi
241*7c478bd9Sstevel@tonic-gate	e_user_msg
242*7c478bd9Sstevel@tonic-gate       	exit 1;;
243*7c478bd9Sstevel@tonic-gate   esac
244*7c478bd9Sstevel@tonic-gatefi
245*7c478bd9Sstevel@tonic-gateexit 2
246