#! /bin/bash
#
# Copyright 1993 Thomas Heiling, Wuerzburg, Germany
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is 
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# As always, bug reports, suggestions, etc: phar006@rz.wrzv1.uni-wuerzburg.de
# 
PATH=:/sbin:/bin:/etc:/usr/bin:/etc/lilo
ROOTDEVICE=/dev/fd0

echo
echo "Welcome to MAKEBOOT, a boot disk creation utility."
echo
if [ "$1" = "" ]; then
	echo "The default kernel used to make this boot disk will be /vmlinuz"
	echo "If you'd like to use a better kernel,then you should"
	echo "hit control-C to end this script and restart"
	echo "makeboot again using the full path and filename as the argument."
	echo "For example: "
	echo  
	echo "makeboot /zImage"
	KERNEL=/vmlinuz
else
	KERNEL=$1
fi
echo
echo "Please insert a formatted floppy disk into your boot drive. This will be"
echo "made into your new Linux boot disk."
echo
echo -n "Press [enter] when ready."  
read REPLY;
echo
echo "Copying kernel ($KERNEL) to floppy."
#The Blocksize is for a 1.2 M Floppy. Use 9216 for a 3.5 M
echo "(dd if=$KERNEL of=$ROOTDEVICE obs=7680)" 
dd if=$KERNEL of=$ROOTDEVICE
echo "Kernel copied."
echo
echo "This boot disk must be configured to boot your root partition."
echo
while [ 0 ]; do
	echo "At this prompt below, enter the name of your root partition (such as"
	echo "/dev/hda1), or enter [p] for a partition list."
	echo "If you make a rescue disk set it to $ROOTDEVICE"
	echo 
	echo -n "Partition? "
	read PARTITION;  
	if [ "$PARTITION" = "p" ]; then
		echo
		fdisk -l
		echo
	else
		break;
	fi
done
echo
echo "Setting root partition to $PARTITION..."
echo "  rdev $ROOTDEVICE $PARTITION"
rdev $ROOTDEVICE $PARTITION
echo
echo "You need to choose a video mode. There is the standard 80x25 mode, and"
echo "an extended mode."
echo
echo "What video mode would you like?"
echo "-1 : Normal VGA"
echo "-2 : Extended VGA"
echo "-3 : Ask at boot time"
echo "0 : as if 0 was pressed at boot time"
echo "1 : as if 1 was pressed at boot time"
echo "2 : as if 2 was pressed at boot time"
echo
while [ 0 ]; do
	echo -n "Video mode (-1, -2, -3,0,1,2)? "	
	read VIDMODE;
	if [ "$VIDMODE" = "-1" -o "$VIDMODE" = "-2" -o "$VIDMODE" = "-3" \
	-o "$VIDMODE" = "0" -o "$VIDMODE" = "1" -o "$VIDMEODE" = "2" ]; then
		break;
	fi
done
echo
echo "Setting video mode to $VIDMODE..."
echo "  rdev -v $ROOTDEVICE $VIDMODE"
rdev -v $ROOTDEVICE $VIDMODE
echo
echo "Setting of read-only/read-write flag:"
echo
echo "If you're using bootutils, your partition should be mounted read-only."
echo "Bootutils will check the partition, and then remount it read-write. If"
echo "you are not using bootutils, you'll probably want to have this boot disk"
echo "mount your root partition read-write."
echo 
echo "0 : read-write"
echo "1 : read-only"
echo
while [ 0 ]; do
	echo -n "Which setting? "
	read ROOTFLAG;
	if [ "$ROOTFLAG" = "0" -o "$ROOTFLAG" = "1" ]; then
		break;
	fi
done
echo
echo "Setting root flags..."
echo "  rdev -R $ROOTDEVICE $ROOTFLAG"
rdev -R $ROOTDEVICE $ROOTFLAG
echo "Setting the size of the ramdisk"
echo
echo "If you are creating a Rescue disk with MAKEROOT, you should enter"
echo "at least 1200 KB for a RAMDISK."
echo "If you don't need a RAMDISK enter 0" 
echo 
while [ 0 ]; do
	echo -n "Which Size? "
	read RAMDISKSIZE;
	if [ ! "$RAMDISKSIZE" = "" ]; then
		break;
	fi
done
echo
echo "Setting RAMDISK Size..."
echo "  rdev -r $ROOTDEVICE $RAMDISKSIZE"
rdev -r $ROOTDEVICE $RAMDISKSIZE

echo
echo "Boot disk created."
echo
