dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / allocate / sr_clean.sh
blobb424ecbf59c131b6a48f6e464234b59facc27238
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 CD_ROM
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 Definitions ***
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" `basename $0` $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 ***
80 silent=n
82 while getopts Iifs c
84 case $c in
85 I) FLAG=i
86 silent=y;;
87 i) FLAG=$c;;
88 f) FLAG=$c;;
89 s) FLAG=$c;;
90 \?) printf "${USAGE}\n" $PROG >/dev/tty
91 exit 1 ;;
92 esac
93 done
94 shift `expr $OPTIND - 1`
96 # get the map information
98 FLOPPY=$1
99 MAP=`dminfo -v -n $FLOPPY`
100 DEVICE=`echo $MAP | cut -f1 -d:`
101 TYPE=`echo $MAP | cut -f2 -d:`
102 FILES=`echo $MAP | cut -f3 -d:`
103 DEVFILE=`echo $FILES | cut -f1 -d" "`
105 #if init then do once and exit
107 lform=`gettext "%s error: %s."`
109 if [ "$FLAG" = "i" ] ; then
110 x="`eject -q $DEVFILE 2>&1`" # Determine if there is media in drive
111 z="$?"
113 case $z in
114 0) # Media is in the drive.
115 a="`eject -f $DEVFILE 2>&1`"
116 b="$?"
118 case $b in
119 0) # Media has been ejected
120 con_msg
121 exit 0;;
122 1) # Media not ejected
123 mk_error $DEVICE
124 if [ "$silent" != "y" ] ; then
125 printf "${lform}\n" $PROG $a >/dev/tty
127 e_con_msg
128 exit 1;;
129 2) # Error
130 mk_error $DEVICE
131 if [ "$silent" != "y" ] ; then
132 printf "${lform}\n" $PROG $a >/dev/tty
134 e_con_msg
135 exit 1;;
136 3) # Error - Perhaps drive doesn't support ejection
137 mk_error $DEVICE
138 if [ "$silent" != "y" ] ; then
139 printf "${lform}\n" $PROG $a >/dev/tty
141 e_con_msg
142 exit 1;;
143 esac;;
144 1) # No media in drive
145 con_msg
146 exit 0;;
147 2) # Error
148 mk_error $DEVICE
149 if [ "$silent" != "y" ] ; then
150 printf "${lform}\n" $PROG $x >/dev/tty
152 e_con_msg
153 exit 1;;
154 3) # Error
155 mk_error $DEVICE
156 if [ "$silent" != "y" ] ; then
157 printf "${lform}\n" $PROG $x >/dev/tty
159 e_con_msg
160 exit 1;;
161 esac
162 else
163 # interactive clean up
164 x="`eject -q $DEVFILE 2>&1`" # Determine if there is media in drive
165 z="$?"
167 case $z in
168 0) # Media is in the drive.
169 a="`eject -f $DEVFILE 2>&1`"
170 b="$?"
171 case $b in
172 0) # Media has been ejected
173 user_msg
174 exit 0;;
175 1) # Media not ejected
176 mk_error $DEVICE
177 if [ "$silent" != "y" ] ; then
178 printf "${lform}\n" $PROG $a >/dev/tty
180 e_user_msg
181 exit 1;;
182 2) # Other Error
183 mk_error $DEVICE
184 if [ "$silent" != "y" ] ; then
185 printf "${lform}\n" $PROG $a >/dev/tty
187 e_user_msg
188 exit 1;;
191 if echo $a | grep "failed" >/dev/null ; then
192 while true # Drive doesn't support eject, so loop
194 c="`eject -q $DEVFILE 2>&1`" # Is caddy in drive?
195 d="$?"
196 if [ $d -eq 0 ] ; then # Yes, Caddy in drive
197 form=`gettext "Please remove the caddy from %s."`
198 if [ "$silent" != "y" ] ; then
199 printf "${form}\n" $DEVICE >/dev/tty
200 /usr/5bin/echo \\007 >/dev/tty
202 sleep 3
203 elif echo $c | grep "NOT" > /dev/null ; then
204 # No,Caddy NOT in drive
205 user_msg
206 exit 0
207 else # Error occurred
208 mk_error $DEVICE
209 if [ "$silent" != "y" ] ; then
210 printf "${lform}\n" $PROG $a >/dev/tty
212 e_user_msg
213 exit 1
215 done
216 else # Some other failure
217 if [ "$silent" != "y" ] ; then
218 printf "${lform}\n" $PROG $a >/dev/tty
220 e_user_msg
221 mk_error $DEVICE
222 exit 1
223 fi;;
225 esac;;
226 1) # No media in the drive
227 user_msg
228 exit 0;;
230 mk_error $DEVICE
231 if [ "$silent" != "y" ] ; then
232 printf "${lform}\n" $PROG $x >/dev/tty
234 e_user_msg
235 exit 1;;
237 mk_error $DEVICE
238 if [ "$silent" != "y" ] ; then
239 printf "${lform}\n" $PROG $x >/dev/tty
241 e_user_msg
242 exit 1;;
243 esac
245 exit 2