summaryrefslogtreecommitdiff
path: root/1_makerootfs.sh
blob: 839643a11bda9b0c6eb1ce3c12d5ee78a7dfa8e8 (plain)
  1. #!/bin/sh
  2. set -e
  3. . ./config-DEFAULTS || exit 1
  4. . ./config-HOST || exit 1
  5. . ./config-TARGET || exit 1
  6. . ./config-MANDATED || exit 1
  7. . ./functions || exit 1
  8. mkdir "$targettemp"
  9. case "$debootstrap" in
  10. debootstrap)
  11. debootstrap \
  12. --include=$debootstrap_includes \
  13. --exclude=$debootstrap_excludes \
  14. "$suite" "$targettemp" "$aptsource_base_host"
  15. ;;
  16. cdebootstrap)
  17. cdebootstrap \
  18. --flavour=minimal \
  19. "$suite" "$targettemp" "$aptsource_base_cdebootstrap"
  20. ;;
  21. *)
  22. echo "ERROR: unknown debootstrap binary defined: \"$debootstrap\"" >&2
  23. exit 1
  24. esac
  25. # Tweak configuration files
  26. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$rootdev_target\t/\t$ROOTFS\tro\t0\t1" "none\t/proc\tproc\tdefaults\t0\t0"
  27. mkdir -p "$targettemp/etc/network/"
  28. preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto lo"
  29. preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface lo inet loopback"
  30. if [ -n "$DHCPCLIENT" ]; then
  31. preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto eth0"
  32. preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface eth0 inet dhcp"
  33. # TODO: Write function to apply multiline entry for static ip
  34. #elif [ -n "$hostdefaultip" ]; then
  35. # enableoraddlines "$targettemp/etc/network/interfaces" 2 "iface eth0 inet static"
  36. fi
  37. preserveandaddlines "$targettemp/etc/hosts" orig 1 "127.0.0.1 localhost"
  38. if [ -n "$hostdefaultip" ]; then
  39. preserveandaddlines "$targettemp/etc/hosts" orig 1 "$hostdefaultip $hostname.$domainname $hostname"
  40. fi
  41. if [ -n "$hostname" ] && [ -n "$domainname" ]; then
  42. preserveandaddlines "$targettemp/etc/hostname" orig 1 "$hostname.$domainname"
  43. fi
  44. if [ ! -d "$targettemp/etc/resolv.conf" ]; then
  45. if [ -n "$dns_server" ]; then
  46. preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "nameserver $dns_server"
  47. fi
  48. if [ -n "$domainname" ]; then
  49. preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "search $domainname"
  50. fi
  51. fi
  52. for aptsource in $aptsources; do
  53. eval uri=\"'$'aptsource_${aptsource}_host\"
  54. eval components=\"'$'aptsource_${aptsource}_components\"
  55. preserveandaddlines "$targettemp/etc/apt/sources.list" orig 2 "deb $uri $suite ${components:-main}"
  56. done
  57. if [ -n "$pubdev_target" ] && [ -n "$pubfs" ]; then
  58. mkdir -p "$targettemp/pub"
  59. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$pubdev_target\t/pub\t$pubfs\tdefaults,noauto,ro\t0\t0"
  60. fi
  61. rm -rf "$targettemp/var/log/ksymoops"
  62. ln -f -s /proc/mounts "$targettemp/etc/mtab"
  63. preserveandaddlines "$targettemp/etc/modules" orig 1 $modules_load
  64. if [ -n "$loghost" ]; then
  65. preserveolderfile "$targettemp/etc/syslog.conf" orig
  66. echo "*.* @$loghost" > "$targettemp/etc/syslog.conf"
  67. fi
  68. # Install/remove additional packages
  69. export DEBIAN_FRONTEND="noninteractive"
  70. case "$debootstrap" in
  71. debootstrap)
  72. ;;
  73. cdebootstrap)
  74. ./chroot.sh temp apt-get update
  75. ./chroot.sh temp apt-get -y --allow-unauthenticated install aptitude
  76. ./chroot.sh temp aptitude -y purge cdebootstrap-helper-diverts
  77. # Hmm - this next one seems like a bug!
  78. rm -rf "$targettemp/var/cache/debootstrap"
  79. ;;
  80. esac
  81. mkdir -p "$targettemp/etc/apt/apt.conf.d"
  82. echo 'Aptitude::CmdLine::Ignore-Trust-Violations "yes";' > "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  83. ./chroot.sh temp aptitude update
  84. # Next command should *not* cause any packages to get uninstalled, so
  85. # questions asked is an error and shouldn't be suppressed
  86. ./chroot.sh temp aptitude markauto '~i!~M(~E|~prequired|~sdevel|~sinterpreters|~slibdevel|~slibs|~soldlibs|~sperl|~spython|~sshells)'
  87. ./chroot.sh temp aptitude install -y --without-recommends debconf-english policyrcd-script-zg2
  88. cp -af tweaks/usr/local/sbin/policy-rc.d "$targettemp/usr/local/sbin/"
  89. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install $aptitude_dhcpclient_install
  90. # Workaround for Debian bug#272257 (see http://bugs.debian.org/281264 )
  91. #rm -f "$targettemp/etc/resolv.conf"
  92. # Prepare kernel installation
  93. # TODO: support yaird and mkramfs too
  94. # FIXME: deal with initrd generated while on host
  95. if [ -n "$RAMDISKTOOL" = "initrd-tools" ]; then
  96. preserveolderfile "$targettemp/etc/mkinitrd/mkinitrd.conf" orig
  97. perl -pi -e "s¡^ROOT=.*¡ROOT=$rootdev_target¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  98. perl -pi -e "s¡^MODULES=.*¡MODULES=dep¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  99. preserveandaddlines "$targettemp/etc/mkinitrd/modules" orig 1 $modules_install
  100. fi
  101. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 \
  102. "do_symlinks = no" \
  103. "relative_links = yes" \
  104. "do_bootloader = no" \
  105. "do_bootfloppy = no" \
  106. "do_initrd = yes" \
  107. "link_in_boot = no" \
  108. "silent_modules = yes"
  109. # FIXME: check if these are actually still any use with latest kernels
  110. cp -af initrd-tools/usbstick "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  111. chmod 0755 "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  112. cp -af initrd-tools/initrd.usbinit "$targettemp/usr/local/share/initrd.usbinit"
  113. if [ "$FLASHYBRID" = "yes" ]; then
  114. addaddons flashybrid_diskstore flashybrid_diskstore $addons
  115. # preserveandaddlines "$targettemp/etc/flashybrid/config" orig 1 "EMBED_CMDS=\"mount -o remount,ro /; invoke-rc-d mountvirtfs start\""
  116. preserveandaddlines "$targettemp/etc/flashybrid/ramtmp" orig 1 $flashybrid_ramtmp
  117. preserveandaddlines "$targettemp/etc/flashybrid/ramstore" orig 1 $flashybrid_ramstore
  118. preserveandaddlines "$targettemp/etc/flashybrid/diskstore" orig 1 $flashybrid_diskstore
  119. # Move off flashybrid directories (but leave empty dir behind)
  120. mkdir -p "$targetoffline" "$targettemp/ram" "$targettemp/disk"
  121. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$diskdev_target\t/disk\t$diskfs\tdefaults,noauto,nolock\t0\t0"
  122. # FIXME: Somehow make this step idempotent
  123. for dir in $flashybrid_diskstore; do
  124. if [ -d "${targettemp}${dir}" ]; then
  125. mkdir -p "$(dirname "${targetoffline}${dir}")"
  126. mv "${targettemp}${dir}" "${targetoffline}${dir}"
  127. else
  128. mkdir -p "${targetoffline}${dir}"
  129. fi
  130. mkdir -p "${targettemp}${dir}"
  131. done
  132. preserveolderfile "$targettemp/etc/default/flashybrid" orig
  133. perl -pi -e "s¡^ENABLED=.*¡ENABLED=yes¡" "$targettemp/etc/default/flashybrid"
  134. fi
  135. if [ -n "$grubdev_host" ]; then
  136. # Prepare GRUB install
  137. mkdir -p "$targettemp/boot/grub"
  138. mkgrubdevmap "$usbdev_target" > "$targettemp/boot/grub/device.map"
  139. cp -af "$targettemp/lib/grub/i386-pc/"* "$targettemp/boot/grub"
  140. # FIXME: Invent a hook wrapping both this and other bootloaders
  141. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 "postinst_hook = /sbin/update-grub" "postrm_hook = /sbin/update-grub"
  142. # preserveandaddlines "$targettemp/boot/grub/menu.lst" orig 1 "default 0" "timeout 5" "color cyan/blue white/blue"
  143. # FIXME: Write update-grub wrapper that disables "savedefault" option
  144. ./chroot.sh temp update-grub -y
  145. fi
  146. # Install kernel(s)
  147. # (must be after GRUB preparation but before SYSLINUX)
  148. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_kernel_install
  149. if [ -n "$grubdev_host" ]; then
  150. # FIXME: Write a kernel install hook to always strip
  151. # TODO: Rewrite as single-line perl routine
  152. cp -af "$targettemp/boot/grub/menu.lst" "$targettemp/boot/grub/menu.lst.old"
  153. grep -v -x 'savedefault' "$targettemp/boot/grub/menu.lst.old" > "$targettemp/boot/grub/menu.lst"
  154. rm -f "$targettemp/boot/grub/menu.lst.old"
  155. fi
  156. if [ -n "$syslinuxdev_host" ]; then
  157. mkdir -p "$targettemp_fat"
  158. cp -af "$targettemp/boot/initrd.img-${kernel_name}" "$targettemp_fat/initrd.img"
  159. cp -af "$targettemp/boot/vmlinuz-${kernel_name}" "$targettemp_fat/vmlinuz"
  160. enableoraddlines "$targettemp_fat/syslinux.cfg" 1 "default vmlinuz" "append initrd=initrd.img ramdisk_size=10240 root=$rootdev_target ro"
  161. fi
  162. # Install additional packages
  163. export DEBIAN_FRONTEND="noninteractive"
  164. addaddons aptitude_install_custom aptitude_install $addons
  165. if [ -n "$aptitude_install_custom" ]; then
  166. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install_custom
  167. fi
  168. # ifupdown temporarily installs a dir, but cannot replace with symlink later due to rad-only rootfs
  169. if [ -d "$targettemp/etc/network/run" ] && [ ! -L "$targettemp/etc/network/run" ]; then
  170. rm -f "$targettemp/etc/network/run"
  171. ln -s /dev/shm/network "$targettemp/etc/network/run"
  172. fi
  173. # Remove hack to suppress warnings about insecure install
  174. rm -f "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  175. # Strip encryption keys (we don't want them distributed!)
  176. for keyfile in ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; do
  177. rm -f "$targettemp/etc/ssh/$keyfile" "$targettemp/etc/ssh/$keyfile.pub"
  178. done
  179. echo 'Done creating rootfs!'