8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / allocate / st_clean.sh
blob27b8e3fb556612503afd5c827c8b620bfaff00a5
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 all tape drives
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 ***
44 con_msg() {
45 form=`gettext "%s: Media in %s is ready. Please, label and store safely."`
46 if [ "$silent" != "y" ] ; then
47 printf "${form}\n" $PROG $DEVICE > /dev/console
51 e_con_msg() {
52 form=`gettext "%s: Error cleaning up device %s."`
53 if [ "$silent" != "y" ] ; then
54 printf "${form}\n" $PROG $DEVICE > /dev/console
58 user_msg() {
59 form=`gettext "%s: Media in %s is ready. Please, label and store safely."`
60 if [ "$silent" != "y" ] ; then
61 printf "${form}\n" $PROG $DEVICE > /dev/tty
65 e_user_msg() {
66 form=`gettext "%s: Error cleaning up device %s."`
67 if [ "$silent" != "y" ] ; then
68 printf "${form}" $PROG $DEVICE > /dev/tty
69 gettext "Please inform system administrator.\n" > /dev/tty
73 mk_error() {
74 chown bin /etc/security/dev/$1
75 chmod 0100 /etc/security/dev/$1
78 silent=n
80 while getopts Iifs c
82 case $c in
83 I) FLAG=i
84 silent=y;;
85 i) FLAG=$c;;
86 f) FLAG=$c;;
87 s) FLAG=$c;;
88 \?) printf "${USAGE}\n" $PROG >/dev/tty
89 exit 1 ;;
90 esac
91 done
92 shift `expr $OPTIND - 1`
94 # get the map information
96 TAPE=$1
97 MAP=`dminfo -v -n $TAPE`
98 DEVICE=`echo $MAP | cut -f1 -d:`
99 TYPE=`echo $MAP | cut -f2 -d:`
100 FILES=`echo $MAP | cut -f3 -d:`
101 DEVFILE=`echo $FILES | cut -f1 -d" "`
103 #if init then do once and exit
105 if [ "$FLAG" = "i" ] ; then
106 x="`mt -f $DEVFILE rewoffl 2>&1`"
107 z="$?"
109 case $z in
112 # if this is a open reel tape than we a sucessful
113 # else must be a cartrige tape we failed
115 if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" >/dev/null ; then
116 con_msg
117 exit 0
118 else
119 e_con_msg
120 mk_error $DEVICE
121 exit 1
122 fi;;
125 # only one error mesage is satisfactory
127 if echo $x | grep "no tape loaded" >/dev/null ; then
128 con_msg
129 exit 0
130 else
131 e_con_msg
132 mk_error $DEVICE
133 exit 1
134 fi;;
138 # clean up failed exit with error
140 e_con_msg
141 mk_error $DEVICE
142 exit 1;;
144 esac
145 else
146 # interactive clean up
147 x="`mt -f $DEVFILE rewoffl 2>&1`"
148 z="$?"
150 case $z in
153 # if this is a open reel tape than we a sucessful
154 # else must be a cartrige tape we must retry until user removes tape
156 if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" > /dev/null ; then
157 user_msg
158 exit 0
159 else
160 while true
162 if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" > /dev/null ; then
163 user_msg
164 exit 0
165 else
166 form=`gettext "Please remove the tape from the %s."`
167 if [ "$silent" != "y" ] ; then
168 printf "${form}\n" $DEVICE >/dev/tty
169 /usr/5bin/echo \\007 >/dev/tty
171 sleep 3
173 done
174 fi;;
177 # only one error mesage is satisfactory
179 if echo $x | grep "no tape loaded" > /dev/null ; then
180 user_msg
181 exit 0
182 else
183 e_user_msg
184 mk_error $DEVICE
185 exit 1
186 fi;;
190 # clean up failed exit with error
192 e_user_msg
193 mk_error $DEVICE
194 exit 1;;
196 esac
198 exit 2