#! /sbin/sh
#
# Granada Microcare Helpdesk
#
# mkboot... A script to create a floppy containing ( in conjunction 
# with a bootable kernel disc,mkboot disk and achive disk )
# sufficient utilities to boot an R260 with RISCiX 1.21
# from the floppy device. It also contains utilities and scripts for
# building a new RISCiX filesystem on the active drive.


cat << INTRO
                         -- mkboot--

 > This script will create a floppy containing the rest of the system
 > files neccessary to boot ( in conjunction with the 'kernel' disc ,
 > and archive disc ) from the floppy disc drive.
 > It also creates the following scripts :
 >
 > mksystem: which will create a new RISCiX filesystem on a newly
 > formatted hard disc and install the minimum system files needed
 > to make the hard disc bootable. It also installs the following
 > script in the / directory.
 > 
 > cpsys : which will copy all the files across from the archive disc(s),
 > Kernel disc and restore disc.
 > Insert floppy disc and press Return when ready.........
 >
 >     ( Type any character key/s followed by Return to abort )

INTRO

read STRING
if [ ${STRING}X != "X" ]
then
     echo; echo $0 aborted; echo
     exit 1
fi

# Only Return has been pressed so go ahead and make the boot disc.....

echo; echo " > Formatting floppy....."; echo
ffd 
if [ $? -gt 1 ]
then
	echo; echo " > Error formatting floppy"; echo;
	exit
fi

echo; echo " > Making filesystem....."; echo

newfs /dev/fdf1024 fdf1024
# Check for errors during newfs.....
if [ $? -gt 0 ]
then
	echo; echo " > Error in newfs"; echo;
	exit
fi

echo; echo " > Making space.........."; echo
tunefs -o space -A -m 0 /dev/fdf1024

echo
mount /dev/fdf1024 /mnt 

# Check for errors during mount.....
if [ $? -gt 0 ]
then
	echo; echo " > Error mounting floppy"; echo;
	exit
fi

# First the minimum equipment ( ?? ) required to get the system
# up off the floppy drive......

echo; echo " > Creating directories....."; echo
mkdir /mnt/etc /mnt/mnt /mnt/usr /mnt/tmp /mnt/dev /mnt/sbin
mkdir /mnt/usr/sbin  /mnt/usr/lib /mnt/usr/bin  /mnt/ext
mkdir /mnt/usr2 /mnt/usr2/dev /mnt/usr2/tmp /mnt/usr2/mnt

echo; echo " > Creating device driver sub set....."; echo
mknod /mnt/dev/console  c  0 0;
mknod /mnt/dev/fdf1024  b  9 0;
mknod /mnt/dev/rfdf1024 c 19 0;
mknod /mnt/dev/kmem     c  1 1;
mknod /mnt/dev/null     c  1 2;
mknod /mnt/dev/cmos     c  1 3;
mknod /mnt/dev/tty      c  3 0;
mknod /mnt/dev/rsd0a    c  21 0;
mknod /mnt/dev/rsd0b    c  21 1;
mknod /mnt/dev/rsd0c    c  21 2;
mknod /mnt/dev/rsd0h    c  21 7;
mknod /mnt/dev/sd0a     b  12 0;
mknod /mnt/dev/sd0b     b  12 1;
mknod /mnt/dev/sd0c     b  12 2;

echo; echo " > Copying some files....."; echo
( cd /etc ; tar cf - fstab mtab utmp disktab ) | ( cd /mnt/etc ; tar xf - )
( cd /usr/lib ; tar cf - c:9010241403.11 ) | ( cd /mnt/usr/lib ; tar xf - )
( cd /usr/bin ; tar cf - cat ) | ( cd /mnt/usr/bin ; tar xf - )
( cd /sbin ; tar cf - sh init mount umount halt mknod chmod tar ) | ( cd /mnt/sbin ; tar xf - )
cat /dev/null > /mnt/etc/mtab


# awk out the termacap entry for avc....
echo; echo " > Creating mini termcap....."; echo
awk ' /^AV/, /^#/ { print $0 } ' /etc/termcap > /mnt/etc/termcap

# Now create the mksystem script which will be run ( on the 
# floppy ) after booting from the floppies and will carry out
# the single-user rebuild process.....

echo; echo " > Creating mksystem script..."
echo
echo; echo " > scsidm from the (mknewfs disc) must be run before mksystem..."
echo

# =========== THIS IS THE START OF THE mksystem SHELL SCRIPT ========

cat > /mnt/mksystem << MKSYSTEM
#! /sbin/sh

# This script should be run after booting from the floppy
# set and with the floppy as the filesystem root. 
# It will install various files and devices and create the
# cpsys script in the hard discs root which will install the 
# kernel and de-dsplit the archive disc........

cat << WARNING
			   !! WARNING !!

   This process writes data to the RISCiX partition of the target drive !
   Press Return to continue or press Ctrl+C to abort ........

WARNING
read JUNK
cat << OK

       Proceeding with creating file system, please wait.....

OK

mount /dev/sd0a /ext


