#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/dphys2pxe # - extract dphys2 PXE/TFTP boot server files 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 directory for PXE, where our generated files go # we install via ssh/scp, as this is most likely available on boot servers # so this line needs to be format for an scp login@server:/basedir CONF_INST_PXE=not-configured-user@not-configured-server:/not/configured # make sure multiple users (group of them) can install files on boot server # if this is set, chgrp files to this group and chmod g+w CONF_INST_GROUP="" # --- DEBUG_*, various debugging settings # these can be set to "yes" by -D option, followed by name without DEBUG_ # such as like this: dphys2pxe -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 # set this to leave temporary directories undeleted after -i #DEBUG_LEAVE_TEMPDIRS=yes # --- SYS_*, various system internal values # where we want to do all the PXE/TFTP boot server image unpack 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/dphys2pxe-$$-work # where we want to put together stuff for install # not ./install as this may collide with something user already has SYS_INSTALLDIR=/var/tmp/dphys2pxe-$$-install # 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=dphys2pxe 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 boot server 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 PXE boot server files -w workdir workdir: generate using this work directory -i install: install dphys2 files onto boot server -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 # fetch correct rescue floppy image file from the net 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 /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 to 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 # --- extract kernel from rescue floppy image # name for extracted kernel # used also in other places KERNEL=linux.bin if [ x${DO_GEN} != x ] ; then /bin/echo "------------------------------------------------" /bin/echo "*** extracting kernel *** from rescue floppy ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # open rescue floppy image RESCFLOPPY=${SYS_WORKDIR}/floppy /bin/mkdir -p ${RESCFLOPPY} /bin/mount -o loop ${RESC} ${RESCFLOPPY} /bin/cp -p ${RESCFLOPPY}/linux.bin ${KERNEL} /bin/umount ${RESCFLOPPY} /bin/rm -rf ${RESCFLOPPY} if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${KERNEL} /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 PXE files onto an boot server if [ x${DO_INST} != x ] ; then /bin/echo "---------------------------------------------" /bin/echo "*** installing PXE files onto boot server ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # put together stuff to install, needs an temp dir /bin/mkdir -p ${SYS_INSTALLDIR} if [ -f ${ROOT} -a -f ${KERNEL} ] ; then /bin/cp -p ${ROOT} ${KERNEL} ${SYS_INSTALLDIR} if [ x${CONF_INST_GROUP} != x ] ; then /bin/chgrp ${CONF_INST_GROUP} ${SYS_INSTALLDIR}/* /bin/chmod 664 ${SYS_INSTALLDIR}/* fi fi # ${CONF_INST_PXE} is install directory for PXE, where our generated files go # this line needs to be the first part for an scp login@server:/basedir # if user has given us somewhere to install to, else boot server gets screwed if [ x${CONF_INST_PXE} != x ] ; then /usr/bin/scp -p ${SYS_INSTALLDIR}/* ${CONF_INST_PXE} else /bin/echo "$0: ERROR: no server to install PXE boot files on" >&2 exit 1 fi if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -alR ${SYS_INSTALLDIR}/* /bin/echo "--- end info ---" fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then read -p "--- DEBUG: wait after step ---" dummy fi # remove temporary directory and its contents, to save space # must be after debug printout if [ x${DEBUG_LEAVE_TEMPDIRS} != xyes ] ; then # but offer to leave this to investigate bugs /bin/rm -rf ${SYS_INSTALLDIR} fi fi # --- remove PXE boot files if [ x${DO_REMOVE} != x ] ; then /bin/echo "--------------------------" /bin/echo "*** removing PXE files ***" if [ x${DEBUG_PRINT_STEP} = xyes ] ; then /bin/echo "--- DEBUG: info ---" /bin/ls -al ${RESC} ${ROOT} ${KERNEL} /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 ${KERNEL} ] ; then /bin/rm -rf ${RESC} ${ROOT} ${KERNEL} fi fi