xref: /titanic_44/usr/src/cmd/allocate/st_clean.sh (revision 6dfee4834394825da35b977ca71cdc965bc7b6a4)
1#! /bin/sh
2#
3# CDDL HEADER START
4#
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.
9#
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.
14#
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]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28#
29#  This a clean script for all tape drives
30#
31
32PROG=`basename $0`
33PATH="/usr/sbin:/usr/bin"
34TEXTDOMAIN="SUNW_OST_OSCMD"
35export TEXTDOMAIN
36
37USAGE=`gettext "%s [-I|-s|-f|-i] device"`
38
39#
40# 		*** Shell Function Declarations ***
41#
42
43
44con_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
48    fi
49}
50
51e_con_msg() {
52    form=`gettext "%s: Error cleaning up device %s."`
53    if [ "$silent" != "y" ] ; then
54	printf "${form}\n" $PROG $DEVICE > /dev/console
55    fi
56}
57
58user_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
62    fi
63}
64
65e_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
70    fi
71}
72
73mk_error() {
74   chown bin /etc/security/dev/$1
75   chmod 0100 /etc/security/dev/$1
76}
77
78silent=n
79
80while getopts Iifs c
81do
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
91done
92shift `expr $OPTIND - 1`
93
94# get the map information
95
96TAPE=$1
97MAP=`dminfo -v -n $TAPE`
98DEVICE=`echo $MAP | cut -f1 -d:`
99TYPE=`echo $MAP | cut -f2 -d:`
100FILES=`echo $MAP | cut -f3 -d:`
101DEVFILE=`echo $FILES | cut -f1 -d" "`
102
103#if init then do once and exit
104
105if [ "$FLAG" = "i" ] ; then
106   x="`mt -f $DEVFILE rewoffl 2>&1`"
107   z="$?"
108
109   case $z in
110   0)
111
112   # if this is a open reel tape than we a sucessful
113   # else must be a cartrige tape we failed
114
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;;
123   1)
124
125   # only one error mesage is satisfactory
126
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;;
135
136   2)
137
138   # clean up failed exit with error
139
140      e_con_msg
141      mk_error $DEVICE
142      exit 1;;
143
144   esac
145else
146# interactive clean up
147   x="`mt -f $DEVFILE rewoffl 2>&1`"
148   z="$?"
149
150   case $z in
151   0)
152
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
155
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
161         do
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
170		fi
171                sleep 3
172            fi
173         done
174      fi;;
175   1)
176
177   # only one error mesage is satisfactory
178
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;;
187
188   2)
189
190   # clean up failed exit with error
191
192      e_user_msg
193      mk_error $DEVICE
194      exit 1;;
195
196   esac
197fi
198exit 2
199