# Copy whatever utilities there are .....
( cd / ; tar cf - ./usr ) | ( cd /ext ; tar xf - )
( cd / ; tar cf - ./etc ) | ( cd /ext ; tar xf - )
( cd / ; tar cf - ./sbin ) | ( cd /ext ; tar xf - )
( cd / ; tar cf - .profile ) | ( cd /ext ; tar xf - )
( cd /usr2 ; tar cf - ./dev ./tmp ./mnt ) | ( cd /ext ; tar xf - )


# Make devices.....
mknod /ext/dev/console  c  0 0;
mknod /ext/dev/fdf1024  b  9 0;
mknod /ext/dev/rfdf1024 c 19 0;
mknod /ext/dev/kmem     c  1 1;
mknod /ext/dev/mem      c  1 0;
mknod /ext/dev/drum     c  8 0;
mknod /ext/dev/null     c  1 2;
mknod /ext/dev/cmos     c  1 3;
mknod /ext/dev/tty      c  3 0;
mknod /ext/dev/ttyv0    c  0 4;
mknod /ext/dev/ttyv1    c  0 5;
mknod /ext/dev/ptyp0    c  5 0;
mknod /ext/dev/ptyp1    c  5 1;
mknod /ext/dev/ptyp2    c  5 2;
mknod /ext/dev/ptyp3    c  5 3;
mknod /ext/dev/ptyp4    c  5 4;
mknod /ext/dev/rsd0a    c 21 0;
mknod /ext/dev/rsd0b    c 21 1;
mknod /ext/dev/rsd0c    c 21 2;
mknod /ext/dev/rsd0h    c 21 7;
mknod /ext/dev/sd0a     b 12 0;
mknod /ext/dev/sd0b     b 12 1;
mknod /ext/dev/sd0c     b 12 2;


# Create the cpsys script...........
#
# =========== THIS IS THE START OF THE cpsys SHELL SCRIPT ========
#
cat > /ext/cpsys << CPSYS
#! /sbin/sh

# This script ( created by mksystem ) should be run after booting vmunix
# from the floppy and the rest of RISCiX from the hard disc. It will 
# copy the kernel across from the floppy and de-dsplit the archive
# disc...

cat << CPSYS_MSG1

 > Insert kernel disc and press Return when ready.........
 >
 >        ( Press Ctrl and C together to abort )

CPSYS_MSG1

read JUNK

# Copy the kernel across plus files............
/sbin/mount /dev/fdf1024 /mnt
( cd /mnt ; tar cf - vmunix .profile ) | ( cd / ; tar xf - )
( cd /mnt ; tar cf - uncompress dsplit ls ) | ( cd /sbin ; tar xf - )
( cd /mnt ; tar cf - group hosts passwd  ) | ( cd /etc ; tar xf - )

/sbin/umount /mnt

cat << CPSYS_MSG2

 > Insert first archive disc and press Return when ready.........
 >
 >        ( Press Ctrl and C together to abort )

CPSYS_MSG2

read JUNK

/sbin/dsplit -t ARCHIVE | uncompress | tar xf -


cat << CPSYS_MSG3

 > The installation process is now complete. It should now be possible
 > edit the network config files  ( /etc/hosts, /etc/rc.net, /etc/rc.config )
 > go multi-user ( type Ctrl + D )  and mount the network.

CPSYS_MSG3

CPSYS

#
# =========== THIS IS THE END OF THE cpsys SHELL SCRIPT ========
#

chmod 755 /ext/cpsys

# That's it.

cat << MKSYSTEM_MSG

      Filesystem created , device driver subset installed
      and some system files copied to hard disc. To complete 
      the installation you should now 'halt' the system, 
      reboot using the kernel disc for vmunix and the hard disc
      for the rest of the filesystem using the following .....
 
      Set device in cmos ram to fd0

      boot vmunix sd0(0,0) sd0(0,1)

      and then run cpsys to install the kernel etc.

MKSYSTEM_MSG

cat > /ext/.profile  << MKPROFILE_A

PATH=/usr/local/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bin:/usr/5bin:/usr/acorn:/usr/new:/usr/bin/X11::
HOME=/
export PATH HOME

if [ "${TERM}" = "" ]; then
	TERM=avc
	export TERM
fi

echo; echo " > run (cpsys) to start the installation process....."; echo

MKPROFILE_A

MKSYSTEM
#
# =========== THIS IS THE END OF THE mksystem SHELL SCRIPT ========
#
cat > /mnt/.profile  << MKPROFILE

PATH=/usr/local/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bin:/usr/5bin:/usr/acorn:/usr/new:/usr/bin/X11::
HOME=/
export PATH HOME

if [ "${TERM}" = "" ]; then
	TERM=avc
	export TERM
fi

echo; echo " > run (mksystem) to enable single user startup on the target hard disc..."; echo

MKPROFILE


# mksystem is now complete...
chmod ugo+x /mnt/mksystem

cd /
umount /mnt

cat << FINISHED

 > mkboot disc successfully created. Note that in future this
 > disc will be referred to as the 'mkboot disk' and you may 
 > wish to label it accordingly...

FINISHED

#      ================= END OF SCRIPT =====================

