[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[mtools] mtsetup script
From: |
Richardson, Anthony |
Subject: |
[mtools] mtsetup script |
Date: |
Sun, 11 Jan 2004 18:42:53 -0600 |
Dear mtools users,
I've been working with a lot of different floppy and hard disk images
for bochs (under Windows) recently. I found it annoying to always be
editting ~/.mtoolsrc every time I wanted to work with a new image so
I wrote a shell script that automatically creates an appropriate
~/.mtoolsrc file for me. I call the shell script "mtsetup".
It creates an ~/.mtoolsrc file in which a floppy image is available
as drive A: while a hard drive image is available as drive C:
The script autodetects whether an image is a floppy image or a hard
drive image if the filesystem is formatted. If the
filesystem is unformatted autodetection will fail. In that case
use either the -f or -h options to indicate whether it is a floppy
or hard drive image.
Here are some examples demonstrating usage:
> mtsetup floppy.img # floppy.img now available as drive A:
> mtsetup disk.img # set C: drive, floppy.img still as A:
> mtsetup -f floppyb.img # unformatted floppy image
> mtsetup -h x.img 3 # use part 3 of hard drive image as C:
> mtsetup -f /dev/fd0 # real floppy drive is now A:
I've attached the script below. I put it together in a
couple of hours yesterday, so it's a bit of a hack, but maybe it
will inspire someone to clean it up and/or make improvements to it.
I've only used it under cygwin on Windows, but it should work under
Linux.
A word of warning, it wipes out your current ~/.mtoolsrc, so if you've
done a lot of work customizing that file, don't use this script (or copy
it to a different file first).
Regards
Tony Richardson
address@hidden
================ cut here ================================
#!/bin/bash
#usage: mtsetup [-f | -h | --help] image [part #]
error () {
echo $* >&2
}
if [ $# -lt 1 -o $# -gt 3 -o "$1" = "--help" ]
then
error "usage: mtsetup [-f | -h | --help] image [part #]"
error ""
error "Configures mtools so that image is the current mtools drive"
error "At any one time you may have both an active floppy drive (A:)"
error "and an active hard drive (C:)."
error
error "If a partition # is specified (1-4) then a hard drive image
is"
error "assumed. The -f and -h options can be used to indicate"
error "whether the image is a floppy or hard drive image. If these"
error "options are used the filesystem is not checked. This is"
error "useful if the filesystem is to be formatted with mformat."
error "If -f or -h are not used mtsetup tries to deduce whether the"
error "image is a floppy or hard drive image (with parition 1)."
error
error "In practice, you just need to type \"mtsetup floppya.img\" to"
error "access the image file as drive A. If you then type,"
error "\"mtsetup harddisk.img\" then partition 1 of this disk will"
error "available as drive C: (and the last floppy image will still"
error "be available as A:)"
exit 1
fi
forceflop=false
forcehard=false
if [ "$1" = "-f" ]
then
forceflop=true
shift
fi
if [ "$1" = "-h" ]
then
forcehard=true
shift
fi
# Default MTSETUP .mtoolsrc file
line1="#MTSETUP"
line2="MTOOLS_NO_VFAT=1"
line3="drive A: file=\"\" 1.44m mformat_only"
line4="drive C: file=\"\" partition=1"
mtsrc=$HOME/.mtoolsrc
gen_mtsrc () {
echo "#MTSETUP" > $mtsrc
echo "MTOOLS_NO_VFAT=1" >> $mtsrc
echo "drive A: file=\"$1\" 1.44m mformat_only" >> $mtsrc
echo "drive C: file=\"$2\" partition=$3" >> $mtsrc
}
# See if $mtsrc exists
if [ -s $mtsrc ]
then
# Yes, it does.
# Read first line and check if it is an MTSETUP file
read < $mtsrc
if [ "$REPLY" != "#MTSETUP" ]
then
# Not an MTSETUP file, overwrite it
gen_mtsrc "" "" "1"
fi
else
# $mtsrc does not exist, create a default one
gen_mtsrc "" "" "1"
fi
# OK, now we should have a standard MTSETUP file
# Read it in
{ read line1; read line2; read line3; read line4; } < $mtsrc
flopfile=$(echo "$line3" | cut -d' ' -f3 | cut -d\" -f2)
hardfile=$(echo "$line4" | cut -d' ' -f3 | cut -d\" -f2)
partition=$(echo "$line4" | cut -d' ' -f4 | cut -d= -f2)
hardimg=true
if [ $forcehard = true -o $# = 2 ]
then
# A hard drive image
if [ $# = 1 ]
then
# no hard drive partition given
set "$1" "1"
fi
gen_mtsrc "$flopfile" "$1" "$2"
if [ $forcehard = false ]
then
if ! mcd C: 2> /dev/null
then
error "Partition $2 of image $1 does not appear to be a FAT"
error "formatted file system. (Use -h to force.)"
gen_mtsrc "$flopfile" "$hardfile" "$partition"
exit 1
fi
fi
elif [ $forceflop = true ]
then
# A floppy drive image
gen_mtsrc "$1" "$hardfile" "$partition"
hardimg=false
else
# Image type unknown
# guess hard drive partition
gen_mtsrc "$flopfile" "$1" "1"
if ! mcd C: 2> /dev/null
then
# not a hard drive image, try a floppy image
gen_mtsrc "$1" "$hardfile" "$partition"
if ! mcd A: 2> /dev/null
then
error "Hmmm. Does not appear to be a standard floppy or"
error "hard disk with FAT on partition 1. Giving up."
error "Use -f or -h option to force."
gen_mtsrc "$flopfile" "$hardfile" "$partition"
exit 1
fi
hardimg=false
else
partition=1
fi
fi
if [ $hardimg = true ]
then
echo "Partition $partition of hard disk image $hardfile is MTOOLS
drive C:"
else
echo "Floppy disk image $flopfile is MTOOLS drive A:"
fi
_______________________________________________
mtools mailing list
address@hidden
http://www.tux.org/mailman/listinfo/mtools
- [mtools] mtsetup script,
Richardson, Anthony <=