#!/bin/sh
# Copyright (C) 1993 David Niemi
# The author places no restrictions on the use of this script.

# this script requires mtools. If you don't have it, get it
# from prep.ai.mit.edu: /pub/gnu or other GNU repositories.

#define Q&D true	#8^)

set -e

a=3
ap=4
cc=1
d=6
e=5
f=1
iv=2
n=3
oi=3
oop=1
q=4
t=3
tcl=2
x=5
xap=2
xd=3
xv=2
y=1

at="Base Linux"
apt="Text based applications"
cct="GNU C 2.5.2 [NOT RECOMMENDED FOR GENERAL USE]"
dt="Program Development/GCC 2.4.5/kernel source and more"
et="Emacs"
ft="FAQs"
ivt="InterViews"
oit="OI ObjectBuilder"
oopt="OOP: Smalltalk"
qt="Extra Alpha Kernel Source"
tclt="Tcl Script Language/Tk Toolkit"
tt="TeX"
xt="X-Windows (XFree86 2.0)"
xapt="X Applications"
xdt="X Programming/Development"
xvt="XView 3.2 (OpenLook Window Manager)"
yt="Games"

echo
echo "Which of the following is your target device:"
echo
echo "1 - Sun floppy drive"
echo "2 - 3.5\" Linux drive a: (/dev/fd0H1440)"
echo "3 - 3.5\" Linux drive b: (/dev/fd1H1440)"
echo
echo -n "Enter your choice (1/2/3), or the name of an alternate device: "
read device;
FD="a:"
if [ "$device" = "1" ]; then
  device=/dev/rfd0c
elif [ "$device" = "2" ]; then
  device=/dev/fd0H1440
elif [ "$device" = "3" ]; then
  FD="b:"
  device=/dev/fd1H1440
fi
echo "Creating floppies on device $device."
echo
echo "Please insert a blank floppy for the boot disk and"
echo -n "press [enter], or [s] to skip: "
read foo

if [ "X$foo" != 'Xs' ]; then
  gzip -cd bootdisk.gz | dd of=$device obs=18k 
  if [ "$device" = "/dev/rfd0c" ]; then
    eject
  fi
fi

dollar='$'

for series in a e f iv oop oi q tcl x xap xd xv y; do
  diskno=1
  maxdisk=`eval echo "$dollar$series"`
  descrip=`eval echo "$dollar${series}t"`
  echo
  echo "Making $maxdisk floppies for series \"$series\" (${descrip})"
  while [ "$diskno" -le $maxdisk ]; do
    disk=$series$diskno
    done=
    while [ -z "$done" ]; do
      echo "Please insert disk $disk and press [enter], or enter"
      echo -n "[q] to quit, [f] to skip floppy, [s] to skip series: "
      read answer
      case $answer in
      q)
        exit 0
        ;;
      s)
        diskno=$maxdisk
        done=yes
        ;;
      f)
        done=yes
        ;;
      esac
      if [ -z "${done-}" ]; then
        if [ ! -d "$disk" ]; then
          echo '^G'
          echo "Directory \"$disk\" does not exist!"
        else
          if mformat $FD; then
            if mcopy $disk/* $FD; then
              done=yes
              if [ "$device" = "/dev/rfd0c" ]; then
                eject
              fi
            else
              echo '^G'
              echo "mcopy failed!"
              if [ "$device" = "/dev/rfd0c" ]; then
                eject || :
              fi
            fi
          else
            echo '^G'
            echo "mformat failed!"
            if [ "$device" = "/dev/rfd0c" ]; then
              eject || :
            fi
          fi
        fi
      fi
    done
    diskno=`expr $diskno + 1`
  done
done
