#
# was /usr/bin/Fformat10.sh
#sccs	"@(#)adminbin:Fformat10.sh	1.1"
#                                                                Fformat10.sh
# PURPOSE: Format a 10 sector/track Floppy disk using the iv function
# CALLED BY: Floppy object file in /usr/lib/ua
# REQUIRED FILES: /etc/iv, /usr/lib/iv/FD10 files
# -------------------------------------------------------------------------

ERROR1="You have a disk mounted already!\n"

LOCKFILE=/tmp/FinUse.lock
ERRINUSE="The floppy disk is already in use by another application.\n"

MUSTBECON="You may not format floppy disks from a remote terminal.\n"

TERMCAP=
export TERMCAP
umask 022

##  LIMIT FORMATTING TO CONSOLE USERS

TTY=`tty`
expr "$TTY" : "/dev/w." > /dev/null 2>&1
if [ $? != 0 ]
then
	echo "$MUSTBECON"
	exit 1
fi

##  CHECK THAT FLOPPY IS NOT IN USE BY OTHER OPERATIONS.

if [ -s $LOCKFILE ]
then
	sh /usr/bin/Funlock.sh
	if [ $? != 0 ]
	then
		echo "$ERRINUSE"
		exit
	fi
fi

##  CHECK THAT THE FLOPPY IS NOT MOUNTED.

DEVNUM=`mount | wc -l | cut -c7-7` 
if [ "$DEVNUM" != "1" ] 
then
	clear
       	echo $ERROR1
  	exit
fi

GO=1
while [ "$GO" = 1 ]
do
	echo "Please insert the floppy disk for formatting.  (^D to end)  "
	read stuff
	if [ $? != "0" ]
	then
		exit
	fi

	echo "Floppy format in progress...\n"

	echo "$$ Fformat10.sh" > $LOCKFILE

	iv -i /dev/rfp020 /usr/lib/iv/FD10nl > /dev/null 2>&1
	if [ "$?" != "0" ]
	then
		echo "Cannot format floppy disk.\n"
		exit
	else
		mkfs /dev/rfp021 > /dev/null 2>&1
		dismount -f > /dev/null 2>&1
		echo "The floppy diskette is now formatted.\n"
	fi
done
rm -f $LOCKFILE