# shell script to create a bootable floppy disk
# Written by Udo Munk (udo@umunk.GUN.de)
# with help from Vladimir Smelyansky (vlad@mwc.com)
# Modified for 4.2 by Robert Chalmers ( robert@cstpl.com.au )
  clear
  if [ $USER != root ]
  then
    echo "This program must be run as user root!"
    exit
  fi
  echo "This programm creates a bootable floppy disk for COHERENT."
  echo "Because booting the PC hardware only works with floppy drive A"
  echo "I want to know the size of your A device first."
  echo
  while true
  do
    echo -n "Is your A device a 5.25 inch drive (answer y or n): "
    read answer
    if [ $answer = y -o $answer = n ]
    then
      break
    else
      echo "answer with y or n please!"
      echo
    fi
  done
  if [ $answer = y ]
  then
    echo "Fine, let us create a 5.25 inch bootable floppy disk."
    dev=/dev/fha0
    devsize="5.25"
    devblocks=2400
    boot=/conf/boot.fha
  else
    echo "Fine, let us create a 3.5 inch bootable floppy disk."
    dev=/dev/fva0
    devsize="3.5"
    devblocks=2880
    boot=/conf/boot.fva
  fi
  echo
  echo "Now please put a" $devsize "floppy disk into your drive A".
  echo "WARNING: ALL DATA ON THIS FLOPPY DISK WILL BE DESTROYED!"
  echo
  echo -n "Type y if you want to continue, any other to abort: "
  read answer
  if [ $answer != y ]
  then
    exit
  fi
  clear
  echo "Step 1: formating floppy disk..."
  if [ $dev = /dev/fha0 ]
      then
     /etc/fdformat -i 3 -o 0 $dev
  else
     /etc/fdformat -i 3 -o 6 $dev
  fi
  echo "Step 2: building the bad block list..."
  /etc/badscan -o bootdisk $dev $devblocks
  echo "Step 3: building a filesystem..."
  /etc/mkfs $dev bootdisk
  rm bootdisk
  echo "Step 4: copy the bootstrap onto the floppy disk..."
  cp $boot $dev
  /etc/mount $dev /mnt
  if [ -f /tboot ]
  then
    cp /tboot /mnt
  fi
  echo "Step 5: copy the kernel and patch it..."
  cp /coherent /mnt
  ln /mnt/coherent /mnt/autoboot
  if [ -f /tboot ]		
  # we are running Coherent 4.x
  then
    if [ $dev = /dev/fha0 ]	
    # drive A is 5.25 inch
    then
      /conf/patch /mnt/coherent rootdev=makedev\(4,14\)
      /conf/patch /mnt/coherent pipedev=makedev\(4,14\)
    else				
    # drive A is 3.5 inch
      /conf/patch /mnt/coherent rootdev=makedev\(4,15\)
      /conf/patch /mnt/coherent pipedev=makedev\(4,15\)
    fi
   fi
  echo "Step 6: copy all neccesary files to the floppy disk..."
  mkdir /mnt/mnt
  mkdir /mnt/tmp
  cpdir /dev /mnt/dev
  mkdir /mnt/conf
  mkdir /mnt/bin
  #=================== put the keyboard of choice here ==========
  # However, this new keyboard may not run as required. Check
  # your configuration to ensure this. It seems to depend on where
  # the loadable keyboard driver is loaded from? See Udo on this one.
  cp /conf/kbd/german /mnt/conf/kbd
  cp /bin/bad /mnt/bin
  cp /bin/check /mnt/bin
  cp /bin/chgrp /mnt/bin
  cp /bin/chmod /mnt/bin
  cp /bin/chown /mnt/bin
  cp /bin/cp /mnt/bin
  cp /bin/cpdir /mnt/bin
  cp /bin/date /mnt/bin
  cp /bin/df /mnt/bin
  cp /bin/[ /mnt/bin
  cp /bin/find /mnt/bin
  cp /bin/grep /mnt/bin
  cp /bin/ln /mnt/bin
  cp /bin/ls /mnt/bin
  cp /bin/lc /mnt/bin
  cp /bin/mkdir /mnt/bin
  cp /bin/mv /mnt/bin
  cp /bin/ps /mnt/bin
  cp /bin/pwd /mnt/bin
  cp /bin/rm /mnt/bin
  cp /bin/rmdir /mnt/bin
  cp /bin/sh /mnt/bin
  cp /bin/stty /mnt/bin
  cp /bin/sync /mnt/bin
  mkdir /mnt/usr
  mkdir /mnt/usr/tmp
  mkdir /mnt/usr/bin
  cp /usr/bin/vi /mnt/usr/bin
  cp /usr/bin/dpac /mnt/usr/bin
  cp /usr/bin/more /mnt/usr/bin
  if [ -d /usr/lib/terminfo ]
  then
    mkdir /mnt/usr/lib
    mkdir /mnt/usr/lib/terminfo
    mkdir /mnt/usr/lib/terminfo/a
    cp /usr/lib/terminfo/a/ansipc /mnt/usr/lib/terminfo/a
  fi
  mkdir /mnt/etc
  cp /etc/ATclock /mnt/etc
  cp /etc/badscan /mnt/etc
  cp /etc/clri /mnt/etc
  if [ -f /etc/drvld ]
  then
    cp /etc/drvld /mnt/etc
  fi
  cp /etc/profile /mnt/etc
  cp /etc/passwd /mnt/etc
  cp /etc/shadow /mnt/etc
  cp /etc/group /mnt/etc
  cp /etc/domain /mnt/domain
  cp /etc/drvld.all /mnt/etc
  cp /etc/fdisk /mnt/etc
  cp /etc/fsck /mnt/etc
  cp /etc/init /mnt/etc
  cp /etc/mkfs /mnt/etc
  cp /etc/mount /mnt/etc
  cp /etc/reboot /mnt/etc
  cp /etc/umount /mnt/etc
  cp /etc/serialno /mnt/etc
  cp /etc/timezone /mnt/etc
  cp /etc/termcap /mnt/etc
  mkdir /mnt/etc/default
  cp /etc/default/login /mnt/etc/default
  echo "Step 7: create lost+found with enough empty directory slots..."
  mkdir /mnt/lost+found
  if [ $dev = /dev/fha0 ]	
  then
  for I in 0 1 2
  do
    for J in 0 1 2
    do
      touch /mnt/lost+found/$I$J
    done
  done
  else
  for I in 0 1 2 3 4 5 
  do
    for J in 0 1 2 3 4 5
    do
      touch /mnt/lost+found/$I$J
    done
  done
 fi
  rm /mnt/lost+found/*
echo "Step 8: create some files, so that boot ends in single user mode..."
cat > /mnt/etc/brc << TT_EOF
. /etc/timezone
/bin/date -s \`/etc/ATclock\` >/dev/null
#this next bit should load keyboard tables?
/etc/drvld.all
exit 1
TT_EOF
#put a profile in here....
cat > /mnt/etc/.profile << PF_EOF
# /etc/profile 09/08/93
# Executed at login for all users.
umask 022
export PAGER="exec /usr/bin/more -ls"
export PATH=/bin:/usr/bin
export TERM=ansipc
export LOGNAME=$USER
export HZ=100
PF_EOF
cat /etc/checklist >/mnt/etc/checklist
cat /etc/mount.all >/mnt/etc/mount.all
echo "Last step: check the filesystem of the created floppy disk:"
sync
echo "Just a moment..."
sleep 5
/etc/umount $dev
/etc/fsck $dev
echo "Fine, floppy disk ready, store it at a cool dry place but"
echo "where you can remember in case of an emergency :-)"
echo "========================================================="
