xref: /titanic_41/usr/src/cmd/allocate/fd_clean.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 floppy drive
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 Declarations ***
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" $PROG $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-gate
81*7c478bd9Sstevel@tonic-gatesilent=n
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate# Parse the argumnets
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gatewhile getopts Iifs c
86*7c478bd9Sstevel@tonic-gatedo
87*7c478bd9Sstevel@tonic-gate   case $c in
88*7c478bd9Sstevel@tonic-gate   I)	FLAG=i
89*7c478bd9Sstevel@tonic-gate	silent=y;;
90*7c478bd9Sstevel@tonic-gate   i)   FLAG=$c;;
91*7c478bd9Sstevel@tonic-gate   f)   FLAG=$c;;
92*7c478bd9Sstevel@tonic-gate   s)   FLAG=$c;;
93*7c478bd9Sstevel@tonic-gate   \?)   printf "${USAGE}\n" $PROG
94*7c478bd9Sstevel@tonic-gate      exit 1 ;;
95*7c478bd9Sstevel@tonic-gate   esac
96*7c478bd9Sstevel@tonic-gatedone
97*7c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate# get the map information
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gateFLOPPY=$1
102*7c478bd9Sstevel@tonic-gateMAP=`dminfo -v -n $FLOPPY`
103*7c478bd9Sstevel@tonic-gateDEVICE=`echo $MAP | cut -f1 -d:`
104*7c478bd9Sstevel@tonic-gateTYPE=`echo $MAP | cut -f2 -d:`
105*7c478bd9Sstevel@tonic-gateFILES=`echo $MAP | cut -f3 -d:`
106*7c478bd9Sstevel@tonic-gateDEVFILE=`echo $FILES | cut -f1 -d" "`
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate#if init then do once and exit
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gatelform=`gettext "%s error: %s."`
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gateif [ "$FLAG" = "i" ] ; then
113*7c478bd9Sstevel@tonic-gate   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
114*7c478bd9Sstevel@tonic-gate   z="$?"
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate   case $z in
117*7c478bd9Sstevel@tonic-gate   0) 					# Media is in the drive.
118*7c478bd9Sstevel@tonic-gate	a="`eject -f $DEVFILE 2>&1`"
119*7c478bd9Sstevel@tonic-gate	b="$?"
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate	case $b in
122*7c478bd9Sstevel@tonic-gate	0)				# Media has been ejected
123*7c478bd9Sstevel@tonic-gate		con_msg
124*7c478bd9Sstevel@tonic-gate		exit 0;;
125*7c478bd9Sstevel@tonic-gate	1)				# Media not ejected
126*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
127*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
128*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
129*7c478bd9Sstevel@tonic-gate		fi
130*7c478bd9Sstevel@tonic-gate		e_con_msg
131*7c478bd9Sstevel@tonic-gate		exit 1;;
132*7c478bd9Sstevel@tonic-gate	2)			# Error
133*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
134*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
135*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
136*7c478bd9Sstevel@tonic-gate		fi
137*7c478bd9Sstevel@tonic-gate		e_con_msg
138*7c478bd9Sstevel@tonic-gate		exit 1;;
139*7c478bd9Sstevel@tonic-gate	3)			# Error - Perhaps drive doesn't support ejection
140*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
141*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
142*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
143*7c478bd9Sstevel@tonic-gate		fi
144*7c478bd9Sstevel@tonic-gate		e_con_msg
145*7c478bd9Sstevel@tonic-gate		exit 1;;
146*7c478bd9Sstevel@tonic-gate	esac;;
147*7c478bd9Sstevel@tonic-gate   1) 		# No media in drive
148*7c478bd9Sstevel@tonic-gate	con_msg
149*7c478bd9Sstevel@tonic-gate	exit 0;;
150*7c478bd9Sstevel@tonic-gate   2)			# Error
151*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
152*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
153*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $x >/dev/tty
154*7c478bd9Sstevel@tonic-gate		fi
155*7c478bd9Sstevel@tonic-gate		e_con_msg
156*7c478bd9Sstevel@tonic-gate		exit 1;;
157*7c478bd9Sstevel@tonic-gate   3)			# Error
158*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
159*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
160*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $x >/dev/tty
161*7c478bd9Sstevel@tonic-gate		fi
162*7c478bd9Sstevel@tonic-gate		e_con_msg
163*7c478bd9Sstevel@tonic-gate		exit 1;;
164*7c478bd9Sstevel@tonic-gate   esac
165*7c478bd9Sstevel@tonic-gateelse
166*7c478bd9Sstevel@tonic-gate# interactive clean up
167*7c478bd9Sstevel@tonic-gate   x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
168*7c478bd9Sstevel@tonic-gate   z="$?"
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate   case $z in
171*7c478bd9Sstevel@tonic-gate   0)					# Media is in the drive.
172*7c478bd9Sstevel@tonic-gate	a="`eject -f $DEVFILE 2>&1`"
173*7c478bd9Sstevel@tonic-gate	b="$?"
174*7c478bd9Sstevel@tonic-gate	case $b in
175*7c478bd9Sstevel@tonic-gate	0)				# Media has been ejected
176*7c478bd9Sstevel@tonic-gate		user_msg
177*7c478bd9Sstevel@tonic-gate		exit 0;;
178*7c478bd9Sstevel@tonic-gate	1)				# Media didn't eject
179*7c478bd9Sstevel@tonic-gate         	mk_error $DEVICE
180*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
181*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
182*7c478bd9Sstevel@tonic-gate		fi
183*7c478bd9Sstevel@tonic-gate         	e_user_msg
184*7c478bd9Sstevel@tonic-gate         	exit 1;;
185*7c478bd9Sstevel@tonic-gate	2)				# Other Error
186*7c478bd9Sstevel@tonic-gate		mk_error $DEVICE
187*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
188*7c478bd9Sstevel@tonic-gate			printf "${lform}\n" $PROG $a >/dev/tty
189*7c478bd9Sstevel@tonic-gate		fi
190*7c478bd9Sstevel@tonic-gate		e_user_msg
191*7c478bd9Sstevel@tonic-gate         	exit 1;;
192*7c478bd9Sstevel@tonic-gate	3)
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate		if echo $a | grep "failed" >/dev/null ; then
195*7c478bd9Sstevel@tonic-gate         	while true 		# Drive doesn't support eject, so loop
196*7c478bd9Sstevel@tonic-gate         	    do
197*7c478bd9Sstevel@tonic-gate			c="`eject -q $DEVFILE 2>&1`"	# Is floppy in drive?
198*7c478bd9Sstevel@tonic-gate			d="$?"
199*7c478bd9Sstevel@tonic-gate            		if [ $d -eq 0 ] ; then		# Yes, Floppy in drive
200*7c478bd9Sstevel@tonic-gate				form=`gettext "Please remove the floppy from %s."`
201*7c478bd9Sstevel@tonic-gate				if [ "$silent" != "y" ] ; then
202*7c478bd9Sstevel@tonic-gate               				printf "${form}\n" $DEVICE >/dev/tty
203*7c478bd9Sstevel@tonic-gate					/usr/5bin/echo \\007 > /dev/tty
204*7c478bd9Sstevel@tonic-gate				fi
205*7c478bd9Sstevel@tonic-gate               			sleep 3
206*7c478bd9Sstevel@tonic-gate            		elif echo $c | grep "NOT" > /dev/null ; then
207*7c478bd9Sstevel@tonic-gate							# No,Floppy NOT in drive
208*7c478bd9Sstevel@tonic-gate               			user_msg
209*7c478bd9Sstevel@tonic-gate               			exit 0
210*7c478bd9Sstevel@tonic-gate			else				# Error occurred
211*7c478bd9Sstevel@tonic-gate         			mk_error $DEVICE
212*7c478bd9Sstevel@tonic-gate				if [ "$silent" != "y" ] ; then
213*7c478bd9Sstevel@tonic-gate					printf "${lform}\n" $PROG $a >/dev/tty
214*7c478bd9Sstevel@tonic-gate				fi
215*7c478bd9Sstevel@tonic-gate				e_user_msg
216*7c478bd9Sstevel@tonic-gate         			exit 1
217*7c478bd9Sstevel@tonic-gate            		fi
218*7c478bd9Sstevel@tonic-gate         	    done
219*7c478bd9Sstevel@tonic-gate		else 					# Some other failure
220*7c478bd9Sstevel@tonic-gate			if [ "$silent" != "y" ] ; then
221*7c478bd9Sstevel@tonic-gate				printf "${lform}\n" $PROG $a >/dev/tty
222*7c478bd9Sstevel@tonic-gate			fi
223*7c478bd9Sstevel@tonic-gate         		e_user_msg
224*7c478bd9Sstevel@tonic-gate         		mk_error $DEVICE
225*7c478bd9Sstevel@tonic-gate         		exit 1
226*7c478bd9Sstevel@tonic-gate		fi;;
227*7c478bd9Sstevel@tonic-gate
228*7c478bd9Sstevel@tonic-gate	esac;;
229*7c478bd9Sstevel@tonic-gate   1)							# No media in the drive
230*7c478bd9Sstevel@tonic-gate         user_msg
231*7c478bd9Sstevel@tonic-gate         exit 0;;
232*7c478bd9Sstevel@tonic-gate   2)
233*7c478bd9Sstevel@tonic-gate       	mk_error $DEVICE
234*7c478bd9Sstevel@tonic-gate	if [ "$silent" != "y" ] ; then
235*7c478bd9Sstevel@tonic-gate		printf "${lform}\n" $PROG $x >/dev/tty
236*7c478bd9Sstevel@tonic-gate	fi
237*7c478bd9Sstevel@tonic-gate	e_user_msg
238*7c478bd9Sstevel@tonic-gate       	exit 1;;
239*7c478bd9Sstevel@tonic-gate   3)
240*7c478bd9Sstevel@tonic-gate       	mk_error $DEVICE
241*7c478bd9Sstevel@tonic-gate	if [ "$silent" != "y" ] ; then
242*7c478bd9Sstevel@tonic-gate		printf "${lform}\n" $PROG $x >/dev/tty
243*7c478bd9Sstevel@tonic-gate	fi
244*7c478bd9Sstevel@tonic-gate	e_user_msg
245*7c478bd9Sstevel@tonic-gate       	exit 1;;
246*7c478bd9Sstevel@tonic-gate   esac
247*7c478bd9Sstevel@tonic-gatefi
248*7c478bd9Sstevel@tonic-gateexit 2
249