xref: /illumos-gate/usr/src/cmd/allocate/st_clean.sh (revision 7c478bd9)
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 all tape drives
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-gate
44*7c478bd9Sstevel@tonic-gatecon_msg() {
45*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
46*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
47*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/console
48*7c478bd9Sstevel@tonic-gate    fi
49*7c478bd9Sstevel@tonic-gate}
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gatee_con_msg() {
52*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Error cleaning up device %s."`
53*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
54*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/console
55*7c478bd9Sstevel@tonic-gate    fi
56*7c478bd9Sstevel@tonic-gate}
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gateuser_msg() {
59*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Media in %s is ready.  Please, label and store safely."`
60*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
61*7c478bd9Sstevel@tonic-gate	printf "${form}\n" $PROG $DEVICE > /dev/tty
62*7c478bd9Sstevel@tonic-gate    fi
63*7c478bd9Sstevel@tonic-gate}
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gatee_user_msg() {
66*7c478bd9Sstevel@tonic-gate    form=`gettext "%s: Error cleaning up device %s."`
67*7c478bd9Sstevel@tonic-gate    if [ "$silent" != "y" ] ; then
68*7c478bd9Sstevel@tonic-gate	printf "${form}" $PROG $DEVICE > /dev/tty
69*7c478bd9Sstevel@tonic-gate	gettext "Please inform system administrator.\n" > /dev/tty
70*7c478bd9Sstevel@tonic-gate    fi
71*7c478bd9Sstevel@tonic-gate}
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gatemk_error() {
74*7c478bd9Sstevel@tonic-gate   chown bin /etc/security/dev/$1
75*7c478bd9Sstevel@tonic-gate   chmod 0100 /etc/security/dev/$1
76*7c478bd9Sstevel@tonic-gate}
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gatesilent=n
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gatewhile getopts Iifs c
81*7c478bd9Sstevel@tonic-gatedo
82*7c478bd9Sstevel@tonic-gate   case $c in
83*7c478bd9Sstevel@tonic-gate   I)	FLAG=i
84*7c478bd9Sstevel@tonic-gate	silent=y;;
85*7c478bd9Sstevel@tonic-gate   i)   FLAG=$c;;
86*7c478bd9Sstevel@tonic-gate   f)   FLAG=$c;;
87*7c478bd9Sstevel@tonic-gate   s)   FLAG=$c;;
88*7c478bd9Sstevel@tonic-gate   \?)   printf "${USAGE}\n" $PROG >/dev/tty
89*7c478bd9Sstevel@tonic-gate      exit 1 ;;
90*7c478bd9Sstevel@tonic-gate   esac
91*7c478bd9Sstevel@tonic-gatedone
92*7c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate# get the map information
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gateTAPE=$1
97*7c478bd9Sstevel@tonic-gateMAP=`dminfo -v -n $TAPE`
98*7c478bd9Sstevel@tonic-gateDEVICE=`echo $MAP | cut -f1 -d:`
99*7c478bd9Sstevel@tonic-gateTYPE=`echo $MAP | cut -f2 -d:`
100*7c478bd9Sstevel@tonic-gateFILES=`echo $MAP | cut -f3 -d:`
101*7c478bd9Sstevel@tonic-gateDEVFILE=`echo $FILES | cut -f1 -d" "`
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate#if init then do once and exit
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gateif [ "$FLAG" = "i" ] ; then
106*7c478bd9Sstevel@tonic-gate   x="`mt -f $DEVFILE rewoffl 2>&1`"
107*7c478bd9Sstevel@tonic-gate   z="$?"
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate   case $z in
110*7c478bd9Sstevel@tonic-gate   0)
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate   # if this is a open reel tape than we a sucessful
113*7c478bd9Sstevel@tonic-gate   # else must be a cartrige tape we failed
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate      if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" >/dev/null ; then
116*7c478bd9Sstevel@tonic-gate         con_msg
117*7c478bd9Sstevel@tonic-gate         exit 0
118*7c478bd9Sstevel@tonic-gate      else
119*7c478bd9Sstevel@tonic-gate         e_con_msg
120*7c478bd9Sstevel@tonic-gate         mk_error $DEVICE
121*7c478bd9Sstevel@tonic-gate         exit 1
122*7c478bd9Sstevel@tonic-gate      fi;;
123*7c478bd9Sstevel@tonic-gate   1)
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate   # only one error mesage is satisfactory
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate      if echo $x | grep "no tape loaded" >/dev/null ; then
128*7c478bd9Sstevel@tonic-gate         con_msg
129*7c478bd9Sstevel@tonic-gate         exit 0
130*7c478bd9Sstevel@tonic-gate      else
131*7c478bd9Sstevel@tonic-gate         e_con_msg
132*7c478bd9Sstevel@tonic-gate         mk_error $DEVICE
133*7c478bd9Sstevel@tonic-gate         exit 1
134*7c478bd9Sstevel@tonic-gate      fi;;
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate   2)
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate   # clean up failed exit with error
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate      e_con_msg
141*7c478bd9Sstevel@tonic-gate      mk_error $DEVICE
142*7c478bd9Sstevel@tonic-gate      exit 1;;
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate   esac
145*7c478bd9Sstevel@tonic-gateelse
146*7c478bd9Sstevel@tonic-gate# interactive clean up
147*7c478bd9Sstevel@tonic-gate   x="`mt -f $DEVFILE rewoffl 2>&1`"
148*7c478bd9Sstevel@tonic-gate   z="$?"
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gate   case $z in
151*7c478bd9Sstevel@tonic-gate   0)
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate   # if this is a open reel tape than we a sucessful
154*7c478bd9Sstevel@tonic-gate   # else must be a cartrige tape we must retry until user removes tape
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate      if mt -f $DEVFILE status 2>&1 | grep "no tape loaded"  > /dev/null ; then
157*7c478bd9Sstevel@tonic-gate         user_msg
158*7c478bd9Sstevel@tonic-gate         exit 0
159*7c478bd9Sstevel@tonic-gate      else
160*7c478bd9Sstevel@tonic-gate         while true
161*7c478bd9Sstevel@tonic-gate         do
162*7c478bd9Sstevel@tonic-gate            if mt -f $DEVFILE status 2>&1 | grep "no tape loaded" > /dev/null ; then
163*7c478bd9Sstevel@tonic-gate                user_msg
164*7c478bd9Sstevel@tonic-gate                exit 0
165*7c478bd9Sstevel@tonic-gate            else
166*7c478bd9Sstevel@tonic-gate		form=`gettext "Please remove the tape from the %s."`
167*7c478bd9Sstevel@tonic-gate		if [ "$silent" != "y" ] ; then
168*7c478bd9Sstevel@tonic-gate                	printf "${form}\n" $DEVICE  >/dev/tty
169*7c478bd9Sstevel@tonic-gate                	/usr/5bin/echo \\007 >/dev/tty
170*7c478bd9Sstevel@tonic-gate		fi
171*7c478bd9Sstevel@tonic-gate                sleep 3
172*7c478bd9Sstevel@tonic-gate            fi
173*7c478bd9Sstevel@tonic-gate         done
174*7c478bd9Sstevel@tonic-gate      fi;;
175*7c478bd9Sstevel@tonic-gate   1)
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate   # only one error mesage is satisfactory
178*7c478bd9Sstevel@tonic-gate
179*7c478bd9Sstevel@tonic-gate      if echo $x | grep "no tape loaded" > /dev/null ; then
180*7c478bd9Sstevel@tonic-gate         user_msg
181*7c478bd9Sstevel@tonic-gate         exit 0
182*7c478bd9Sstevel@tonic-gate      else
183*7c478bd9Sstevel@tonic-gate         e_user_msg
184*7c478bd9Sstevel@tonic-gate         mk_error $DEVICE
185*7c478bd9Sstevel@tonic-gate         exit 1
186*7c478bd9Sstevel@tonic-gate      fi;;
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate   2)
189*7c478bd9Sstevel@tonic-gate
190*7c478bd9Sstevel@tonic-gate   # clean up failed exit with error
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate      e_user_msg
193*7c478bd9Sstevel@tonic-gate      mk_error $DEVICE
194*7c478bd9Sstevel@tonic-gate      exit 1;;
195*7c478bd9Sstevel@tonic-gate
196*7c478bd9Sstevel@tonic-gate   esac
197*7c478bd9Sstevel@tonic-gatefi
198*7c478bd9Sstevel@tonic-gateexit 2
199