#! /bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 1992-1993, 1997-2001 by Sun Microsystems, Inc. # All rights reserved. # #ident "%Z%%M% %I% %E% SMI" # # This a clean script for the floppy drive # setvar PROG = $(basename $0) setvar PATH = ""/usr/sbin:/usr/bin"" setvar TEXTDOMAIN = ""SUNW_OST_OSCMD"" export TEXTDOMAIN setvar USAGE = $(gettext "%s [-I|-s|-f|-i] device) # # *** Shell Function Declarations *** # proc con_msg { setvar form = $(gettext "%s: Media in %s is ready. Please, label and store safely.) if test $silent != "y" { printf "${form}\n" $PROG $DEVICE > /dev/console } } proc e_con_msg { setvar form = $(gettext "%s: Error cleaning up device %s.) if test $silent != "y" { printf "${form}\n" $PROG $DEVICE > /dev/console } } proc user_msg { setvar form = $(gettext "%s: Media in %s is ready. Please, label and store safely.) if test $silent != "y" { printf "${form}\n" $PROG $DEVICE > /dev/tty } } proc e_user_msg { setvar form = $(gettext "%s: Error cleaning up device %s.) if test $silent != "y" { printf "${form}\n" $PROG $DEVICE > /dev/tty gettext "Please inform system administrator.\n" > /dev/tty } } proc mk_error { chown bin /etc/security/dev/$1 chmod 0100 /etc/security/dev/$1 } # # *** Begin main program *** # setvar silent = 'n' # Parse the argumnets while getopts Iifs c { match $c { with I setvar FLAG = 'i' setvar silent = 'y' with i setvar FLAG = "$c" with f setvar FLAG = "$c" with s setvar FLAG = "$c" with \? printf "${USAGE}\n" $PROG exit 1 } } shift $(expr $OPTIND - 1) # get the map information setvar FLOPPY = "$1" setvar MAP = $(dminfo -v -n $FLOPPY) setvar DEVICE = $(echo $MAP | cut -f1 -d:) setvar TYPE = $(echo $MAP | cut -f2 -d:) setvar FILES = $(echo $MAP | cut -f3 -d:) setvar DEVFILE = $(echo $FILES | cut -f1 -d" ) #if init then do once and exit setvar lform = $(gettext "%s error: %s.) if test $FLAG = "i" { setvar x = "$(eject -q $DEVFILE )" # Determine if there is media in drive setvar z = ""$Status"" match $z { with 0 # Media is in the drive. setvar a = "$(eject -f $DEVFILE )" setvar b = ""$Status"" match $b { with 0 # Media has been ejected con_msg exit 0 with 1 # Media not ejected mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_con_msg exit 1 with 2 # Error mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_con_msg exit 1 with 3 # Error - Perhaps drive doesn't support ejection mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_con_msg exit 1 } with 1 # No media in drive con_msg exit 0 with 2 # Error mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $x >/dev/tty } e_con_msg exit 1 with 3 # Error mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $x >/dev/tty } e_con_msg exit 1 } } else { # interactive clean up setvar x = "$(eject -q $DEVFILE )" # Determine if there is media in drive setvar z = ""$Status"" match $z { with 0 # Media is in the drive. setvar a = "$(eject -f $DEVFILE )" setvar b = ""$Status"" match $b { with 0 # Media has been ejected user_msg exit 0 with 1 # Media didn't eject mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_user_msg exit 1 with 2 # Other Error mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_user_msg exit 1 with 3 if echo $a | grep "failed" >/dev/null { while true # Drive doesn't support eject, so loop { setvar c = "$(eject -q $DEVFILE )" # Is floppy in drive? setvar d = ""$Status"" if test $d -eq 0 { # Yes, Floppy in drive setvar form = $(gettext "Please remove the floppy from %s.) if test $silent != "y" { printf "${form}\n" $DEVICE >/dev/tty /usr/5bin/echo '\'007 > /dev/tty } sleep 3 } elif echo $c | grep "NOT" > /dev/null { # No,Floppy NOT in drive user_msg exit 0 } else { # Error occurred mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_user_msg exit 1 } } } else { # Some other failure if test $silent != "y" { printf "${lform}\n" $PROG $a >/dev/tty } e_user_msg mk_error $DEVICE exit 1 } } with 1 # No media in the drive user_msg exit 0 with 2 mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $x >/dev/tty } e_user_msg exit 1 with 3 mk_error $DEVICE if test $silent != "y" { printf "${lform}\n" $PROG $x >/dev/tty } e_user_msg exit 1 } } exit 2