summaryrefslogtreecommitdiff
path: root/1_makerootfs.sh
blob: eb2d3654c3221df3fb3d232341b960b62e53f25c (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. case "$suite" in
  76. etch|sid)
  77. ./chroot.sh temp apt-get -y --allow-unauthenticated install aptitude
  78. ;;
  79. *)
  80. ./chroot.sh temp apt-get -y install aptitude
  81. ;;
  82. esac
  83. ./chroot.sh temp aptitude -y purge cdebootstrap-helper-diverts
  84. # Hmm - this next one seems like a bug!
  85. rm -rf "$targettemp/var/cache/debootstrap"
  86. ;;
  87. esac
  88. mkdir -p "$targettemp/etc/apt/apt.conf.d"
  89. echo 'Aptitude::CmdLine::Ignore-Trust-Violations "yes";' > "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  90. ./chroot.sh temp aptitude update
  91. # Next command should *not* cause any packages to get uninstalled, so
  92. # questions asked is an error and shouldn't be suppressed
  93. ./chroot.sh temp aptitude markauto '~i!~M(~E|~prequired|~sdevel|~sinterpreters|~slibdevel|~slibs|~soldlibs|~sperl|~spython|~sshells)'
  94. ./chroot.sh temp aptitude install -y --without-recommends debconf-english policyrcd-script-zg2
  95. cp -af tweaks/usr/local/sbin/policy-rc.d "$targettemp/usr/local/sbin/"
  96. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install $aptitude_dhcpclient_install
  97. # Workaround for Debian bug#272257 (see http://bugs.debian.org/281264 )
  98. #rm -f "$targettemp/etc/resolv.conf"
  99. # Prepare kernel installation
  100. # TODO: support yaird and mkramfs too
  101. # FIXME: deal with initrd generated while on host
  102. if [ "$RAMDISKTOOL" = "initrd-tools" ]; then
  103. preserveolderfile "$targettemp/etc/mkinitrd/mkinitrd.conf" orig
  104. perl -pi -e "s¡^ROOT=.*¡ROOT=$rootdev_target¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  105. perl -pi -e "s¡^MODULES=.*¡MODULES=dep¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  106. preserveandaddlines "$targettemp/etc/mkinitrd/modules" orig 1 $modules_install
  107. fi
  108. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 \
  109. "do_symlinks = no" \
  110. "relative_links = yes" \
  111. "do_bootloader = no" \
  112. "do_bootfloppy = no" \
  113. "do_initrd = yes" \
  114. "link_in_boot = no" \
  115. "silent_modules = yes"
  116. # FIXME: check if these are actually still any use with latest kernels
  117. cp -af initrd-tools/usbstick "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  118. chmod 0755 "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  119. cp -af initrd-tools/initrd.usbinit "$targettemp/usr/local/share/initrd.usbinit"
  120. if [ "$FLASHYBRID" = "yes" ]; then
  121. addaddons flashybrid_diskstore flashybrid_diskstore $addons
  122. # preserveandaddlines "$targettemp/etc/flashybrid/config" orig 1 "EMBED_CMDS=\"mount -o remount,ro /; invoke-rc-d mountvirtfs start\""
  123. preserveandaddlines "$targettemp/etc/flashybrid/ramtmp" orig 1 $flashybrid_ramtmp
  124. preserveandaddlines "$targettemp/etc/flashybrid/ramstore" orig 1 $flashybrid_ramstore
  125. preserveandaddlines "$targettemp/etc/flashybrid/diskstore" orig 1 $flashybrid_diskstore
  126. # Disable /dev
  127. # FIXME: Add and honour flag about using udev or not
  128. preserveandhashdisablelines "$targettemp/etc/flashybrid/ramstore" orig 1 "/dev"
  129. # Move off flashybrid directories (but leave empty dir behind)
  130. mkdir -p "$targetoffline" "$targettemp/ram" "$targettemp/disk"
  131. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$diskdev_target\t/disk\t$diskfs\tdefaults,noauto,nolock\t0\t0"
  132. # FIXME: Somehow make this step idempotent
  133. for dir in $flashybrid_diskstore; do
  134. if [ -d "${targettemp}${dir}" ]; then
  135. mkdir -p "$(dirname "${targetoffline}${dir}")"
  136. mv "${targettemp}${dir}" "${targetoffline}${dir}"
  137. else
  138. mkdir -p "${targetoffline}${dir}"
  139. fi
  140. mkdir -p "${targettemp}${dir}"
  141. done
  142. preserveolderfile "$targettemp/etc/default/flashybrid" orig
  143. perl -pi -e "s¡^ENABLED=.*¡ENABLED=yes¡" "$targettemp/etc/default/flashybrid"
  144. fi
  145. if [ -n "$grubdev_host" ]; then
  146. # Prepare GRUB install
  147. mkdir -p "$targettemp/boot/grub"
  148. mkgrubdevmap "$usbdev_target" > "$targettemp/boot/grub/device.map"
  149. cp -af "$targettemp/lib/grub/i386-pc/"* "$targettemp/boot/grub"
  150. # FIXME: Invent a hook wrapping both this and other bootloaders
  151. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 "postinst_hook = /sbin/update-grub" "postrm_hook = /sbin/update-grub"
  152. # preserveandaddlines "$targettemp/boot/grub/menu.lst" orig 1 "default 0" "timeout 5" "color cyan/blue white/blue"
  153. # FIXME: Write update-grub wrapper that disables "savedefault" option
  154. ./chroot.sh temp update-grub -y
  155. fi
  156. # Install kernel(s)
  157. # (must be after GRUB preparation but before SYSLINUX)
  158. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_kernel_install
  159. if [ -n "$grubdev_host" ]; then
  160. # FIXME: Write a kernel install hook to always strip
  161. # TODO: Rewrite as single-line perl routine
  162. cp -af "$targettemp/boot/grub/menu.lst" "$targettemp/boot/grub/menu.lst.old"
  163. grep -v -x 'savedefault' "$targettemp/boot/grub/menu.lst.old" > "$targettemp/boot/grub/menu.lst"
  164. rm -f "$targettemp/boot/grub/menu.lst.old"
  165. fi
  166. if [ -n "$syslinuxdev_host" ]; then
  167. mkdir -p "$targettemp_fat"
  168. cp -af "$targettemp/boot/initrd.img-${kernel_name}" "$targettemp_fat/initrd.img"
  169. cp -af "$targettemp/boot/vmlinuz-${kernel_name}" "$targettemp_fat/vmlinuz"
  170. enableoraddlines "$targettemp_fat/syslinux.cfg" 1 "default vmlinuz" "append initrd=initrd.img ramdisk_size=10240 root=$rootdev_target ro"
  171. fi
  172. # Install additional packages
  173. export DEBIAN_FRONTEND="noninteractive"
  174. addaddons aptitude_install_custom aptitude_install $addons
  175. if [ -n "$aptitude_install_custom" ]; then
  176. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install_custom
  177. fi
  178. # ifupdown temporarily installs a dir, but cannot replace with symlink later due to rad-only rootfs
  179. for context in network resolvconf; do
  180. if [ -d "$targettemp/etc/$context/run" ] && [ ! -L "$targettemp/etc/$context/run" ]; then
  181. rm -rf "$targettemp/etc/$context/run"
  182. ln -s "/dev/shm/$context" "$targettemp/etc/$context/run"
  183. fi
  184. done
  185. # Remove hack to suppress warnings about insecure install
  186. rm -f "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  187. # Strip encryption keys (we don't want them distributed!)
  188. for keyfile in ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; do
  189. rm -f "$targettemp/etc/ssh/$keyfile" "$targettemp/etc/ssh/$keyfile.pub"
  190. done
  191. echo 'Done creating rootfs!'