#!/bin/sh # /usr/bin/dphys3preseed - # - build dphys3 replacement floppy images w preseed for Debian 3.1 (sarge) # author Neil Franklin, last modification 2006.11.16 # copyright ETH Zuerich Physics Departement, # use under either BSD or GPL license ### ------ 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 # where we put all the stuff needed for compiling CONF_SOURCEDIR=. # upload server for compiled floppy images, where our image files go # the -u option uploads everything relative to this # /dir is the base directory for adding dists/.../*.deb and pool/.../*.deb # paralleling Debians use [dist|spool]/.../*.deb on their servers # and so should appear in the http:// space of our own install server # we upload via ssh/scp, as this is most likely available on boot servers # so this line needs to be in user@server:/directory format for scp CONF_UPLOAD_SERVER=not-configured-user@server:/dir # make sure multiple users (group of them) can install files on package server # if this is set, chgrp directories and files to this group and chmod g+w CONF_UPLOAD_GROUP="" # this is the directory to use, within the dists/.../disks-i386 directory # vary this for multiple sets of files (say multiple kernels or configs) # naming schemes maybe by subnets, or by kernel options, or by compiling user CONF_DISKSVERSION=dphys3-custom # base URL from which our generated stuff can be downloaded # 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 # what net drivers we want included in our install root floppy # net is needed to install from, to load files from # this can be left empty if needed drivers are compiled into kernel CONF_MODULESNET="" # prevent unnecessary questions while installing packages # install everything with maintainers defaults, then fix up with own scripts CONF_SILENCE_DEBCONF=yes # what keyboard layout you use, just name without path or .kmap.gz ending CONF_KEYBD=us # force use of this network interface, set it to eth0 eth1 etc # this defaults to auto which uses the first usable one # but sometimes the kernel choses an broken but existing driver CONF_IF=auto # amount of disk to use for the swap partition, if wanted, in MBytes # set to 0 or "", will make no partition and disable its use # this defaults to off, because we use swap files around here # as they are more flexible, auto-resizable, and not relevantly slower # to autogenerate/mount/umount swapfiles install the dphys-swapfile package: # http://www.phys.ethz.ch/~franklin/Projects/dphys-swapfile/ CONF_SWAP_SIZE=0 # what time zone we have here, local time settings CONF_TIMEZONE_AREA=not-configured-area CONF_TIMEZONE_PLACE=not-configured-place # set root password, this may be only temporary, overwrite later CONF_PASSWORD_ROOT="" # apt config what stuff we use, this is just minimal stuff, extend later CONF_USE_NON_FREE=no CONF_USE_CONTRIB=no CONF_USE_SECURITY=no # automagically run this script (or binary) at end of "zeroth" install stage # to run script while generating root disk, use filename like this: # CONF_END0STAGE=end0stage # *** this script will be run as root at end of "zeroth" install stage *** # / is root of the *installation* system, as we are making root floppy! # we use this to modify root disk so that we can reinstall without data loss # it prevents repartitioning and reformatting, instead deleting old system CONF_END0STAGE="" # automagically run this script (or binary) at end of first install stage # to include script on image, use filename like this: # CONF_END1STAGE=end1stage # to download script at install time, use URL like this: # CONF_END1STAGE=http://our-admin-server/install-stuff/end1stage # *** this script will be run as root at end of first install stage *** # / is root of the *install* system, as we are still before reboot! # we use this to install our custom production kernels before the reboot # to prevent having to make debian installer compatible loading stuff CONF_END1STAGE="" # automagically run this script (or binary) at end of second install stage # use with script filename like this: CONF_END2STAGE=end2stage # *** this script will be run as root at end of second install stage *** # / is root of the final system, as we are just short before login prompt # we use this to install our automatic package installer/updater/remover: # http://www.phys.ethz.ch/~franklin/Projects/dphys-admin/ CONF_END2STAGE="" # --- DEBUG_*, various debugging settings # these can be set to "yes" by -D option, followed by name without DEBUG_ # such as like this: dphys3preseed -D PRINT_STEP -D LEAVE_TEMPFILES -g # set this to sleep after displaying each steps header #DEBUG_SLEEP=yes # 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 have old initrd backupped #DEBUG_BACKUP_INITRD=yes # set this to have an copy of the generated preseed file in current directory #DEBUG_DUMP_PRESEED=yes # set this to not delete end0stage script from install disk after running it #DEBUG_LEAVE_END0STAGE=yes # set this to not delete temporary files (workdir) after -g #DEBUG_LEAVE_TEMPFILES=yes # set this to leave temporary directories undeleted after -u #DEBUG_LEAVE_TEMPDIRS=yes # --- SYS_*, various system internal values # where we want to do all the unpack/modify/pack stuff # this must be a directory that root can access (not a root-squash NFS mount) # and there should be about 50MByte free space in its filesystem SYS_WORKDIR="/var/tmp/dphys3preseed-$$-work" # where we want to put together stuff for upload # not ./upload as this may collide with something user already has SYS_UPLOADDIR="/var/tmp/dphys3preseed-$$-upload" # 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 # version of the kernel on Debian [boot|root|net-drivers].img floppies # used for extracting additional drivers from .udeb on net-drivers.img # will need replacing by the correct one for custom kernels SYS_KERN_VERSION=2.4.27-2-386 ### ------ actual implementation from here on # no user settings any more below this point set -e # --- get ready to work # sanitise this place, else some commands may fail # must be before any commands are executed, incl config/input processing PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # --- tidy up some commands, make systematic, common infrastructure # stuff that goes wrong, not expected by user, not in data output, use >&2 # so also with $0 in case this script was called by an other script # something within the system that user does not expect, give up CMD_FATAL="echo $0: FATAL:" # something from users input, user will correct this and continue CMD_ERROR="echo $0: ERROR:" # something we can continue with, but may be wrong, and user may not suspect it CMD_WARNING="echo $0: WARNING:" # something most likely not wrong, but tell user for the odd case it is wrong CMD_NOTE="echo $0: NOTE:" # normal stuff users expect, so to stdout as normal output, no $0, no marking CMD_INFO="echo" # stuff users asked for, so add to stdout as normal output, no $0, but mark it CMD_DEBUG="echo DEBUG:" # other stuff we may want to use CMD_SLEEP="sleep 2" CMD_WAIT="read -p ---DEBUG-wait-after-step--- dummy" # DEBUG_* or option controllable stuff CMD_INFO_PRINT="${CMD_INFO}" CMD_VERBOSE_PRINT=true CMD_DEBUG_SLEEP=true CMD_DEBUG_PRINT=true CMD_DEBUG_WAIT=true # set debug option controllable stuff here if [ "${DEBUG_SLEEP}" = yes ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "${DEBUG_PRINT_STEP}" = yes ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "${DEBUG_WAIT_STEP}" = yes ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi # --- config file stuff # what we are NAME=dphys3preseed PNAME=dphys3 # check user config file(s), let user override settings # same config files used in dphys3[kernel|preseed|boot|root|cd|pxe] if [ -f /etc/"${PNAME}" ] ; then . /etc/"${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 [ "`echo "$1" | cut -c 1`" = - ] ; do # extract options from parameter (cut off the "-") OPTS="`echo "$1" | cut -c 2-`" shift 1 # so long still unprocessed option characters while [ "${OPTS}" != "" ] ; do # first option to process OPT="`echo "${OPTS}" | cut -c 1`" # and rest of options for later OPTS="`echo "${OPTS}" | cut -c 2-`" case "${OPT}" in d) # download: download orignal Debian files from distribution server DO_DOWN=yes COMMAND_OPTION=yes ;; g) # generate: generate our own files DO_GEN=yes COMMAND_OPTION=yes ;; s) # sourcedir: find all files to use in this subdirectory CONF_SOURCEDIR="$1" shift 1 ;; k) # kernel: use this kernel archive, only as "use own images" flag KERNEL="$1" shift 1 ;; c) # config: use this config file, only as "use own images" flag CONFIG="$1" shift 1 ;; u) # upload: upload generated files to local install server DO_UPLOAD=yes COMMAND_OPTION=yes ;; r) # remove: remove Debian and own files, after installing DO_REMOVE=yes COMMAND_OPTION=yes ;; q) # quiet: don't inform user what we are doing CMD_INFO_PRINT=true ;; v) # verbose: detailed inform user what we are doing CMD_VERBOSE_PRINT="${CMD_INFO}" ;; D) # Debug: set an debug option to yes eval "DEBUG_$1"=yes if [ "DEBUG_$1" = DEBUG_SLEEP ] ; then CMD_DEBUG_SLEEP="${CMD_SLEEP}" fi if [ "DEBUG_$1" = DEBUG_PRINT_STEP ] ; then CMD_DEBUG_PRINT="${CMD_DEBUG}" fi if [ "DEBUG_$1" = DEBUG_WAIT_STEP ] ; then CMD_DEBUG_WAIT="${CMD_WAIT}" fi shift 1 ;; h) # help: give out help how this script can be used cat << END-HELP-TEXT Usage is: $0 command [option]... [command [option]... ]... command/function/action letters: one or multiple of the following commands must be used, default nothing done if multiple of these are used, they are processed in the row they appear here, not the row they are typed on the command line -d download: download orignal Debian files from distribution server -g generate: generate our own files -u upload: upload generated files to local install server for usage by -f before install -r remove: remove Debian and own files, after installing options: [only for -g generate] -s sourcedir sourcedir: use kernel/config from here -k kernel kernel: use this kernel archive, only as "own images" flag -c config config: use this config file, only as "own images" flag [for all commands] -q quiet: don't give user an running report of what we are doing -v verbose: give user detailed running report -D Debug: activate an debug option -h help: give out help how this script can be used END-HELP-TEXT exit 0 ;; *) # not one of our recognized options ${CMD_ERROR} "unknown option: ${OPT}" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h exit 1 ;; esac done done if [ "${COMMAND_OPTION}" = "" ] ; then ${CMD_ERROR} "no command option selected, will not do anything" >&2 ${CMD_INFO} >&2 # call self with -h to display help "$0" -h >&2 exit 1 fi ${CMD_DEBUG_PRINT} "options are:" \ "DO_DOWN: ${DO_DOWN}, DO_GEN: ${DO_GEN}," \ "DO_UPLOAD: ${DO_UPLOAD}, DO_REMOVE: ${DO_REMOVE}" ${CMD_DEBUG_WAIT} # --- test if we can work # this script is intended to be run as root, it will fail if run as user! if [ ! "`whoami`" = root ] ; then ${CMD_ERROR} "sorry, you need to run this as root, aborting ..." >&2 exit 1 fi # --- compute paths on disk image server # path for Debian directory we download from server DEBINST="dists/sarge/main/installer-${SYS_ARCH}/current" # path for our directory we upload to and download from server OWNINST="dists/sarge/local/main/installer-${SYS_ARCH}/${CONF_DISKSVERSION}" # actual files inside all of these BOOTIMG=images/floppy/boot.img ROOTIMG=images/floppy/root.img DRIVIMG=images/floppy/net-drivers.img # --- determine if own or Debian disk images are to be used if [ "${DO_DOWN}" != "" ] ; then ${CMD_VERBOSE_PRINT} "checking for own dphys3kernel floppy images ..." ${CMD_DEBUG_SLEEP} # kernel or config are present, assume user made own ones # same code as in dphys3kernel, see there for explanations if [ "${KERNEL}" = "" ] ; then KERNEL="`ls -1U "${CONF_SOURCEDIR}"/linux-*.tar.bz2 2> /dev/null | \ rev | cut -f 3- -d '.' | rev | sort | tail -n 1`.tar.bz2" fi if [ "${KERNEL}" = ".tar.bz2" ] ; then # only an empty ending, no .tar.bz2 archive, retry for .tar.gz archive KERNEL="`ls -1U "${CONF_SOURCEDIR}"/linux-*.tar.gz 2> /dev/null | \ rev | cut -f 3- -d '.' | rev | sort | tail -n 1`.tar.gz" fi if [ "${KERNEL}" != ".tar.gz" ] ; then OWN_KERNEL=yes fi if [ "${CONFIG}" = "" ] ; then CONFIG="`ls -1 "${CONF_SOURCEDIR}"/config* 2> /dev/null | tail -n 1`" fi if [ "${CONFIG}" = "" ] ; then CONFIG="`ls -1 "${CONF_SOURCEDIR}"/.config* 2> /dev/null | tail -n 1`" fi if [ "${CONFIG}" != "" ] ; then OWN_KERNEL=yes fi if [ "${OWN_KERNEL}" != "" ] ; then ${CMD_VERBOSE_PRINT} " found an kernel archive or config file, using own" fi ${CMD_DEBUG_PRINT} "`ls -al "${KERNEL}" 2> /dev/null`" ${CMD_DEBUG_PRINT} "`ls -al "${CONFIG}" 2> /dev/null`" ${CMD_DEBUG_WAIT} fi # --- download own or Debian boot disk image to work on # determine the correct boot floppy image file # variable used by -d and -g and others, so once here outside of -d if [ "${OWN_KERNEL}" != "" ] ; then # fetch images generated by dphys3kernel, if user made some BOOT_URL="${CONF_OWNSERVER}/${OWNINST}/${BOOTIMG}" else BOOT_URL="${CONF_DEBSERVER}/${DEBINST}/${BOOTIMG}" fi # in current dir, not workdir, as user wants to see this file BOOT="`basename "${BOOT_URL}"`" if [ "${DO_DOWN}" != "" ] ; then ${CMD_INFO_PRINT} "downloading boot disk image ..." ${CMD_DEBUG_SLEEP} # check if we can download if ! which wget > /dev/null ; then ${CMD_FATAL} "failed to find wget, can not download, aborting ..." >&2 ${CMD_LOG_FATAL} "failed to find wget, can not download, aborting ..." exit 1 fi # -N so only newer is got, 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 wget -q -N "${BOOT_URL}" -O "${BOOT}" ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}"`" ${CMD_DEBUG_WAIT} fi # --- download own or Debian root disk image to work on # determine the correct root floppy image file if [ "${OWN_KERNEL}" != "" ] ; then ROOT_URL="${CONF_OWNSERVER}/${OWNINST}/${ROOTIMG}" else ROOT_URL="${CONF_DEBSERVER}/${DEBINST}/${ROOTIMG}" fi ROOT="`basename "${ROOT_URL}"`" if [ "${DO_DOWN}" != "" ] ; then ${CMD_INFO_PRINT} "downloading root disk image ..." ${CMD_DEBUG_SLEEP} # -N so only newer is got, save waisting bandwidth if already here # if user wants to force download, use an make clean before wget -q -N "${ROOT_URL}" -O "${ROOT}" ${CMD_DEBUG_PRINT} "`ls -al "${ROOT}"`" ${CMD_DEBUG_WAIT} fi # --- download Debian drivers disk image to work on # there is never an dphys3kernel generated drivers image, only if using Debians if [ "${OWN_KERNEL}" = "" ] ; then # determine the correct full drivers archive DRV_URL="${CONF_DEBSERVER}/${DEBINST}/${DRIVIMG}" DRV="`basename "${DRV_URL}"`" if [ "${DO_DOWN}" != "" ] ; then ${CMD_INFO_PRINT} "downloading drivers disk image ..." ${CMD_DEBUG_SLEEP} # -N so only newer is got, save waisting bandwidth if already here # if user wants to force download, use an make clean before wget -q -N "${DRV_URL}" -O "${DRV}" ${CMD_DEBUG_PRINT} "`ls -al "${DRV}"`" ${CMD_DEBUG_WAIT} fi fi # --- space to work in if [ "${DO_GEN}" != "" ] ; then mkdir -p "${SYS_WORKDIR}" fi # --- set syslinux timeout and eliminate ram disk size limit on boot floppy if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "modifying syslinux on boot disk ..." ${CMD_DEBUG_SLEEP} # mount boot file system from floppy image BOOTFLOPPY="${SYS_WORKDIR}/boot" mkdir -p "${BOOTFLOPPY}" mount -o loop "${BOOT}" "${BOOTFLOPPY}" # set timeout to autostart after 1/10sec, as we don't need prompt # don't do this with ${BOOTFLOPPY}/syslinux.cfg.tmp, may run out of space sed -e '/timeout/s/0/10/' "${BOOTFLOPPY}/syslinux.cfg" > \ "${SYS_WORKDIR}/syslinux.cfg.tmp" mv "${SYS_WORKDIR}/syslinux.cfg.tmp" "${BOOTFLOPPY}/syslinux.cfg" # eliminate ram disk size limit # else CD boot2.88 with larger root initrd crashes sed -e '/append/s/ramdisk_size=[0-9]* //' \ "${BOOTFLOPPY}/syslinux.cfg" > "${SYS_WORKDIR}/syslinux.cfg.tmp" mv "${SYS_WORKDIR}/syslinux.cfg.tmp" "${BOOTFLOPPY}/syslinux.cfg" ${CMD_DEBUG_PRINT} "+++ begin syslinux.cfg +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then cat "${BOOTFLOPPY}/syslinux.cfg" fi ${CMD_DEBUG_PRINT} "+++ end syslinux.cfg +++" ${CMD_DEBUG_WAIT} # before closing, to see inside floppy ${CMD_DEBUG_PRINT} "+++ begin bootfloppy listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${BOOTFLOPPY}" fi ${CMD_DEBUG_PRINT} "+++ end bootfloppy listing +++" ${CMD_DEBUG_WAIT} umount "${BOOTFLOPPY}" # modifying via -o loop fails to set changed time, mark this touch "${BOOT}" ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}"`" ${CMD_DEBUG_WAIT} fi # --- unpack and mount root initrd if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "unpacking root image into ${SYS_WORKDIR} ..." ${CMD_DEBUG_SLEEP} # unpack initrd file system from root floppy image ROOTFLOPPY="${SYS_WORKDIR}/root" mkdir -p "${ROOTFLOPPY}" mount -o loop "${ROOT}" "${ROOTFLOPPY}" # copy so that we have enough space to gunzip ROOTINITRD_IMG="${SYS_WORKDIR}/root-initrd.img" gunzip -c "${ROOTFLOPPY}/initrd.gz" > "${ROOTINITRD_IMG}" if [ "${DEBUG_BACKUP_INITRD}" != "" ] ; then # save the unmodified initrd for comparing stuff cp -p "${ROOTINITRD_IMG}" "${ROOTINITRD_IMG}.bak" fi ROOTINITRD="${SYS_WORKDIR}/root-initrd" mkdir -p "${ROOTINITRD}" mount -o loop "${ROOTINITRD_IMG}" "${ROOTINITRD}" ${CMD_DEBUG_PRINT} "+++ begin directory overview +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${SYS_WORKDIR}" "${ROOTFLOPPY}" "${ROOTINITRD}" fi ${CMD_DEBUG_PRINT} "+++ end directory overview +++" ${CMD_DEBUG_WAIT} fi # --- insert network drivers if we want additional ones, to avoid driver disk if [ "${DO_GEN}" != "" -a \ "`echo "${CONF_MODULESNET}" | cut -f 1 -d " "`" != "" ] ; then ${CMD_INFO_PRINT} "adding facultative net drivers that we need/want ..." ${CMD_DEBUG_SLEEP} if [ "${OWN_KERNEL}" != "" ] ; then ${CMD_ERROR} "own kernel being used, and CONF_MODULESNET is selected," \ "which only can use Debian net driver image, aborting ..." >&2 exit 1 fi # the network hardware may need one of these # non-modular kernels (users may want to make such) may not want any # open net-drivers floppy image DRVFLOPPY="${SYS_WORKDIR}/drv" MODULES="nic-extra-modules-${SYS_KERN_VERSION}-di" MODULEDIR="./lib/modules/${SYS_KERN_VERSION}/kernel/drivers/net" mkdir -p "${DRVFLOPPY}" mount -o loop "${DRV}" "${DRVFLOPPY}" cp -p "${DRVFLOPPY}/${MODULES}.udeb" "${SYS_WORKDIR}" umount "${DRVFLOPPY}" # get the actual stuff out of the .udeb dpkg-deb --fsys-tarfile "${SYS_WORKDIR}/${MODULES}.udeb" > \ "${SYS_WORKDIR}/${MODULES}.tar" rm "${SYS_WORKDIR}/${MODULES}.udeb" # and fetch the desired additional modules for MODULE in `echo "${CONF_MODULESNET}" | tr -c -d 'a-z0-9-'` ; do tar xf "${SYS_WORKDIR}/${MODULES}.tar" -C "${ROOTINITRD}" \ "${MODULEDIR}/${MODULE}" done rm -r "${SYS_WORKDIR}/${MODULES}.tar" ${CMD_DEBUG_PRINT} "+++ begin net modules listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTINITRD}/${MODULEDIR}" fi ${CMD_DEBUG_PRINT} "+++ end net modules listing +++" ${CMD_DEBUG_WAIT} fi # --- install the .udeb files for doing the entire preseed thing if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "packing in preseed .udebs onto root initrd ..." ${CMD_DEBUG_SLEEP} # the sarge root image has no modern 1.02 preseeding stuff on it # according to Joey Hess (Bug#299059) no preseed on floppys, fix post-sarge # according to Joey Hess 1.02 and initrd-preseed are also post-sarge # so we fix this here, by installing their .udeb files to our floppy image if [ ! -f "${ROOTINITRD}/lib/debian-installer-startup.d/S35preseed" ] ; then UDEB_LIB=/usr/lib/dphys3/udeb UDEB_PRESEED=preseed-common_1.10_all.udeb UDEB_INITRD=initrd-preseed_1.10_all.udeb cp -p "${UDEB_LIB}/${UDEB_PRESEED}" "${ROOTINITRD}" cp -p "${UDEB_LIB}/${UDEB_INITRD}" "${ROOTINITRD}" chroot "${ROOTINITRD}" udpkg -i "/${UDEB_PRESEED}" > /dev/null chroot "${ROOTINITRD}" udpkg -i "/${UDEB_INITRD}" > /dev/null rm "${ROOTINITRD}/${UDEB_PRESEED}" rm "${ROOTINITRD}/${UDEB_INITRD}" fi ${CMD_DEBUG_PRINT} "+++ begin startup script listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTINITRD}/lib/debian-installer-startup.d" fi ${CMD_DEBUG_PRINT} "+++ end startup script listing +++" ${CMD_DEBUG_WAIT} fi # --- add preseed file for setting up debconf if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "packing preseed file onto root initrd ..." ${CMD_DEBUG_SLEEP} # this location is hardwired into the initrd-preseed packages script PS="${ROOTINITRD}/preseed.cfg" if [ -f "${PS}" ] ; then echo >> "${PS}" echo >> "${PS}" fi echo >> "${PS}" "### --- from here on generated by dphys3pressed" echo >> "${PS}" # - instead of syslinux.cfg settings preseed these here, less trouble # syslinux.cfg can only set max 8 kernel parameters and 5 already taken # get rid of all questions that are avoidable, in all packages echo >> "${PS}" "d-i debconf/priority select critical" # set our language and where we are echo >> "${PS}" "d-i languagechooser/language-name select English" echo >> "${PS}" "d-i countrychooser/shortlist select Switzerland" # select type of keyboard and keymap to use echo >> "${PS}" "d-i console-tools/archs select" \ "PC-style (AT or PS-2 connector) keyboard" echo >> "${PS}" "d-i console-keymaps-at/keymap select ${CONF_KEYBD}" # - do not load additional drivers from floppy, get rid of question # note that this only works with the floppy loader patching below echo >> "${PS}" "d-i retriever/floppy/loadnow boolean false" # - network configuration # set the interface, we default to auto, use first echo >> "${PS}" "d-i netcfg/choose_interface select ${CONF_IF}" # just set dummy hostname and domain names # as dhcp takes precedence over these, but this still prevents questions echo >> "${PS}" "d-i netcfg/get_hostname string dummy-hostname" echo >> "${PS}" "d-i netcfg/get_domain string dummy-domain" # - mirror settings # server must have http://hostname/dir/name URL form, an not file if ! echo "${CONF_DEBSERVER}" | grep -q '^[a-z]*://.*/' ; then ${CMD_ERROR} "CONF_DEBSERVER is \"${CONF_DEBSERVER}\", not valid URL" >&2 exit 1 fi # cut hostname from http://hostname/dir/name MIRROR_HOST="`echo "${CONF_DEBSERVER}" | cut -f 3 -d '/'`" # cut dir/name from http://hostname/dir/name, with leading / MIRROR_DIR="/`echo "${CONF_DEBSERVER}" | cut -f 4- -d '/'`" echo >> "${PS}" "d-i mirror/country string enter information manually" echo >> "${PS}" "d-i mirror/http/hostname string ${MIRROR_HOST}" echo >> "${PS}" "d-i mirror/http/directory string ${MIRROR_DIR}" echo >> "${PS}" "d-i mirror/suite string sarge" echo >> "${PS}" "d-i mirror/http/proxy string" # - partitioning # devfs device name automatically selects hda or sda, cool echo >> "${PS}" "d-i partman-auto/disk string /dev/discs/disc0/disc" if [ "${CONF_SWAP_SIZE}" = "" -o "${CONF_SWAP_SIZE}" = 0 ] ; then # we just want an single big partition, so use own recipe # we also need /boot partition because some BIOSes are still too stupid # size numbers: minimal factor maximal, whatever factor is supposed to be echo >> "${PS}" "d-i partman-auto/expert_recipe string" \ "boot-and-root ::" \ "30 10000 30 ext3" \ "\$primary{ } \$bootable{ } method{ format } format{ }" \ "use_filesystem{ } filesystem{ ext3 } mountpoint{ /boot } ." \ "500 10000 1000000 ext3" \ "method{ format } format{ }" \ "use_filesystem{ } filesystem{ ext3 } mountpoint{ / } ." else # or some people may want an swap partition as well, so also use own recipe echo >> "${PS}" "d-i partman-auto/expert_recipe string" \ "boot-and-swap-and-root ::" \ "30 10000 30 ext3" \ "\$primary{ } \$bootable{ } method{ format } format{ }" \ "use_filesystem{ } filesystem{ ext3 } mountpoint{ /boot } ." \ "${CONF_SWAP_SIZE} 10000 ${CONF_SWAP_SIZE} linux-swap" \ "format{ } ." "500 10000 1000000 ext3" \ "method{ format } format{ }" \ "use_filesystem{ } filesystem{ ext3 } mountpoint{ / } ." fi # and yes we want above, all 3 dialogs long, yes, yes really, yes totally! echo >> "${PS}" "d-i partman/confirm_write_new_label boolean true" echo >> "${PS}" "d-i partman/choose_partition select" \ "Finish partitioning and write changes to disk" echo >> "${PS}" "d-i partman/confirm boolean true" # - boot loader installation # use the standard well tested grub in MBR method # fix using other bootloader or other config later, if wanted echo >> "${PS}" "d-i grub-installer/only_debian boolean true" # - get rid of gratuitous dialogs telling us was is happening # avoid that last message about the install being complete echo >> "${PS}" "d-i prebaseconfig/reboot_in_progress note" # avoid the introductory message after rebooting echo >> "${PS}" "base-config base-config/intro note" # avoid the final message before login appears echo >> "${PS}" "base-config base-config/login note" # - time zone setup # we always use GMT clocks around here echo >> "${PS}" "base-config tzconfig/gmt boolean true" # set up our time zone, in 2 parts echo >> "${PS}" "base-config tzconfig/geographic_area" \ "select ${CONF_TIMEZONE_AREA}" echo >> "${PS}" "base-config tzconfig/select_zone/${CONF_TIMEZONE_AREA}" \ "select ${CONF_TIMEZONE_PLACE}" # - account setup # set an temporary root password, will be later corrected by admin stuff echo >> "${PS}" "passwd passwd/root-password password" \ "${CONF_PASSWORD_ROOT}" echo >> "${PS}" "passwd passwd/root-password-again password" \ "${CONF_PASSWORD_ROOT}" # and we don't want any local users, LDAP and NFS rule around here echo >> "${PS}" "passwd passwd/make-user boolean false" # - apt setup # we load our packages via http echo >> "${PS}" "base-config apt-setup/uri_type select http" # mirror settings, for the second time echo >> "${PS}" "base-config apt-setup/country select" \ "enter information manually" echo >> "${PS}" "base-config apt-setup/hostname string ${MIRROR_HOST}" echo >> "${PS}" "base-config apt-setup/directory string ${MIRROR_DIR}" # only one mirror, rest will be later corrected by local admin stuff echo >> "${PS}" "base-config apt-setup/another boolean false" # some people use non-free and contrib software, some hate them if [ "${CONF_USE_NON_FREE}" = yes -o "${CONF_USE_NON_FREE}" = true ] ; then echo >> "${PS}" "base-config apt-setup/non-free boolean true" else echo >> "${PS}" "base-config apt-setup/non-free boolean false" fi if [ "${CONF_USE_CONTRIB}" = yes -o "${CONF_USE_CONTRIB}" = true ] ; then echo >> "${PS}" "base-config apt-setup/contrib boolean true" else echo >> "${PS}" "base-config apt-setup/contrib boolean false" fi # some people want security updates, some prefer to set this later if [ "${CONF_USE_SECURITY}" = yes -o "${CONF_USE_SECURITY}" = true ] ; then echo >> "${PS}" "base-config apt-setup/security-updates boolean true" else echo >> "${PS}" "base-config apt-setup/security-updates boolean false" fi # - package selection # just minimal installation, as rest is done by our own admin tools echo >> "${PS}" "tasksel tasksel/first multiselect" # - mailer configuration # simply get exim to be quiet as fast as possible, will be replaced later echo >> "${PS}" "exim4-config exim4/dc_eximconfig_configtype select" \ "local delivery only; not on a network" echo >> "${PS}" "exim4-config exim4/dc_postmaster string root" if [ "${DEBUG_DUMP_PRESEED}" = yes ] ; then cp -p "${PS}" . fi ${CMD_DEBUG_PRINT} "`ls -al "${PS}"`" ${CMD_DEBUG_WAIT} fi # --- fix floppy loader so it does not ask, despite preseeding if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "fixing floppy loader on root initrd ..." ${CMD_DEBUG_SLEEP} # remove the db_set command that kills the preseeded value LOADER="${ROOTINITRD}/var/lib/dpkg/info/load-floppy.postinst" sed -e '/db_set/d' "${LOADER}" > "${LOADER}.tmp" mv "${LOADER}.tmp" "${LOADER}" chmod 755 "${LOADER}" ${CMD_DEBUG_PRINT} "`ls -al "${LOADER}"`" ${CMD_DEBUG_WAIT} fi # --- fix silly anna test, so it does not ask if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "fixing anna kernel modules test ..." ${CMD_DEBUG_SLEEP} # this stops the test being done, according to mail answer from Joey Hess # else install waits at dialog, when module-less custom kernel is used echo >> "${PS}" "d-i anna/no_kernel_modules boolean true" ${CMD_DEBUG_PRINT} "`ls -al "${PS}"`" ${CMD_DEBUG_WAIT} fi # --- free up some space for all the additonal stuff if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "freeing up space, deleting unused large stuff ..." ${CMD_DEBUG_SLEEP} # this is only used for non-alphabetical interactive menues rm "${ROOTINITRD}/unifont.bgf" ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD}"`" ${CMD_DEBUG_WAIT} fi # --- run user scripts at end of install stages, for further automation if [ "${DO_GEN}" != "" -a \ "`echo "${CONF_END1STAGE}${CONF_END2STAGE}" | cut -f 1 -d " "`" != "" ] ; \ then ${CMD_INFO_PRINT} "including user scripts for further automation ..." ${CMD_DEBUG_SLEEP} # make sure that ${END1STAGE_CMD} and ${END2STAGE_CMD} get something to do # and that adding anything starting with "; " works, no "; " at beginning # this avoids needing to test for empty and only add an "; " if not empty # this runs at end of first install stage, just before reboot # with install system as / and final system as /target, more flexible so END1STAGE_CMD=true # this runs at end of second install stage, just before login appears # with final system as /, no install system exists any more END2STAGE_CMD=true if [ "${CONF_END1STAGE}" != "" ] ; then # if set to http:// or ftp:// value, then fetch from server at install time if echo "${CONF_END1STAGE}" | grep -q '^[a-z]*://.*/' ; then # an URL was given, wget script at install time, just before using it END1STAGE_CMD="${END1STAGE_CMD}; wget -O /e1s ${CONF_END1STAGE}" elif [ -f "${CONF_END1STAGE}" ] ; then # filename given, use fixed name (/e1s) on target, to avoid name clashes cp -p "${CONF_END1STAGE}" "${ROOTINITRD}/e1s" else ${CMD_ERROR} "CONF_END1STAGE feature enabled in setup, non-URL mode," \ "but file ${CONF_END1STAGE} is missing" >&2 exit 1 fi # put chown and chmod here, before run, to guarantee they allways get done END1STAGE_CMD="${END1STAGE_CMD}; chown root.root /e1s; chmod 755 /e1s; /e1s" fi if [ "${CONF_END2STAGE}" != "" ] ; then if echo "${CONF_END2STAGE}" | grep -q '^[a-z]*://.*/' ; then # an URL was given, wget script at install time, just before using it END2STAGE_CMD="${END2STAGE_CMD}; wget -O /e2s ${CONF_END2STAGE}" elif [ -f "${CONF_END2STAGE}" ] ; then # filename given, use fixed name (/e2s) on target, to avoid name clashes cp -p "${CONF_END2STAGE}" "${ROOTINITRD}/e2s" # and later copy script, which must be originally on /, to /target END1STAGE_CMD="${END1STAGE_CMD}; cp -p /e2s /target" else ${CMD_ERROR} "CONF_END2STAGE feature enabled in setup, non-URL mode," \ "but file ${CONF_END2STAGE} is missing" >&2 exit 1 fi END2STAGE_CMD="${END2STAGE_CMD}; chown root.root /e2s; chmod 755 /e2s; /e2s" fi # preseed running the commands, at end of both install stages echo >> "${PS}" "d-i preseed/late_command string ${END1STAGE_CMD}" echo >> "${PS}" "base-config base-config/late_command string" \ "${END2STAGE_CMD}" if [ "${DEBUG_DUMP_PRESEED}" = yes ] ; then cp -p "${PS}" . fi if [ -f "${ROOTINITRD}/e1s" ] ; then ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD}/e1s"`" fi if [ -f "${ROOTINITRD}/e2s" ] ; then ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD}/e2s"`" fi if [ "`echo "${END1STAGE_CMD}" | cut -c 1`" != "" ] ; then ${CMD_DEBUG_PRINT} "${END1STAGE_CMD}" fi if [ "`echo "${END2STAGE_CMD}" | cut -c 1`" != "" ] ; then ${CMD_DEBUG_PRINT} "${END2STAGE_CMD}" fi ${CMD_DEBUG_PRINT} "`ls -al "${PS}"`" ${CMD_DEBUG_WAIT} fi # --- run user script at end of generating stage, for further automation if [ "${DO_GEN}" != "" -a \ "`echo "${CONF_END0STAGE}" | cut -f 1 -d ' '`" != "" ] ; then ${CMD_INFO_PRINT} "running user script for further automation ..." ${CMD_DEBUG_SLEEP} if [ -f "${CONF_END0STAGE}" ] ; then # run it with the initrd as /, same as END1STAGE is run # so that user does not need to know where we mounted the initrd cp -p "${CONF_END0STAGE}" "${ROOTINITRD}/e0s" chown root.root "${ROOTINITRD}/e0s" chmod 755 "${ROOTINITRD}/e0s" chroot "${ROOTINITRD}" "/e0s" if [ "$?" != 0 ] ; then ${CMD_FATAL} "CONF_END0STAGE script returned error, aborting ..." >&2 exit 1 fi if [ "${DEBUG_LEAVE_END0STAGE}" != yes ] ; then rm "${ROOTINITRD}/e0s" fi else ${CMD_ERROR} "CONF_END0STAGE feature enabled in setup," \ "but file ${CONF_END0STAGE} is missing" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "`ls -al "${CONF_END0STAGE}"`" ${CMD_DEBUG_WAIT} fi # --- unmount and pack root initrd if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "unmounting and packing root image from ${SYS_WORKDIR} ..." ${CMD_DEBUG_SLEEP} # - close root floppy initrd # before closing, to see inside initrd ${CMD_DEBUG_PRINT} "+++ begin rootfloppy initrd listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTINITRD}" fi ${CMD_DEBUG_PRINT} "+++ end rootfloppy initrd listing +++" ${CMD_DEBUG_PRINT} "`du -sk "${ROOTINITRD_IMG}"`" ${CMD_DEBUG_WAIT} umount "${ROOTINITRD}" # - close root floppy image ROOTINITRD_GZ="${SYS_WORKDIR}/root-initrd.gz" gzip -9 -c "${ROOTINITRD_IMG}" > "${ROOTINITRD_GZ}" ${CMD_DEBUG_PRINT} "`ls -al "${ROOTINITRD_GZ}"`" ${CMD_DEBUG_WAIT} set +e cp -p "${ROOTINITRD_GZ}" "${ROOTFLOPPY}/initrd.gz" 2> /dev/null RETVAL="$?" set -e if [ "${RETVAL}" != 0 ] ; then umount "${ROOTFLOPPY}" ${CMD_FATAL} "not enough space for ${ROOTINITRD_GZ} on ${ROOTFLOPPY}" >&2 exit 1 fi # before closing, to see inside floppy ${CMD_DEBUG_PRINT} "+++ begin rootfloppy image listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${ROOTFLOPPY}" fi ${CMD_DEBUG_PRINT} "+++ end rootfloppy image listing +++" ${CMD_DEBUG_WAIT} umount "${ROOTFLOPPY}" # writing to loop mounted image file does not seem to update its access time touch "${ROOT}" ${CMD_DEBUG_PRINT} "`ls -al "${ROOT}"`" ${CMD_DEBUG_WAIT} fi # --- tidy up after working if [ "${DO_GEN}" != "" ] ; then ${CMD_INFO_PRINT} "tidying up from working ..." ${CMD_DEBUG_SLEEP} ${CMD_DEBUG_PRINT} "+++ begin workdirectory listing +++" if [ "${DEBUG_PRINT_STEP}" = yes ] ; then ls -al "${SYS_WORKDIR}" fi ${CMD_DEBUG_PRINT} "+++ end workdirectory listing +++" ${CMD_DEBUG_WAIT} # remove all temporary directories and their contents, to save space # must be after debug printout if [ "${DEBUG_LEAVE_TEMPFILES}" != yes ] ; then # but offer to leave them to investigate bugs rm -rf "${SYS_WORKDIR}" fi fi # --- upload generated floppy images if [ "${DO_UPLOAD}" != "" ] ; then ${CMD_INFO_PRINT} "uploading images to ${CONF_INST_SERVER} ..." ${CMD_DEBUG_SLEEP} # put together stuff to upload, needs an temp dir BOOT_DIR="${SYS_UPLOADDIR}/`dirname "${OWNINST}/${BOOTIMG}"`" ROOT_DIR="${SYS_UPLOADDIR}/`dirname "${OWNINST}/${ROOTIMG}"`" mkdir -p "${BOOT_DIR}" "${ROOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp -R "${CONF_UPLOAD_GROUP}" "${SYS_UPLOADDIR}" chmod -R 2775 "${SYS_UPLOADDIR}" fi if [ -f "${BOOT}" ] ; then cp -p "${BOOT}" "${BOOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp "${CONF_UPLOAD_GROUP}" "${BOOT_DIR}"/* chmod 664 "${BOOT_DIR}"/* fi fi if [ -f "${ROOT}" ] ; then cp -p "${ROOT}" "${ROOT_DIR}" if [ "${CONF_UPLOAD_GROUP}" != "" ] ; then chgrp "${CONF_UPLOAD_GROUP}" "${ROOT_DIR}"/* chmod 664 "${ROOT_DIR}"/* fi fi # include directory tree, duplicating tree to server, in case server has none # may be none if new package is in an previously unused section # this is a bit site dependant, you need ssh on your local package server # 2> needed to get rid of error message, because scp can not change dir modes # this loses us the progress bar, because scp tests also 2> for tty or not # if user has given us somewhere to upload to, else dphys2cp|pxe get screwed if [ "${CONF_UPLOAD_SERVER}" != "" ] ; then scp -pr "${SYS_UPLOADDIR}"/* "${CONF_UPLOAD_SERVER}" 2> /dev/null else ${CMD_FATAL} "no server to upload root floppy image to" >&2 exit 1 fi ${CMD_DEBUG_PRINT} "`ls -al "${SYS_UPLOADDIR}/${OWNINST}/${BOOTIMG}"`" ${CMD_DEBUG_PRINT} "`ls -al "${SYS_UPLOADDIR}/${OWNINST}/${ROOTIMG}"`" ${CMD_DEBUG_WAIT} # remove temporary directory and its contents, to save space # must be after debug printout if [ "${DEBUG_LEAVE_TEMPDIRS}" != yes ] ; then # but offer to leave this to investigate bugs rm -rf "${SYS_UPLOADDIR}" fi fi # --- remove disk images if [ "${DO_REMOVE}" != "" ] ; then ${CMD_INFO_PRINT} "removing disk images ..." ${CMD_DEBUG_PRINT} "`ls -al "${BOOT}" 2> /dev/null`" ${CMD_DEBUG_PRINT} "`ls -al "${ROOT}" 2> /dev/null`" if [ -f "${DRV}" ] ; then ${CMD_DEBUG_PRINT} "`ls -al "${DRV}" 2> /dev/null`" fi ${CMD_DEBUG_WAIT} rm -f "${BOOT}" "${ROOT}" "${DRV}" fi exit 0