anyway, here's version 0.1 of floppycopy, it works fine as far as i can see:
- Code: Select all
#!/bin/bash
##################################################################
# floppycopy
#
# This script is designed to make a backup image of a floppy disk
# in /dev/fd0 (the first floppy drive in Linux) and write it to a
# file.
#
# This script (such as it is) where copied is regulated by the
# terms of the GNU General Public Licence, see www.gnu.org for
# more information.
#
# Usage: floppycopy <nameofimage>
# where nameofimage is the filename you wish to give the new
# image file. The actual filename will be "<nameofimage>.img"
# in the current directory. This file can be mounted and edited
# like any other filesystem using:
# mount -o loop <nameofimage>.img <directory>
# where <directory> is the name of the directory at which to mount
# the image. It can be rewritten to another floppy using:
# dd if=<nameofimage>.img of=/dev/fd0
#
# This script depends on "mount" and "dd"
#
# Version 0.1
##################################################################
umount /dev/fd0
dd if=/dev/fd0 of=$1.img
mount /dev/fd0
echo -e "\nBackup complete, floppy disk has now been remounted"
echo -e "Disk image has been written as $1.img"
and in fact i now have it sitting in my /usr/local/bin directory as a testament to my 1337 scripting skills!
however...
Version 0.2 is a little more ambitious and is not entirely "bug free" i think. it's (hopefully) simple enough but i thought i would post it here because of ESR's famous 'many eyeballs' thing.
- Code: Select all
#!/bin/bash
##################################################################
# floppycopy
#
# This script is designed to make a backup image of a floppy disk
# in /dev/fd0 (the first floppy drive in Linux) and write it to a
# file.
#
# This script (such as it is) where copied is regulated by the
# terms of the GNU General Public Licence, see www.gnu.org for
# more information.
#
# Usage: floppycopy <nameofimage>
# where nameofimage is the filename you wish to give the new
# image file. The actual filename will be "<nameofimage>.img"
# in the current directory. This file can be mounted and edited
# like any other filesystem using:
# mount -o loop <nameofimage>.img <directory>
# where <directory> is the name of the directory at which to mount
# the image. It can be rewritten to another floppy using:
# dd if=<nameofimage>.img of=/dev/fd0
#
# This script depends on "mount", "grep" and "dd"
# It also assumes the floppy disk drive is /dev/fd0, of course you
# could edit the script if your floppy drive is referred to by
# another device name.
#
# Version 0.2
#
# Version History:
# 0.2 - checks given filename before starting operation
# only attempts un/remounts if necessary
# 0.1 - can write floppy image to a file & remount disk
##################################################################
# Firstly I'm just going to check if /dev/fd0 is already mounted
mount | grep /dev/fd0 > /dev/null
mounted="echo $?"
# Now, let's unmount the floppy before we try to make our image
if [ $mounted -eq 0 ]
then
umount /dev/fd0
if [ $? -ne 0 ]
then
echo -e "Cannot unmount floppy disk,\nplease ensure no programs are accessing it and try
again"
exit 1
fi
fi
# Here, I am using dd to create an image file of the floppy disk
if [ $1 = 0 ]
then
echo -e "You must enter a file name\nExample: floppycopy filename"
exit 2
else
dd if=/dev/fd0 of=$1.img
fi
if [ $? -ne 0 ]
then
echo -e "PANIC PANIC PANIC!!!!! I couldn't make a backup of your floppy."
echo -e "Is the floppy in the drive?"
echo -e "Do you have write permission to the current directory?"
exit 3
fi
# If the disk was mounted before, let's be nice and remount it here
if [ $mounted -eq 0 ]
then
mount /dev/fd0
if [ $? -ne 0 ]
then
echo -e "Could not remount floppy, perhaps /dev/fd0 is not in /etc/fstab?"
fi
fi
# Goodbye Message:
echo -e "\nBackup complete,\nDisk image has been written as $1.img"
exit
now this doesn't seem to work properly to me, although it does appear to do the job, it doesn't seem to be unmounting the floppy while it does it (if i do 'mount' in another window, /dev/fd0 still shows up) also, whenever i execute the script, bash gives the error "./floppycopy: [: too many arguments" before continuing. I have limited skill at this, and in fact floppycopy 0.2 represents virtually my entire scripting knowledge (apart from a couple of hours learning perl i have since forgotten). I was going to try and recreate each of the errors i was trying to make it check for to see if it went wrong correctly (heh, if you see what i mean) but i haven't had time.
Anyway, comments, criticisms, insults are all welcomed.

