#!/bin/bash
#
# Original File
# --------------
#	http://www.Linux-1U.net/CDRW/scripts/boot.MakeContents.sh
#
#
# Create All the Files Needed on the CDROM
#
#
# 21-Nov-02 amo Date-of-birth
#
#
NAM="cdrw.MakeContents-0.5.sh"
#
TAR=/bin/new.tar
#
TREE="/opt/cd_image.Tree"
CDRW="/opt/Boot.CDRW"
#
EXCLUDE=$CDRW/Exclude
#
#
#
if [ ! -d $TREE ];
then
  echo ""
  echo "ERROR: Missing dir=$TREE"
  echo ""
  exit 1
fi
#
#
echo ""
echo "$NAM: Prepare the contents for the cdrom: $TREE"
echo ""
#
#
# Create a Clean CDROM image tree
# --------------------------------
rm -rf $TREE/*
#
#
# $TREE/tmp	- needs to be writable 
# $TREE/mnt	- seems to be mountable points
#
mkdir -p $TREE/proc  $TREE/opt $TREE/ramdisk
#
# Do these at ramdisk allocation time
# mkdir /ramdisk/{lock/subsys,log,run,tmp}
# chmod 1777 $TREE/ramdisk/tmp
#
#
cd /
#
#
# Copy teh required /boot info 
$TAR cf - /boot `cat $EXCLUDE/boot.lst | grep -v ^#` | ( cd $TREE ; $TAR xfp - )
#
# Now Copy /etc  - exclude /etc/ssh --> needs to be "chmod 400 ssh/*key"
$TAR cf - /etc `cat $EXCLUDE/etc.lst | grep -v ^# ` | ( cd $TREE ; $TAR xfp - )
#
#
# /usr/src/linux/Documentation/devices.txt
#	/dev/gpmctl
#	/dev/log
#
#	/dev/cdrom -->>> is it /dev/hdc  or /dev/scd0
#
#	/dev/ram -> ram1
#	/dev/ramdisk -> ram0
#
DEV1="/dev/cdrom /dev/console /dev/core /dev/fd0 /dev/fd0h1440 /dev/fd0H1440"
DEV2="/dev/hda /dev/hda? /dev/hdb /dev/hdb? /dev/hdc /dev/hdc? /dev/hdd /dev/hdd?"
DEV3="/dev/inet /dev/initctl /dev/input /dev/initrd /dev/kmem /dev/mem "
DEV4="/dev/loop? /dev/null /dev/mouse /dev/psaux /dev/input/mice /dev/pts"
DEV5="/dev/MAKEDEV /dev/ram /dev/ram? /dev/ramdisk /dev/random /dev/raw/raw? /dev/raw/raw1? /dev/rtc"
DEV6="/dev/scd? /dev/sda /dev/sg? /dev/shm /dev/std* /dev/tcp "
DEV7="/dev/tty /dev/tty? /dev/ttyS? /dev/urandom /dev/zero" 
DEV="$DEV1 $DEV2 $DEV3 $DEV4 $DEV5 $DEV6 $DEV7"
$TAR cf - $DEV| ( cd $TREE ; $TAR xfp - )
#
#
# Now copy the libs
#
$TAR cf - /lib `cat $EXCLUDE/lib.lst | grep -v ^#` | ( cd $TREE ; $TAR xfp - )
#
#
# Now copy some binaries
#
$TAR cf - /bin /sbin | ( cd $TREE ; $TAR xfp - )
#
#
#
# Now do /var  -- skip /var/lib/random-seed
$TAR cf - /var `cat $EXCLUDE/var.lst | grep -v ^#` | ( cd $TREE ; $TAR xfp - )
#
#
# Now do /usr
$TAR cf - /usr `cat $EXCLUDE/usr.lst | grep -v ^#` | ( cd $TREE ; $TAR xfp - )
#
#
# Now pick up the /usr/lib dirs we want required by the system
#
#	find /usr/share -type d -maxdepth 2 | sort 
#
UL1="/usr/lib/autofs /usr/lib/bash /usr/lib/gcc-lib /usr/lib/locale"
UL2="/usr/lib/perl5 /usr/lib/psutils /usr/lib/security /usr/lib/syslinux"
US1="/usr/share/awk /usr/share/bison /usr/share/fonts/default /usr/share/locale"
US2="/usr/share/service /usr/share/tabset /usr/share/terminfo"
$TAR cf - /usr/lib/lib* $UL1 $UL2 $US1 $US2 | ( cd $TREE ; $TAR xfp - )
#	/usr/lib/glib* is NOT in minimum setup
#
# Now pick up some of /opt
$TAR cf - /opt/Boot.* /opt/Scripts | ( cd $TREE ; $TAR xfp - )
#
#
# Directories/Files that need to be writable ( or permission issues ) when using standalone bootable cdrom
# ===========================================
#	/tmp /var/run /var/log /var/lock ...
#
#   created by
#	cdrw.MakeContents.ramdisk.RW_Patches.sh
cp -p $CDRW/cdrw.MakeContents.ramdisk.RW_Patches.tgz $TREE/ramdisk.RW_Patches.tgz
#
#
# Now do some Cleanup
# --------------------
#
find $TREE/usr/lib \( -name java -o -name javax -o -name org \) -exec rm -rf {} \;
#
#
#
# Now Apply the Changed files/patches to support standalone cdrom
# -----------------------------------
#	- new symlinks ( typically to ramdisk )
#
#   patches created by
#	cdrw.MakeContents.Patches.sh
cd $TREE ; $TAR zxfp $CDRW/cdrw.MakeContents.Patches.tgz
#
#	- to test the patches/changes
# $TAR cf - $CDRW/cdrw.MakeContents.Patches | ( cd $TREE ; $TAR xvfp - )
#
#
echo ""
echo "$NAM: Now Create an ISO image to write to the cdrw"
echo "\t http://ww.Linux-1U.net/CDRW/scripts/cdrw.MakeISO.sh"
echo ""
#
#
# End of file

