#!/bin/sh # http://www.phys.ethz.ch/~franklin/Projects/dphys2/makerescue # - build our replacement rescue floppy image for Debian woody (3.0) # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license # author Neil Franklin, last modification 2004.02.13 # this script is intended to be run as root, it will fail if run as user! # ------ read in setup # this is shared by Makefile, makerescue, makeroot, dbootstrap . ./setup-dphys2 # ------ from here on code to do the actual actions # --- test if we can work if [ ! `/usr/bin/whoami` = root ] ; then /bin/echo "sorry, you need to run this script as root - aborting ..." exit 1 fi # --- place to work on rescue /bin/mkdir -p ${SYS_RESCWORK} # --- fetch rescue disk image to work on /bin/echo "-------------------------------------" /bin/echo "*** downloading rescue disk image ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # fetch correct rescue floppy image file from the net if [ x${CONF_KERNEL_24} = xyes ] ; then RESC="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBRESCUE_BF24}" else RESC="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBRESCUE}" 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 -P ${SYS_RESCWORK} ${RESC} # --- no own kernel, no need to compile, only above download for floppy install if [ x${CONF_KERNEL_OWN} = x ] ; then /bin/echo "-----------------------------------------------" /bin/echo "*** using standard Debian rescue floppy *** ..." /bin/echo "no own kernel, not making own rescue image or drivers archive" # thats it for standard rescue, rest is all for making making own rescue exit 0 fi # --- fetch drivers archive to work on /bin/echo "---------------------------------------" /bin/echo "*** downloading drivers tar archive ***" if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # fetch the correct full drivers archive from the net if [ x${CONF_KERNEL_24} = xyes ] ; then DRV="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBDRIVERS_BF24}" else DRV="http://${CONF_DEBSERVER}/${CONF_DEBDIR}/${SYS_DEBDRIVERS}" 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 -P ${SYS_RESCWORK} ${DRV} # --- unpack users kernel /bin/echo "----------------------------------------------------" /bin/echo "*** unpacking kernel *** from ${CONF_KERNEL_OWN} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # remove any existing kernel, to avoid mess on overwriting # directory may be linux for < 2.4 or linux- for >= 2.4 if [ -d ${SYS_RESCWORK}/linux* ] ; then /bin/rm -rf ${SYS_RESCWORK}/linux* fi if [ ! -f ${CONF_KERNEL_OWN} ] ; then /bin/echo "kernel archive ${CONF_KERNEL_OWN} not found" exit 1 fi # allow either .tar.bz or .tar.gz archives if [ x`/bin/echo ${CONF_KERNEL_OWN} | /bin/grep '\.tar\.bz2$'` != x ] ; then /bin/tar -jxpf ${CONF_KERNEL_OWN} -C ${SYS_RESCWORK} elif [ x`/bin/echo ${CONF_KERNEL_OWN} | /bin/grep '\.tar\.gz$'` != x ] ; then /bin/tar -zxpf ${CONF_KERNEL_OWN} -C ${SYS_RESCWORK} else /bin/echo "kernel archive ${CONF_KERNEL_OWN} is not a .tar.bz or .tar.gz" exit 1 fi if [ -d ${SYS_RESCWORK}/linux* ] ; then # not LINUX=${SYS_RESCWORK}/linux* as then cp -p ${LINUX}/.config # becomes cp -p ${SYS_RESCWORK}/linux*/.config and does not expand LINUX=`/bin/echo ${SYS_RESCWORK}/linux*` else /bin/echo "kernel archive ${CONF_KERNEL_OWN} did not unpack, aborting ..." exit 1 fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -ald ${LINUX} read dummy fi # --- extract Debians .config file to kernel directory # no .config file given so extract one from Debian rescue disk if [ x${CONF_KERNEL_CONFIG} != x ] ; then /bin/echo "---------------------------------------------------------" /bin/echo "*** copying in .config *** from ${CONF_KERNEL_CONFIG} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi if [ ! -f ${CONF_KERNEL_CONFIG} ] ; then /bin/echo "kernel archive ${CONF_KERNEL_CONFIG} not found" exit 1 fi /bin/cp -p ${CONF_KERNEL_CONFIG} ${LINUX}/.config else /bin/echo "------------------------------------------------------" /bin/echo "*** extracting .config *** from Debian rescue disk ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # get rescue file system from floppy image RESCFLOPPY=${SYS_RESCWORK}/floppy /bin/mkdir -p ${RESCFLOPPY} /bin/mount -o loop ${SYS_RESCWORK}/`/usr/bin/basename ${RESC}` ${RESCFLOPPY} /bin/gunzip -c ${RESCFLOPPY}/config.gz > ${LINUX}/.config /bin/umount ${RESCFLOPPY} /bin/rm -rf ${RESCFLOPPY} fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${LINUX}/.config read dummy fi # --- make oldconfig /bin/echo "----------------------------------------" /bin/echo "*** making oldconfig *** in ${LINUX} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi /bin/echo /bin/echo "*** --- oldconfig... --- ***" /bin/echo "(if you are using an debian .config this may ask you questions)" /bin/echo (cd ${LINUX}; /usr/bin/make oldconfig) if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${LINUX}/.config read dummy fi # --- build the kernel, make dep bzImage modules /bin/echo "-------------------------------------------" /bin/echo "*** building the kernel *** in ${LINUX} ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi /bin/echo /bin/echo "*** --- dep... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make dep) /bin/echo /bin/echo "*** --- bzImage... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make -j 4 bzImage) /bin/echo /bin/echo "*** --- modules... --- ***" /bin/echo (cd ${LINUX}; /usr/bin/make -j 4 modules) if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${LINUX}/vmlinux ${LINUX}/arch/${SYS_ARCH}/boot/bzImage \ ${LINUX}/System.map ${LINUX}/.config read dummy fi # --- install stuff into own rescue floppy image /bin/echo "-----------------------------------------------" /bin/echo "*** packing kernel *** into own rescue disk ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # make an copy of Debians disk (for Syslinux and help) to pack stuff into /bin/cp -p ${SYS_RESCWORK}/`/usr/bin/basename ${RESC}` \ ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNRESCUE}` # put our kernel stuff onto it RESCFLOPPY=${SYS_RESCWORK}/floppy /bin/mkdir -p ${RESCFLOPPY} /bin/mount -o loop ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNRESCUE}` \ ${RESCFLOPPY} /bin/cp -p ${LINUX}/arch/${SYS_ARCH}/boot/bzImage ${RESCFLOPPY}/linux.bin /bin/gzip -c ${LINUX}/System.map > ${RESCFLOPPY}/sys_map.gz /bin/gzip -c ${LINUX}/.config > ${RESCFLOPPY}/config.gz # announce what rescue disk the user has inserted, for checking if right one KERNVERS=`echo ${CONF_KERNEL_OWN} | cut -f 2 -d "-" | cut -f1-3 -d "."` /bin/sed -e "/^This disk uses/s/2.*$/${KERNVERS}/" \ ${RESCFLOPPY}/debian.txt > ${RESCFLOPPY}/debian.tmp /bin/mv ${RESCFLOPPY}/debian.tmp ${RESCFLOPPY}/debian.txt /bin/umount ${RESCFLOPPY} /bin/rm -rf ${RESCFLOPPY} # writing onto loop mounted file does not seem to update its access time /bin/touch ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNRESCUE}` if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNRESCUE}` read dummy fi # --- make own drivers archive /bin/echo "----------------------------------------------------" /bin/echo "*** packing modules *** into own drivers archive ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # create our /lib/modules//* stuff /bin/rm -rf ${SYS_RESCWORK}/modules /bin/mkdir -p ${SYS_RESCWORK}/modules (cd ${LINUX}; INSTALL_MOD_PATH=`/bin/pwd`/../modules make modules_install) # unpack drivers archive to insert our modules /bin/rm -rf ${SYS_RESCWORK}/drivers /bin/mkdir -p ${SYS_RESCWORK}/drivers /bin/tar zxpf ${SYS_RESCWORK}/`/usr/bin/basename ${DRV}` \ -C ${SYS_RESCWORK}/drivers # insert our modules /bin/tar zcf ${SYS_RESCWORK}/drivers/modules.tgz -C ${SYS_RESCWORK}/modules . # and repack drivers to our drivers archive after inserting our modules /bin/tar zcf ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNDRIVERS}` \ -C ${SYS_RESCWORK}/drivers . if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${SYS_RESCWORK}/drivers \ ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNDRIVERS}` read dummy fi # --- upload own rescue floppy image and drivers archive /bin/echo "------------------------------------------------------------" /bin/echo "*** uploading rescue floppy image and drivers archive *** to" \ "`dirname ${CONF_UPLOAD_NFSBASE}/${SYS_OWNDRIVERS}` ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # upload sources, including ensure that directories for them exist if [ ! -d `dirname ${CONF_UPLOAD_NFSBASE}/${SYS_OWNRESCUE}` ] ; then /bin/su ${CONF_UPLOAD_USER} -c "/bin/mkdir -p \ `dirname ${CONF_UPLOAD_NFSBASE}/${SYS_OWNRESCUE}`" fi if [ ! -d `dirname ${CONF_UPLOAD_NFSBASE}/${SYS_OWNDRIVERS}` ] ; then /bin/su ${CONF_UPLOAD_USER} -c "/bin/mkdir -p \ `dirname ${CONF_UPLOAD_NFSBASE}/${SYS_OWNDRIVERS}`" fi /bin/su ${CONF_UPLOAD_USER} -c "/bin/cp -p \ ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNRESCUE}` \ ${CONF_UPLOAD_NFSBASE}/${SYS_OWNRESCUE}" /bin/su ${CONF_UPLOAD_USER} -c "/bin/cp -p \ ${SYS_RESCWORK}/`/usr/bin/basename ${SYS_OWNDRIVERS}` \ ${CONF_UPLOAD_NFSBASE}/${SYS_OWNDRIVERS}" if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/ls -al ${CONF_UPLOAD_NFSBASE}/${SYS_OWNRESCUE} \ ${CONF_UPLOAD_NFSBASE}/${SYS_OWNDRIVERS} read dummy fi # --- tidy up after working /bin/echo "-----------------------------------" /bin/echo "*** tidying up from working *** ..." if [ x${DEBUG_SLEEP} != x ] ; then /bin/sleep ${DEBUG_SLEEP} fi # remove all root owned directories, so user can clean up without being root if [ x${DEBUG_LEAVE_UNPACKED} != xyes ] ; then # but offer to leave them to investigate bugs /bin/rm -rf ${SYS_RESCWORK}/drivers /bin/rm -rf ${SYS_RESCWORK}/modules /bin/rm -rf ${LINUX} fi if [ x${DEBUG_WAIT_STEP} = xyes ] ; then /bin/echo "--- debug info ---" /bin/ls -al ${SYS_RESCWORK} read dummy fi