After one of our users had issues formatting a USB connected floppy disk, it came to me that I might want to automate this procedure. Please find below my bash script I called S.U.F.F. for SuSE USB Floppy Formatter. S.U.F.F. requires no run time parameters, it can install the required ufiformat if allowed, should it be missing. All floppy disk sizes are support as well as setting a volume label when complete. To create S.U.F.F., copy and paste the text from the code block below into your favorite text editor and save it as the file suff in your local ~/bin folder (/home/username/bin/suff):
#!/bin/bash
#: Title : S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00
#: Date Created: Sat Sep 10 10:04:11 CDT 2011
#: Last Edit : Sat Sep 10 10:04:11 CDT 2011
#: Author : James D. McDaniel
#: Version : 1.00
#: Description : Floppy Disk Formatter Script
#: Options : none
TITLE="S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00"
#
# Written for the openSUSE forums on Saturday September 10, 2011
#
#
# Copy and Paste the text of this script into a text editor and save
# it as the file suff in the folder ~/bin (/home/username/bin).
# This script must be marked executable to be used. Please run
# the following Terminal command: chmod +x ~/bin/suff
#
declare -a format
#
# Check to see if we are root
#
if $UID -ne 0 ]]; then
id -Gn | grep -q wheel || echo "Root User Permissions are required, Please Enter the ..."
echo
sudo $0 $1
exit 0
fi
#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#
function show_gpl {
echo ""
echo "usbfloppyformat is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}
#
# Locate next Substring by space seperator in a long string
# Start looking at character position $1 in string $2
# Return location of next space, between sub-strings
#
function sub_string {
counter=$1
start=$2
num2=${#start}
while $(( counter )) -lt $(( num2 + 1 )) ] ; do
temp="${start:$(($counter)):1}"
if $temp != " " ]] ; then
let counter=counter+1
else
return ${counter}
fi
done
return ${counter}
}
# ----------------------------------------------------------------------------
# Prepair for install of ufiformat if needed by more than one distro
# The following coding provided by please_try_again
#
# install cpufrequtils under openSUSE, Fedora, Mandriva, Ubuntu
suselinux="zypper in"
mandrivalinux="urpmi"
fedora="yum install"
ubuntu="apt-get install"
# default to openSUSE if lsb_release is not found (or write more code to install
# lsb_release withouth confirmation or get the release name in another way)
install=suselinux
which lsb_release &>/dev/null && install=$(lsb_release -is | tr ":upper:]" ":lower:]" | tr -d " ")
install=${!install}
#-----------------------------------------------------------------------------
#
# Determine if the package ufiformat is installed
#
which ufiformat > /dev/null
Exit_Code=$?
if $(( Exit_Code )) -ge 1 ] ; then
tput clear
echo "The ufiformat Utility Package is not installed!"
echo
echo -n "Would you like to install the ufiformat package(y/N)?"
read CHOICE
if $CHOICE == [Yy] ]] ; then
sudo $install ufiformat
else
exit 1
fi
fi
#
# Main Program Starts Here
#
gui=true
while $gui ; do
clear
echo $TITLE
#
# Determine Floppy Drive designation
#
floppydrive=$(ufiformat --inquire --verbose | grep /dev/)
if "$floppydrive" == "" ] ; then
echo
echo "No USB connected Floppy Drive was found!"
echo
exit 1
fi
sub_string "0" "$floppydrive"
Exit_Code=$?
floppydrive=${floppydrive:0:$Exit_Code}
echo
echo "Your Floppy Disk Drive is called: $floppydrive"
if mount|grep $floppydrive > /dev/null ; then
echo
echo "Your device $floppydrive is mounted and must be un-mounted!"
echo
echo -n "Would you like to un-mount your floppy disk $floppydrive (y/N)?: "
read CHOICE
if $CHOICE == [Yy] ]] ; then
umount $floppydrive
else
echo
echo "Your floppy disk $floppydrive can't be formatted while mounted!"
echo
exit 1
fi
fi
sizes=$(ufiformat -i /dev/sdj | grep -c formattable)
line=$sizes
start=1
echo
echo "$floppydrive supports the following $sizes Formats:"
while $line -gt 0 ] ; do
format$start]=$(ufiformat -i /dev/sdj | grep formattable | sed -n $(( start ))p)
let line=line-1
let start=start+1
done
counter=0
echo
echo " status block size kb"
echo "--------------+-----+----+----"
while counter -lt sizes ]] ; do
let counter=counter+1
echo "$counter) ${format$counter]}"
done
echo
echo -n "Enter the Format size to use [1-$((sizes))] (q=Quit):"
read CHOICE
if $CHOICE =~ ^[0-9]+$ ]] ; then
if $CHOICE -le $sizes ]] && $CHOICE -gt 0 ]]; then
gui=false
let next1=1
let Exit_Code=0
format$CHOICE]=$( echo ${format$CHOICE]} | tr " " " ")
let length=${#format$CHOICE]}
while next1 -lt 5 ]] ; do
let final=Exit_Code
sub_string "$Exit_Code" "${format$CHOICE]}"
Exit_Code=$?
let Exit_Code=Exit_Code+1
let next1=next1+1
done
let form=length-final+1
size=${format$CHOICE]:final:form}
echo
echo -n "You have selected the format size of $size kb. Continue (y/N)?:"
read CHOICE
if $CHOICE == [Yy] ]] ; then
echo
echo "Formatting Floppy Disk Drive $floppydrive, Please Wait ...."
echo
ufiformat -f $size /dev/sdj
echo
echo "Please Enter The Floppy Disk Volume Label you wish to use. Do not"
echo "use any spaces or special charaters and max length is 13 charaters."
echo
echo -n "Please Enter the Disk Label or just press enter for the default: "
read CHOICE
/sbin/mkdosfs -I /dev/sdj -n "$CHOICE"
echo
echo "Your Floppy Disk Format of $floppydrive is now Complete."
show_gpl
else
echo
echo "Floppy Disk Format was Aborted!"
echo
fi
fi
else
if $CHOICE == [Qq] ]] ; then
show_gpl
exit 0
fi
fi
done
exit 0
# End Of Script
To mark S.U.F.F. executable, open up a terminal session and run the following command:
chmod +x ~/bin/suff
To us S.U.F.F. , just open up a terminal session and type:
suff
If you have any issues or comments about the S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00 script file, please let me know.
Thank You,