#!/bin/sh
#
# This shell script assumes that you have mounted your root partition
# on /mnt and all other partitions on /mnt/usr, /mnt/var, /mnt/usr/src,
# /mnt/usr/local, and /mnt/home.
#
# This assumes that var, home, usr, usr/local and usr/src have already
# been made.  This is necessary since these directories are required to
# be able to mount all of the filesystems.

cd /mnt

if [ ! -e var -o ! -e home -o ! -e usr -o ! -e usr/local -o ! -e usr/src ]
then
    echo "Not all of the required directories exist."
    echo
    echo "The following directories must exist:"
    echo "    /mnt/var"
    echo "    /mnt/home"
    echo "    /mnt/usr"
    echo "    /mnt/usr/local"
    echo "    /mnt/usr/src"
    echo "before copying files can begin."
    exit 1
fi

echo "Making directories..."
umask 022
mkdir bin boot dev etc lib mnt proc root sbin tmp

mkdir usr/bin usr/dict usr/doc usr/etc usr/games
mkdir usr/include usr/info usr/lib usr/man usr/sbin usr/share

mkdir usr/lib/games

mkdir usr/local/bin usr/local/doc usr/local/etc usr/local/games
mkdir usr/local/lib usr/local/info usr/local/man usr/local/sbin
mkdir usr/local/src

mkdir usr/man/man1 usr/man/man2 usr/man/man3 usr/man/man4 usr/man/man5
mkdir usr/man/man6 usr/man/man7 usr/man/man8 usr/man/man9

mkdir var/adm var/catman var/lib var/local var/lock var/named
mkdir var/nis var/preserve var/run var/spool var/tmp
mkdir var/lib/games var/lib/emacs
mkdir var/lock/emacs
mkdir var/spool/at var/spool/cron var/spool/lpd var/spool/mail
mkdir var/spool/mqueue var/spool/news var/spool/rwho var/spool/smail
mkdir var/spool/uucp

echo "Making links..."
ln -sf /var/tmp usr/tmp

echo "Copying files..."
cp -a /bin /boot /etc /home /lib /sbin /mnt
cp -a /dev/MAKEDEV /mnt/dev
cp -a /usr/bin /usr/sbin /usr/src /mnt/usr
cp -a /vmlinuz /mnt
cp /dev/null /mnt/var/adm/wtmp
cp /dev/null /mnt/var/adm/lastlog

echo "Changing permissions..."
chmod -R 777 /mnt/var/lock /mnt/var/spool
chmod -R 1777 /mnt/tmp /mnt/var/spool/mail /mnt/var/tmp
if [ -e /mnt/playpen ]; then chmod 777 /mnt/playpen; fi
chmod 775 /mnt/var/lib/games
chown root.games /mnt/var/lib/games

echo "Making devices..."
cd dev
./MAKEDEV generic

# Fix up a few things
mv /mnt/etc/fstab.inst /mnt/etc/fstab
mv /mnt/etc/lilo.conf.inst /mnt/etc/lilo.conf
mv /mnt/etc/rc.local.inst /mnt/etc/rc.local
mv /mnt/etc/termcap.inst /mnt/etc/termcap
cp /root/.profile.inst /mnt/root/.profile
cp /root/.cshrc.inst /mnt/root/.cshrc
cp /root/INSTALL /mnt/root/INSTALL

echo
echo "You need to:"
echo "   1. Edit /mnt/etc/fstab to mount all of your file systems"
echo "   2. Edit /mnt/etc/lilo.conf to set up lilo for your systems"
echo "   3. Type: sh -c 'ROOT=/mnt /mnt/sbin/lilo'"
echo
echo "You can then reboot from your hard disk."
