8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / allocate / fd_clean.sh
blobbb2590b146e2b58c77b831f7e1382068dea40858
1 #! /bin/sh
3 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
24 # Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
25 # All rights reserved.
27 #ident "%Z%%M% %I% %E% SMI"
29 # This a clean script for the floppy drive
32 PROG=`basename $0`
33 PATH="/usr/sbin:/usr/bin"
34 TEXTDOMAIN="SUNW_OST_OSCMD"
35 export TEXTDOMAIN
37 USAGE=`gettext "%s [-I|-s|-f|-i] device"`
40 # *** Shell Function Declarations ***
43 con_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
50 e_con_msg() {
51 form=`gettext "%s: Error cleaning up device %s."`
52 if [ "$silent" != "y" ] ; then
53 printf "${form}\n" $PROG $DEVICE > /dev/console
57 user_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
64 e_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
72 mk_error() {
73 chown bin /etc/security/dev/$1
74 chmod 0100 /etc/security/dev/$1
78 # *** Begin main program ***
81 silent=n
83 # Parse the argumnets
85 while getopts Iifs c
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
96 done
97 shift `expr $OPTIND - 1`
99 # get the map information
101 FLOPPY=$1
102 MAP=`dminfo -v -n $FLOPPY`
103 DEVICE=`echo $MAP | cut -f1 -d:`
104 TYPE=`echo $MAP | cut -f2 -d:`
105 FILES=`echo $MAP | cut -f3 -d:`
106 DEVFILE=`echo $FILES | cut -f1 -d" "`
108 #if init then do once and exit
110 lform=`gettext "%s error: %s."`
112 if [ "$FLAG" = "i" ] ; then
113 x="`eject -q $DEVFILE 2>&1`" # Determine if there is media in drive
114 z="$?"
116 case $z in
117 0) # Media is in the drive.
118 a="`eject -f $DEVFILE 2>&1`"
119 b="$?"
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
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
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
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
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
162 e_con_msg
163 exit 1;;
164 esac
165 else
166 # interactive clean up
167 x="`eject -q $DEVFILE 2>&1`" # Determine if there is media in drive
168 z="$?"
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
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
190 e_user_msg
191 exit 1;;
194 if echo $a | grep "failed" >/dev/null ; then
195 while true # Drive doesn't support eject, so loop
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
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
215 e_user_msg
216 exit 1
218 done
219 else # Some other failure
220 if [ "$silent" != "y" ] ; then
221 printf "${lform}\n" $PROG $a >/dev/tty
223 e_user_msg
224 mk_error $DEVICE
225 exit 1
226 fi;;
228 esac;;
229 1) # No media in the drive
230 user_msg
231 exit 0;;
233 mk_error $DEVICE
234 if [ "$silent" != "y" ] ; then
235 printf "${lform}\n" $PROG $x >/dev/tty
237 e_user_msg
238 exit 1;;
240 mk_error $DEVICE
241 if [ "$silent" != "y" ] ; then
242 printf "${lform}\n" $PROG $x >/dev/tty
244 e_user_msg
245 exit 1;;
246 esac
248 exit 2