#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/dphys2cd # - build dphys2 boot CD .iso image for Debian woody (3.0) # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # author Neil Franklin, last modification 2004.10.08 ### ------ configuration for this site # first CONF_* various site or subnet dependant user config variables # then DEBUG_* various debugging settings # last SYS_* various system internal values # some of these are overridable by command line options # --- CONF_* various site or subnet dependant user config variables # base URL from which all Debian stuff can be downloaded CONF_DEBSERVER=http://ftp.debian.org/debian # are we using an 2.2 or 2.4 style kernel # if Debian kernels, this selects whether standard 2.2.20 or bf24 2.4.18 # if own kernels, this determines which Debian .config to use as base # if no own config is provided in CONF_KERNEL_CONFIG # so set this allways, if using or making an 2.4 kernel, instead of 2.2 CONF_KERNEL_24=no # use this to select an own (2.2 or 2.4) kernel source, to self compile # only needed if making own kernel CONF_KERNEL_OWN="" # base URL from which the dphys2 rescue root and drivers can be fetched # used for generating the URLs. to access our packages web server # the end result should parallel the scp login@server:/basedir above CONF_OWNSERVER=http://not-configured-server/not/configured/directory # this is the directory to use, within dists/woody/local/main/disks-i386 tree # vary this for multiple sets of rescue images and drivers archives # naming schemes maybe by subnets, or by kernel options, or by compiling user CONF_DISKSVERSION=custom # install CD drive, where our generated .iso image goes # this should be the drive on the install generating system, not on target(s) # this line contains the drive ID and whatever options the drive needs # config for no burnproof and CD-R (no blank=fast): # CONF_INST_CD=dev=0,0,0 # config for burnproof and CD-RW (blank=fast): # CONF_INST_CD="-driveropts=burnfree blank=fast dev=0,0,0" CONF_INST_CD=dev=0,0,0 # --- DEBUG_*, various debugging settings # these can be set to "yes" by -D option, followed by name without DEBUG_ # such as like this: dphys2cd -D PRINT_STEP -D LEAVE_TEMPFILES -g # set this to sleep after displaying each steps header, number is in seconds #DEBUG_SLEEP=2 # set this to output debug state info after each step #DEBUG_PRINT_STEP=yes # set this to wait after each debug state info #DEBUG_WAIT_STEP=yes # set this to not delete temporary files (workdir) after -g #DEBUG_LEAVE_TEMPFILES=yes # --- SYS_*, various system internal values # where we want to do all the cd image unpack/modify/pack stuff # this must be a directory that root can access (not a root-squash NFS mount) # and there should be about 10MByte free space in its filesystem SYS_WORKDIR=/var/tmp/dphys2cd-$$-work # note: this program has only been designed for and tested with i386 # others at own risk, I expect them to fail badly SYS_ARCH=i386 ### ------ actual implementation from here on # no user settings any more below this point # --- config file stuff # what we are NAME=dphys2cd PNAME=dphys2 # check user config file(s), let user override settings # same config files used in dphys2[rescue|root|cd|pxe] and dbootstrap if [ -f /etc/${PNAME} ] ; then . /etc/${PNAME} fi if [ -f /etc/default/${PNAME} ] ; then . /etc/default/${PNAME} fi if [ -f ~/.${PNAME} ] ; then . ~/.${PNAME} fi if [ -f ./${PNAME} ] ; then . ./${PNAME} fi # --- parse command line # so long next parameter is a set of options (= begins with an - character) while [ x`/bin/echo $1 | /usr/bin/cut -c 1` = x- ] ; do # extract options from parameter (cut off the "-") OPTS=`/bin/echo $1 | /usr/bin/cut -c 2-` shift 1 # so long still unprocessed option characters while [ x${OPTS} != x ] ; do # first option to process OPT=`/bin/echo ${OPTS} | /usr/bin/cut -c 1` # and rest of options for later OPTS=`/bin/echo ${OPTS} | /usr/bin/cut -c 2-` case ${OPT} in d) # download: download dphys2 files from server DO_DOWN=yes ;; g) # generate: generate dphys2 files DO_GEN=yes ;; w) # workdir: generate using this work directory SYS_WORKDIR=$1 shift 1 ;; i) # install: install original or dphys2 files onto CD DO_INST=yes ;; r) # remove: remove dphys2 files, after installing DO_REMOVE=yes ;; D) # Debug: set an debug option to yes eval DEBUG_$1=yes shift 1 ;; h) # help: give out help how this script can be used /bin/cat << END-HELP-TEXT Usage is: $0 [options] options: -d download: download dphys2 rescue and root image files from distribution server -g generate: generate dphys2 CD .iso image -w workdir workdir: generate using this work directory -i install: install dphys2 .iso image onto CD -r remove: remove dphys2 files, after installing -D Debug: activate an debug option -h help: give out help how this script can be used If multiple of -d -g -i -r or -i are used, they are processed in the order they appear here in the help section, not the order they are typed on the command line. Other options modify behaviour. END-HELP-TEXT exit 0 ;; *) # not one of our recognized options /bin/echo "$0: ERROR: unknown option: ${OPT}" >&2 /bin/echo # call self with -h to display help $0 -h exit 1 ;; esac done done if [ "x${DO_DOWN}${DO_GEN}$${DO_INST}${DO_REMOVE}" = x ] ; then /bin/echo "$0: WARNING: no option selected, doing nothing" >&2 fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/echo options are: DO_DOWN: ${DO_DOWN}, DO_GEN: ${DO_GEN}, \ DO_INST: ${DO_INST}, DO_REMOVE: ${DO_REMOVE} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi # --- test if we can work # this script is intended to be run as root, it will fail if run as user! if [ ! `/usr/bin/whoami` = root ] ; then /bin/echo "$0: sorry, you need to run this script as root - aborting ..." exit 1 fi # --- compute paths on disk image server # paths for Debian files we download from server DEBDISKS=dists/woody/main/disks-${SYS_ARCH}/current # for standard 2.2(.20) kernel DEBRESCUE=${DEBDISKS}/images-1.44/rescue.bin DEBROOT=${DEBDISKS}/images-1.44/root.bin DEBDRIVERS=${DEBDISKS}/drivers.tgz # for bf2.4 (2.4.18) kernel DEBRESCUE_BF24=${DEBDISKS}/images-1.44/bf2.4/rescue.bin DEBROOT_BF24=${DEBDISKS}/images-1.44/bf2.4/root.bin DEBDRIVERS_BF24=${DEBDISKS}/bf2.4/drivers.tgz # paths for dphys2 files we upload to and fetch from server OWNDISKS=dists/woody/local/main/disks-${SYS_ARCH}/${CONF_DISKSVERSION} OWNRESCUE=${OWNDISKS}/images-1.44/rescue-dphys.bin OWNROOT=${OWNDISKS}/images-1.44/root-dphys.bin OWNDRIVERS=${OWNDISKS}/drivers-dphys.tgz # --- download dphys2 or Debian rescue disk image to work on # determine the correct rescue floppy image file # used by -d and -g and others, so once here outside of -d if [ x${CONF_KERNEL_OWN} != x ] ; then RESC_URL="${CONF_OWNSERVER}/${OWNRESCUE}" elif [ x${CONF_KERNEL_24} = xyes ] ; then RESC_URL="${CONF_DEBSERVER}/${DEBRESCUE_BF24}" else RESC_URL="${CONF_DEBSERVER}/${DEBRESCUE}" fi RESC=`/usr/bin/basename ${RESC_URL}` if [ x${DO_DOWN} != x ] ; then /bin/echo "-------------------------------------" /bin/echo "*** downloading rescue disk image ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # -N so only newer is fetched, save waisting bandwidth if already here # if user wants to force download, use an make clean before # downloaded and to-upload files should end in current directory # this is also most likely where config and kernel archive will be # everything else in work directory and then deleted at the end /usr/bin/wget -N ${RESC_URL} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${RESC} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- download dphys2 or Debian root disk image to work on # this uses allways our root floppy image, because we allways want auto install # no matter whether using an custom kernel or Debian kernel ROOT_URL="${CONF_OWNSERVER}/${OWNROOT}" ROOT=`/usr/bin/basename ${ROOT_URL}` if [ x${DO_DOWN} != x ] ; then /bin/echo "-----------------------------------" /bin/echo "*** downloading root disk image ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # -N so only newer is fetched, save waisting bandwidth if already here # if user wants to force download, use an make clean before /usr/bin/wget -N ${ROOT_URL} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${ROOT} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- space to work in if [ x${DO_GEN} != x ] ; then /bin/mkdir -p ${SYS_WORKDIR} fi # --- copy rescue from 1.44 to 2.88MByte boot image if [ x${DO_GEN} != x ] ; then /bin/echo "------------------------------------------------------------" /bin/echo "*** copying rescue image to 2880kByte *** from 1440kByte ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # get pseudo disk ready for making floppy image # need 2880kByte to fit rescue and root, as ElTorito allows only 1 floppy /bin/dd if=/dev/zero of=${SYS_WORKDIR}/boot-dphys.bin bs=1024 count=2880 # format this disk image as MSDOS FAT as SYSLINUX wants it so /sbin/mkfs -t msdos ${SYS_WORKDIR}/boot-dphys.bin # open boot image BOOTFLOPPY=${SYS_WORKDIR}/bfloppy /bin/mkdir -p ${BOOTFLOPPY} /bin/mount -o loop ${SYS_WORKDIR}/boot-dphys.bin ${BOOTFLOPPY} # copy stuff from 1440k to 2880k RESCFLOPPY=${SYS_WORKDIR}/floppy /bin/mkdir -p ${RESCFLOPPY} /bin/mount -o loop ${RESC} ${RESCFLOPPY} /bin/cp -p ${RESCFLOPPY}/* ${BOOTFLOPPY} /bin/umount ${RESCFLOPPY} /bin/rm -rf ${RESCFLOPPY} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${BOOTFLOPPY} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- insert root image into boot image if [ x${DO_GEN} != x ] ; then /bin/echo "------------------------------------------------" /bin/echo "*** inserting root image into boot image *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # insert image file into boot image # use root-d.bin instead of root-dphys.bin because FAT 8.3 name limitation ROOT_IMG=root-d.bin # no -p here as chmod not permitted on MSDOS filesysters, complains /bin/cp ${ROOT} ${BOOTFLOPPY}/${ROOT_IMG} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${BOOTFLOPPY} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- update syslinux.cfg to use root image from here, not 2nd floppy if [ x${DO_GEN} != x ] ; then /bin/echo "---------------------------------------------------------------" /bin/echo "*** updating syslinux conf *** of ${BOOTFLOPPY}/${ROOT_IMG} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # edit syslinux.cfg, tell it about our initrd # use name.tmp naming instead of name.ext.1 because FAT 8.3 limit /bin/sed -e "s/noinitrd/initrd=${ROOT_IMG}/" ${BOOTFLOPPY}/syslinux.cfg \ > ${BOOTFLOPPY}/syslinux.tmp /bin/mv ${BOOTFLOPPY}/syslinux.tmp ${BOOTFLOPPY}/syslinux.cfg if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${BOOTFLOPPY} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi # close boot image /bin/umount ${BOOTFLOPPY} /bin/rm -rf ${BOOTFLOPPY} fi # --- install syslinux boot sector if [ x${DO_GEN} != x ] ; then /bin/echo "----------------------------------------------------------------" /bin/echo "*** installing syslinux *** on ${SYS_WORKDIR}/boot-dphys.bin ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi /usr/bin/syslinux ${SYS_WORKDIR}/boot-dphys.bin if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${SYS_WORKDIR} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- make the .iso image # name for new CD image # used also in other places CD_DPHYS2=cd-dphys.iso if [ x${DO_GEN} != x ] ; then /bin/echo "----------------------------------------------------------------" /bin/echo "*** making .iso image *** from ${SYS_WORKDIR}/boot-dphys.bin ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi /bin/mkdir -p ${SYS_WORKDIR}/cd-dphys /bin/mv ${SYS_WORKDIR}/boot-dphys.bin ${SYS_WORKDIR}/cd-dphys /usr/bin/mkisofs -o ${CD_DPHYS2} -b boot-dphys.bin ${SYS_WORKDIR}/cd-dphys if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${CD_DPHYS2} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- tidy up after working if [ x${DO_GEN} != x ] ; then /bin/echo "-----------------------------------" /bin/echo "*** tidying up from working *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${SYS_WORKDIR} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi # remove all temporary directories and their contents, to save space # must be after debug printout if [ x${DEBUG_LEAVE_TEMPFILES} != xyes ] ; then # but offer to leave them to investigate bugs /bin/rm -rf ${SYS_WORKDIR} fi fi # --- install .iso image onto an CD if [ x${DO_INST} != x ] ; then /bin/echo "-----------------------------------" /bin/echo "*** installing .iso image on CD ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # ${CONF_INST_CD} is install CD drive, where our generated .iso image goes # this contains the drive ID and whatever options it needs /usr/bin/cdrecord ${CONF_INST_CD} ${CD_DPHYS2} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${CD_DPHYS2} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi fi # --- remove disk and .iso images if [ x${DO_REMOVE} != x ] ; then /bin/echo "---------------------------" /bin/echo "*** removing .iso image ***" if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${RESC} ${ROOT} ${CD_DPHYS2} /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi if [ -f ${RESC} -o -f ${ROOT} -o -f ${CD_DPHYS2} ] ; then /bin/rm -rf ${RESC} ${ROOT} ${CD_DPHYS2} fi fi