#!/bin/sh set -e . ./config-DEFAULTS || exit 1 . ./config-HOST || exit 1 . ./config-TARGET || exit 1 . ./config-MANDATED || exit 1 . ./functions || exit 1 mkdir "$targettemp" case "$debootstrap" in debootstrap) debootstrap \ --include=$debootstrap_includes \ --exclude=$debootstrap_excludes \ "$suite" "$targettemp" "$aptsource_base_host" ;; cdebootstrap) cdebootstrap \ --flavour=minimal \ "$suite" "$targettemp" "$aptsource_base_cdebootstrap" ;; *) echo "ERROR: unknown debootstrap binary defined: \"$debootstrap\"" >&2 exit 1 esac # Tweak configuration files preserveandaddlines "$targettemp/etc/fstab" orig 2 "$rootdev_target\t/\t$ROOTFS\tro\t0\t1" "none\t/proc\tproc\tdefaults\t0\t0" mkdir -p "$targettemp/etc/network/" preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto lo" preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface lo inet loopback" if [ -n "$DHCPCLIENT" ]; then preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto eth0" preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface eth0 inet dhcp" # TODO: Write function to apply multiline entry for static ip #elif [ -n "$hostdefaultip" ]; then # enableoraddlines "$targettemp/etc/network/interfaces" 2 "iface eth0 inet static" fi preserveandaddlines "$targettemp/etc/hosts" orig 1 "127.0.0.1 localhost" if [ -n "$hostdefaultip" ]; then preserveandaddlines "$targettemp/etc/hosts" orig 1 "$hostdefaultip $hostname.$domainname $hostname" fi if [ -n "$hostname" ] && [ -n "$domainname" ]; then preserveandaddlines "$targettemp/etc/hostname" orig 1 "$hostname.$domainname" fi if [ ! -d "$targettemp/etc/resolv.conf" ]; then if [ -n "$dns_server" ]; then preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "nameserver $dns_server" fi if [ -n "$domainname" ]; then preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "search $domainname" fi fi for aptsource in $aptsources; do eval uri=\"'$'aptsource_${aptsource}_host\" eval components=\"'$'aptsource_${aptsource}_components\" preserveandaddlines "$targettemp/etc/apt/sources.list" orig 2 "deb $uri $suite ${components:-main}" done if [ -n "$pubdev_target" ] && [ -n "$pubfs" ]; then mkdir -p "$targettemp/pub" preserveandaddlines "$targettemp/etc/fstab" orig 2 "$pubdev_target\t/pub\t$pubfs\tdefaults,noauto,ro\t0\t0" fi rm -rf "$targettemp/var/log/ksymoops" ln -f -s /proc/mounts "$targettemp/etc/mtab" preserveandaddlines "$targettemp/etc/modules" orig 1 $modules_load if [ -n "$loghost" ]; then preserveolderfile "$targettemp/etc/syslog.conf" orig echo "*.* @$loghost" > "$targettemp/etc/syslog.conf" fi # Install/remove additional packages export DEBIAN_FRONTEND="noninteractive" case "$debootstrap" in debootstrap) ;; cdebootstrap) ./chroot.sh temp apt-get update ./chroot.sh temp apt-get -y --allow-unauthenticated install aptitude ./chroot.sh temp aptitude -y purge cdebootstrap-helper-diverts # Hmm - this next one seems like a bug! rm -rf "$targettemp/var/cache/debootstrap" ;; esac mkdir -p "$targettemp/etc/apt/apt.conf.d" echo 'Aptitude::CmdLine::Ignore-Trust-Violations "yes";' > "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall" ./chroot.sh temp aptitude update # Next command should *not* cause any packages to get uninstalled, so # questions asked is an error and shouldn't be suppressed ./chroot.sh temp aptitude markauto '~i!~M(~E|~prequired|~sdevel|~sinterpreters|~slibdevel|~slibs|~soldlibs|~sperl|~spython|~sshells)' ./chroot.sh temp aptitude install -y --without-recommends debconf-english policyrcd-script-zg2 cp -af tweaks/usr/local/sbin/policy-rc.d "$targettemp/usr/local/sbin/" ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install $aptitude_dhcpclient_install # Workaround for Debian bug#272257 (see http://bugs.debian.org/281264 ) #rm -f "$targettemp/etc/resolv.conf" # Prepare kernel installation # TODO: support yaird and mkramfs too # FIXME: deal with initrd generated while on host if [ -n "$RAMDISKTOOL" = "initrd-tools" ]; then preserveolderfile "$targettemp/etc/mkinitrd/mkinitrd.conf" orig perl -pi -e "s¡^ROOT=.*¡ROOT=$rootdev_target¡" "$targettemp/etc/mkinitrd/mkinitrd.conf" perl -pi -e "s¡^MODULES=.*¡MODULES=dep¡" "$targettemp/etc/mkinitrd/mkinitrd.conf" preserveandaddlines "$targettemp/etc/mkinitrd/modules" orig 1 $modules_install fi preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 \ "do_symlinks = no" \ "relative_links = yes" \ "do_bootloader = no" \ "do_bootfloppy = no" \ "do_initrd = yes" \ "link_in_boot = no" \ "silent_modules = yes" # FIXME: check if these are actually still any use with latest kernels cp -af initrd-tools/usbstick "$targettemp/usr/share/initrd-tools/scripts/usbstick" chmod 0755 "$targettemp/usr/share/initrd-tools/scripts/usbstick" cp -af initrd-tools/initrd.usbinit "$targettemp/usr/local/share/initrd.usbinit" if [ "$FLASHYBRID" = "yes" ]; then addaddons flashybrid_diskstore flashybrid_diskstore $addons # preserveandaddlines "$targettemp/etc/flashybrid/config" orig 1 "EMBED_CMDS=\"mount -o remount,ro /; invoke-rc-d mountvirtfs start\"" preserveandaddlines "$targettemp/etc/flashybrid/ramtmp" orig 1 $flashybrid_ramtmp preserveandaddlines "$targettemp/etc/flashybrid/ramstore" orig 1 $flashybrid_ramstore preserveandaddlines "$targettemp/etc/flashybrid/diskstore" orig 1 $flashybrid_diskstore # Disable /dev # FIXME: Add and honour flag about using udev or not preserveandhashdisablelines "$targettemp/etc/flashybrid/ramstore" orig 1 "/dev" # Move off flashybrid directories (but leave empty dir behind) mkdir -p "$targetoffline" "$targettemp/ram" "$targettemp/disk" preserveandaddlines "$targettemp/etc/fstab" orig 2 "$diskdev_target\t/disk\t$diskfs\tdefaults,noauto,nolock\t0\t0" # FIXME: Somehow make this step idempotent for dir in $flashybrid_diskstore; do if [ -d "${targettemp}${dir}" ]; then mkdir -p "$(dirname "${targetoffline}${dir}")" mv "${targettemp}${dir}" "${targetoffline}${dir}" else mkdir -p "${targetoffline}${dir}" fi mkdir -p "${targettemp}${dir}" done preserveolderfile "$targettemp/etc/default/flashybrid" orig perl -pi -e "s¡^ENABLED=.*¡ENABLED=yes¡" "$targettemp/etc/default/flashybrid" fi if [ -n "$grubdev_host" ]; then # Prepare GRUB install mkdir -p "$targettemp/boot/grub" mkgrubdevmap "$usbdev_target" > "$targettemp/boot/grub/device.map" cp -af "$targettemp/lib/grub/i386-pc/"* "$targettemp/boot/grub" # FIXME: Invent a hook wrapping both this and other bootloaders preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 "postinst_hook = /sbin/update-grub" "postrm_hook = /sbin/update-grub" # preserveandaddlines "$targettemp/boot/grub/menu.lst" orig 1 "default 0" "timeout 5" "color cyan/blue white/blue" # FIXME: Write update-grub wrapper that disables "savedefault" option ./chroot.sh temp update-grub -y fi # Install kernel(s) # (must be after GRUB preparation but before SYSLINUX) ./chroot.sh temp aptitude install -y --without-recommends $aptitude_kernel_install if [ -n "$grubdev_host" ]; then # FIXME: Write a kernel install hook to always strip # TODO: Rewrite as single-line perl routine cp -af "$targettemp/boot/grub/menu.lst" "$targettemp/boot/grub/menu.lst.old" grep -v -x 'savedefault' "$targettemp/boot/grub/menu.lst.old" > "$targettemp/boot/grub/menu.lst" rm -f "$targettemp/boot/grub/menu.lst.old" fi if [ -n "$syslinuxdev_host" ]; then mkdir -p "$targettemp_fat" cp -af "$targettemp/boot/initrd.img-${kernel_name}" "$targettemp_fat/initrd.img" cp -af "$targettemp/boot/vmlinuz-${kernel_name}" "$targettemp_fat/vmlinuz" enableoraddlines "$targettemp_fat/syslinux.cfg" 1 "default vmlinuz" "append initrd=initrd.img ramdisk_size=10240 root=$rootdev_target ro" fi # Install additional packages export DEBIAN_FRONTEND="noninteractive" addaddons aptitude_install_custom aptitude_install $addons if [ -n "$aptitude_install_custom" ]; then ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install_custom fi # ifupdown temporarily installs a dir, but cannot replace with symlink later due to rad-only rootfs for context in network resolvconf; do if [ -d "$targettemp/etc/$context/run" ] && [ ! -L "$targettemp/etc/$context/run" ]; then rm -rf "$targettemp/etc/$context/run" ln -s "/dev/shm/$context" "$targettemp/etc/$context/run" fi done # Remove hack to suppress warnings about insecure install rm -f "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall" # Strip encryption keys (we don't want them distributed!) for keyfile in ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; do rm -f "$targettemp/etc/ssh/$keyfile" "$targettemp/etc/ssh/$keyfile.pub" done echo 'Done creating rootfs!'