summaryrefslogtreecommitdiff
path: root/1_makerootfs.sh
diff options
context:
space:
mode:
authorjonas <jonas@8f53b18a-e215-0410-8885-9f593d34873e>2006-06-10 18:18:37 +0000
committerjonas <jonas@8f53b18a-e215-0410-8885-9f593d34873e>2006-06-10 18:18:37 +0000
commitb6d85b04286d30498a11aaac36e75032b1e72801 (patch)
tree2fc597a2ae2cf69a5cc6b3e7162f02f89613b08d /1_makerootfs.sh
parent369cb1e5a343ec9e7c6f05de64f0eb102488d77f (diff)
Added all work so far...
git-svn-id: svn+ssh://xayide/home/jonas/private_svn/fleshybrid/trunk@2 8f53b18a-e215-0410-8885-9f593d34873e
Diffstat (limited to '1_makerootfs.sh')
-rwxr-xr-x1_makerootfs.sh189
1 files changed, 189 insertions, 0 deletions
diff --git a/1_makerootfs.sh b/1_makerootfs.sh
new file mode 100755
index 0000000..0f56607
--- /dev/null
+++ b/1_makerootfs.sh
@@ -0,0 +1,189 @@
+#!/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
+ # 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
+
+# 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!'