#!/bin/sh
#BLURB="Create a Linux boot floppy"
TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
T_PX="$1"
ROOT_DEVICE="$2"
while [ 0 ]; do # the bootdisk menu loop
 dialog --title "MAKE BOOTDISK" --ok-label Create --cancel-label Skip --menu \
"It is highly recommended that you make \
a bootdisk (or two) for your system at this time.  Please insert a floppy disk \
(formatted or unformatted) and press ENTER to create a bootdisk.  \n\
\n\
The existing contents of the floppy disk will be erased." 13 70 2 \
 "Create" "Make a Linux bootdisk in /dev/fd0" \
 "Skip" "Skip making a bootdisk" \
 2> $TMP/return
 REPLY=`cat $TMP/return`
 rm -f $TMP/return
 if [ "$REPLY" = "Create" ]; then
   dialog --title "Formatting /dev/fd0u1680" --infobox "Formatting /dev/fd0, \
1.68 megabytes." 3 42
   if [ -x /sbin/fdformat ]; then
     /sbin/fdformat -n /dev/fd0u1680 1> /dev/null 2> /dev/null
   else
     chroot $T_PX fdformat -n /dev/fd0u1680 1> /dev/null 2> /dev/null
   fi
   if [ ! $? = 0 ]; then
     dialog --title "ERROR: FLOPPY FORMAT FAILED" --msgbox "The attempt to format the floppy \
disk in /dev/fd0 has failed, probably due to bad media.  Please try again with a \
different disk.  If that doesn't work, perhaps the drive needs cleaning." 0 0
    continue
   fi
  rm -f $TMP/return
  dialog --title "CREATING BOOT FLOPPY" --infobox "Creating SYSLINUX bootdisk for \
$ROOT_DEVICE in /dev/fd0." 3 64 
   if [ -x /sbin/mkdosfs ]; then
     /sbin/mkdosfs -F 12 /dev/fd0u1680 1680 1> /dev/null 2> /dev/null
   else
     chroot $T_PX /sbin/mkdosfs -F 12 /dev/fd0u1680 1680 1> /dev/null 2> /dev/null
   fi
   if [ ! -d $TMP/bootdisk ]; then
    mkdir $TMP/bootdisk
   fi
   mount -t vfat /dev/fd0 $TMP/bootdisk 1> /dev/null 2> /dev/null
   if [ -r $T_PX/vmlinuz ]; then
     cp $T_PX/vmlinuz $TMP/bootdisk/vmlinuz
   elif [ -r $T_PX/boot/vmlinuz ]; then
     cp $T_PX/boot/vmlinuz $TMP/bootdisk/vmlinuz
   fi
   ## This avoids a syslinux-1.72 bug, and doesn't seem to hurt anything:
   #dd if=/dev/zero bs=1k count=1 >> $TMP/bootdisk/vmlinuz 2> /dev/null
   cat << EOF > $TMP/bootdisk/message.txt

Welcome to the 09Slackware07 Linux custom bootdisk!

By default, this disk boots a root Linux partition on $ROOT_DEVICE when you
hit ENTER.  If you'd like to boot some other partition, use a command like
this on the prompt below:

    mount root=/dev/sda1 ro

Where "/dev/sda1" is the partition you want to boot, and "ro" specifies that
the partition should be initially mounted as read-only.  If you wish to mount
the partition read-write, use "rw" instead.  To set the video console mode,
use the vga= parameter (press F1 to see a table).  You may also add any other
kernel parameters you might need depending on your hardware, and which
drivers are included in your kernel.

EOF
   cat << EOF > $TMP/bootdisk/syslinux.cfg
default vmlinuz ramdisk_size=7000 root=$ROOT_DEVICE vga=normal ro
prompt 1
timeout 6000
display message.txt
F1 f1.txt
F2 message.txt
#F3 f3.txt
#F4 f4.txt
#F5 f5.txt
#F6 f6.txt
#F7 f7.txt
label mount
  kernel vmlinuz
  append ramdisk_size=7000 root=$ROOT_DEVICE vga=normal ro
label ramdisk
  kernel vmlinuz
  append vmlinuz ramdisk_size=7000 root=/dev/fd0u1440 vga=normal rw
EOF
  cat << EOF > $TMP/bootdisk/f1.txt
 STANDARD MODES:
 To make the kernel prompt for standard video modes use: vga=ask

 FRAMEBUFFER MODES:
 To get the kernel to start in VESA framebuffer mode, you need to pass it
 a vga= init string on the "boot:" prompt.  Here's a table:

   Colors   640x480 800x600 1024x768 1280x1024 1600x1200
  --------+---------------------------------------------
  256     |   769     771      773      775       796
  32,768  |   784     787      790      793       797
  65,536  |   785     788      791      794       798
  16.8M   |   786     789      792      795       799

  ...such as this for 1024x768x64k:
   vga=791

  F2 returns to the previous page.

EOF
  umount /dev/fd0
  syslinux -s /dev/fd0
  rm -r $TMP/bootdisk
  dialog --title "BOOTDISK CREATED" --ok-label Continue --cancel-label Create --menu \
"The boot floppy has been successfully created in /dev/fd0.  If you would like to \
create an additional bootdisk, please select 'Create' and we'll go back and make another \
one, otherwise select 'Continue' to continue configuring your system." 12 70 2 \
 "Continue" "Continue the configuration (done making bootdisks)" \
 "Create" "Make a spare Linux bootdisk in /dev/fd0" \
 2> $TMP/return
  REPLY=`cat $TMP/return`
  rm -f $TMP/return
  if [ "$REPLY" = "Create" ]; then
   continue
  else
   break
  fi
 else # ! Create
  break
 fi
done