
#!/bin/sh
# Linux-Mandrake ISO CD Creation Script (thanks to Kenny Graunke for this one!)
# Fixes and modifications to handle using a preexisting mirror (without
#      messing up that mirror) added by Guy T. Rice
# Fixes and modifications to handle burning the main CD automatically plus adding
#      most of the commentaries below  --  by Daniel Hammer (dhammer@cybercable.fr)
#
#	20000904 warly <warly@mandrakesoft.com>: support for last rpmtools tools 
#
# Before You Start: 
#   o  Check all variables and insert a CD-R/RW into you CD-writer
#   o  In most settings you must run this script as "root"
#   o  It makes sense to get rid of lots of useless files which you
#      get during the download but which you don't need for the CD's
#      - these are for example lots of ".listing" files and some forgotten
#      junk-files like "locale.dir~", etc.
#      Cleaning them off is easily made by the following (perhaps not most
#      elegant) procedure:
#        * change into the appropriate directory of your mirror
#        * type "find . -name .listing > rmdotlisting&&chmod +x rmdotlisting"
#        * using "sed" or just by eding the rmdotlisting file replace "./"
#          at the beginning of each line by "rm "
#        * then run "rmdotlisting" by typing "./rmdotlisting"
#  
#   o check if you don't have any two versions of any package in the RPMS/RPMS2
#     directories; this can happen if you use "wget -rm" since you get all newer
#     versions of the packages and the outdated ones remain in your mirror 
#     directory 
#     Example: you've already downloaded certainpackage-1.2.3mdk.rpm and when 
#              updating you get the newer certainpackage-1.2.5mdk.rpm now you'll 
#              have both packages in the RPMS directory of your local mirror & when 
#              later creating deplists this produces "depslist.ordered does not match ..."
#  
# Preferably run this script by typing: "sh isomake.sh 2>&1 | tee -a ~/.isomake.log"
#    since if you get any errors you'll have a log-file to check what went wrong


# You MUST change these variables for your particular configuration:

shopt -s extglob

# Set this to the location of where you want to download Linux-Mandrake to.
mdkLOCALROOT=/image
# Set these to the location where you want your ISO images to be created.
mdkISO1DIR=/tmp/
#mdkISO2DIR=/tmp/mdkiso2
# Set this to 1 to download Linux-Mandrake.
#mdkMIRROR=0
# Set these to your FTP mirror and directory, respectively:
#mdkFTPSITE=sunsite.uio.no
#mdkFTPDIR=/pub/unix/Linux/Mandrake-devel/cooker
# Set this to a non-empty string to copy an already existing local mirror
#mdkPREEXISTING=/mnt/z-olinux/sunsite.uio.no/pub/unix/Linux/Mandrake-devel/cooker

# put the image in a separate dir to be sure the CD will boot everywhere
#mkdir -p $mdkLOCALROOT/images
#mv $mdkLOCALROOT/cd1/images $mdkLOCALROOT/images

# change to directory of main CD
cd $mdkLOCALROOT/

# the utilities in misc don't work unless they're in the PATH
export PATH=$mdkLOCALROOT/misc:$PATH

# generate the dependance files

rm -f $mdkLOCALROOT/Mandrake/base/{hdlists,hdlist.cz2}
./misc/genhdlist_cz2 -o $mdkLOCALROOT/Mandrake/base/hdlist1.cz $mdkLOCALROOT/Mandrake/RPMS
echo "hdlist1.cz     Mandrake/RPMS  CD1 Installation CD" > $mdkLOCALROOT/Mandrake/base/hdlists

#rm -f $mdkLOCALROOT/Mandrake/base/hdlist2.cz2
#./misc/genhdlist_cz2 -o $mdkLOCALROOT/cd1/Mandrake/base/hdlist2.cz $mdkLOCALROOT/cd2/Mandrake/RPMS2
#echo "hdlist2.cz     Mandrake/RPMS2  CD2 Extension CD" >> $mdkLOCALROOT/cd1/Mandrake/base/hdlists

rm -f $mdkLOCALROOT/Mandrake/base/{depslist,deplist.ordered,filelist}
./misc/genbasefiles $mdkLOCALROOT/Mandrake/base/ $mdkLOCALROOT/Mandrake/base/hdlist1.cz $mdkLOCALROOT/Mandrake/base/hdlist2.cz
./usr/bin/genfilelist $mdkLOCALROOT/Mandrake/RPMS > $mdkLOCALROOT/Mandrake/base/filelist

# order the hdlist with the depslist to get faster accesses
./misc/genhdlist_cz2 --noclean --ordered-depslist Mandrake/base/depslist.ordered \
	-o Mandrake/base/hdlist1.cz $mdkLOCALROOT/Mandrake/RPMS
#./misc/genhdlist_cz2 --noclean --ordered-depslist Mandrake/base/depslist.ordered \      
#	-o Mandrake/base/hdlist2.cz $mdkLOCALROOT/cd2/Mandrake/RPMS2

# create the first iso image (Main Installation CD)
#mkisofs -J -r \
#  -o $mdkISO1DIR/Cooker-CD1.iso \
#  -b images/all.img \
#  -c images/boot.cat \
#  $mdkLOCALROOT/images \
#  $mdkLOCALROOT/cd1

# create the second iso image (Extensions CD)
#mkisofs -J -r \
#  -o $mdkISO2DIR/Cooker-CD2.iso \
#  $mdkLOCALROOT/cd2

# burn the main CD 
# the values for cd-writer speed and the scsi-bus target/lun must be set
# according to your local settings
#cd $mdkISO1DIR
#cdrecord -eject -v -data speed=4 dev=4,0 Cooker-CD1.iso

# the first CD comes out the CD-writer and the script comes out at the
# place where your second image file is - ready to perform 
# 'cdrecor
#cd $mdkISO2DIR
#cdrecord -eject -v -data speed=4 dev=4,0 Cooker-CD2.iso
