#!/bin/bash # Author: Daniel Kahn Gillmor # Date: 2009-10-08 # License: GPL v3+ set -e # depends on grub2 # specify the first argument as the new installer image: output="$1" # optionally specify the second argument as a preseed file: preseed="$2" SUITE=${SUITE:-stable} ARCH=${ARCH:-amd64} DISTRO=${DISTRO:-debian} if [ -z "$output" ] ; then printf "you must specify a file name for the image to be built" >&2 exit 1 fi if [ -e "$output" ] ; then printf "file '%s' already exists" "$output" >&2 exit 1 fi preseed_args='' if [ "$preseed" ] ; then if ! [ -r "$preseed" ] ; then printf "could not read preseed file '%s'\n" "$preseed" >&2 exit 1 fi fi WORKDIR=$(mktemp -d) cleanup() { rm -rf "$WORKDIR" } trap cleanup EXIT case "$DISTRO" in debian) BASEPATH="http://ftp.nl.debian.org/debian/dists/$SUITE/main/installer-$ARCH/current/images/netboot/debian-installer/$ARCH" ;; ubuntu) BASEPATH="http://archive.ubuntu.com/ubuntu/dists/$SUITE/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH" ;; esac KERNEL=linux INITRAMFS=initrd.gz BOOTINSTRUCTIONS=" linux /$KERNEL verbose -- console=ttyS0,115200n8 initrd /$INITRAMFS " case "$ARCH" in kfreebsd-*) # FIXME: this discards the requested SUITE, and just pulls the # latest d-i, because dkg is lazy SUITE=sid KERNEL=kfreebsd.gz BASEPATH="http://d-i.debian.org/daily-images/$ARCH/daily/monolithic/" BOOTINSTRUCTIONS=' # this set came from mini.iso kfreebsd /kfreebsd.gz kfreebsd_module /initrd.gz type=mfs_root set kFreeBSD.vfs.root.mountfrom=ufs:/dev/md0 set kFreeBSD.hw.ata.ata_dma=0 # needed for qemu hard disk # TODO: delete set kFreeBSD.hw.ata.atapi_dma=0 # needed for qemu cd # TODO: 1 # this set came from http://jdc.parodius.com/freebsd/pxeboot_serial_install_7.html set kFreeBSD.comconsole_speed="115200" set kFreeBSD.console="comconsole" ' esac ( cd "$WORKDIR" && wget "$BASEPATH"/{$KERNEL,$INITRAMFS} ) if [ "$preseed" ]; then unpackdir=$(mktemp -d) cp "$preseed" "$unpackdir/preseed.cfg" ( cd "$unpackdir" && fakeroot bash -c "gzip -d < '$WORKDIR/$INITRAMFS' | cpio --extract ; find . | cpio --create -H newc | gzip" ) > "$WORKDIR/$INITRAMFS.new" mv "$WORKDIR/$INITRAMFS.new" "$WORKDIR/$INITRAMFS" fi mkdir -p "$WORKDIR/boot/grub" cat > "$WORKDIR/boot/grub/grub.cfg" <