Home | History | Annotate | Download | only in allocate
      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 the CD_ROM
     30 # 
     31 
     32 PROG=`basename $0`
     33 PATH="/usr/sbin:/usr/bin"
     34 TEXTDOMAIN="SUNW_OST_OSCMD"
     35 export TEXTDOMAIN
     36 
     37 USAGE=`gettext "%s [-I|-s|-f|-i] device"`
     38 
     39 #
     40 # 			*** Shell Function Definitions ***
     41 #
     42 
     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
     47     fi
     48 }
     49 
     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
     54     fi
     55 }
     56 
     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
     61     fi
     62 }
     63 
     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
     69     fi
     70 }
     71 
     72 mk_error() {
     73    chown bin /etc/security/dev/$1
     74    chmod 0100 /etc/security/dev/$1
     75 }
     76 
     77 #
     78 #			*** Begin Main Program ***
     79 #
     80 silent=n
     81 
     82 while getopts Iifs c
     83 do
     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`
     95 
     96 # get the map information
     97 
     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" "`
    104 
    105 #if init then do once and exit
    106 
    107 lform=`gettext "%s error: %s."`
    108 
    109 if [ "$FLAG" = "i" ] ; then
    110    x="`eject -q $DEVFILE 2>&1`"		# Determine if there is media in drive
    111    z="$?"   
    112 
    113    case $z in
    114    0) 					# Media is in the drive.
    115 	a="`eject -f $DEVFILE 2>&1`"
    116 	b="$?"
    117 
    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
    126 		fi
    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
    133 		fi
    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
    140 		fi
    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
    151 		fi
    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
    158 		fi
    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="$?"   
    166 
    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
    179 		fi
    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
    186 		fi
    187 		e_user_msg
    188          	exit 1;;
    189 	3)				
    190 	
    191 		if echo $a | grep "failed" >/dev/null ; then
    192          	while true 		# Drive doesn't support eject, so loop	
    193          	    do
    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
    201 				fi
    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
    211 				fi
    212 				e_user_msg
    213          			exit 1
    214             		fi
    215          	    done
    216 		else 					# Some other failure
    217 			if [ "$silent" != "y" ] ; then
    218 				printf "${lform}\n" $PROG $a >/dev/tty
    219 			fi
    220          		e_user_msg
    221          		mk_error $DEVICE
    222          		exit 1
    223 		fi;;
    224 			
    225 	esac;;
    226    1)							# No media in the drive
    227          user_msg
    228          exit 0;;
    229    2)
    230        	mk_error $DEVICE
    231 	if [ "$silent" != "y" ] ; then
    232 		printf "${lform}\n" $PROG $x >/dev/tty
    233 	fi
    234 	e_user_msg
    235        	exit 1;;
    236    3)
    237        	mk_error $DEVICE
    238 	if [ "$silent" != "y" ] ; then
    239 		printf "${lform}\n" $PROG $x >/dev/tty
    240 	fi
    241 	e_user_msg
    242        	exit 1;;
    243    esac
    244 fi
    245 exit 2
    246