Index: /trunk/src/VBox/Main/UnattendedTemplates/debian_postinstall.sh
===================================================================
--- /trunk/src/VBox/Main/UnattendedTemplates/debian_postinstall.sh	(revision 68086)
+++ /trunk/src/VBox/Main/UnattendedTemplates/debian_postinstall.sh	(revision 68087)
@@ -3,5 +3,7 @@
 # Post installation script template for debian-like distros.
 #
-# This script expects to be running w/o chroot.
+# Note! This script expects to be running w/o chroot.
+# Note! When using ubiquity, this is run after installation logs have
+#       been copied to /var/log/installation.
 #
 
@@ -18,9 +20,55 @@
 #
 
-#MY_DEBUG="yes"
-MY_DEBUG=""
+
+#
+# Globals.
+#
 MY_TARGET="/target"
 MY_LOGFILE="${MY_TARGET}/var/log/vboxpostinstall.log"
 MY_EXITCODE=0
+MY_DEBUG="" # "yes"
+
+
+#
+# Do we need to exec using target bash?  If so, we must do that early
+# or ash will bark 'bad substitution' and fail.
+#
+if [ "$1" = "--need-target-bash" ]; then
+    # Try figure out which directories we might need in the library path.
+    if [ -z "${LD_LIBRARY_PATH}" ]; then
+        LD_LIBRARY_PATH="${MY_TARGET}/lib"
+    fi
+    for x in \
+        ${MY_TARGET}/lib \
+        ${MY_TARGET}/usr/lib \
+        ${MY_TARGET}/lib/*linux-gnu/ \
+        ${MY_TARGET}/lib32/ \
+        ${MY_TARGET}/lib64/ \
+        ${MY_TARGET}/usr/lib/*linux-gnu/ \
+        ${MY_TARGET}/usr/lib32/ \
+        ${MY_TARGET}/usr/lib64/ \
+        ;
+    do
+        if [ -e "$x" ]; then LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${x}"; fi;
+    done
+    export LD_LIBRARY_PATH
+
+    # Append target bin directories to the PATH as busybox may not have tee.
+    PATH="${PATH}:${MY_TARGET}/bin:${MY_TARGET}/usr/bin:${MY_TARGET}/sbin:${MY_TARGET}/usr/sbin"
+    export PATH
+
+    # Drop the --need-target-bash argument and re-exec.
+    shift
+    echo "******************************************************************************" >> "${MY_LOGFILE}"
+    echo "** Relaunching using ${MY_TARGET}/bin/bash $0 $*" >> "${MY_LOGFILE}"
+    echo "**   LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${MY_LOGFILE}"
+    echo "**              PATH=${PATH}" >> "${MY_LOGFILE}"
+    exec "${MY_TARGET}/bin/bash" "$0" "$@"
+fi
+
+
+#
+# Commands.
+#
 
 # Logs execution of a command.
@@ -42,4 +90,5 @@
 }
 
+# Logs execution of a command inside the target.
 log_command_in_target()
 {
@@ -58,5 +107,5 @@
 
 #
-# Header.
+# Log header.
 #
 echo "******************************************************************************" >> "${MY_LOGFILE}"
@@ -64,4 +113,5 @@
 echo "** Date:    `date -R`" >> "${MY_LOGFILE}"
 echo "** Started: $0 $*" >> "${MY_LOGFILE}"
+
 
 #
@@ -80,7 +130,15 @@
 fi
 
+
 #
 # We want the ISO available inside the target jail.
 #
+if [ -d "${MY_TARGET}/cdrom" ]; then
+    MY_RMDIR_TARGET_CDROM=
+else
+    MY_RMDIR_TARGET_CDROM="yes"
+    log_command mkdir -p ${MY_TARGET}/cdrom
+fi
+
 if [ -f "${MY_TARGET}/cdrom/vboxpostinstall.sh" ]; then
     MY_UNMOUNT_TARGET_CDROM=
@@ -99,4 +157,5 @@
 fi
 
+
 #
 # Debug
@@ -104,23 +163,30 @@
 if [ "${MY_DEBUG}" = "yes" ]; then
     log_command id
+    log_command ps
+    log_command ps auxwwwf
+    log_command env
     log_command df
     log_command mount
     log_command_in_target df
     log_command_in_target mount
-    log_command find /
+    #log_command find /
     MY_EXITCODE=0
 fi
 
+
 #
 # Packages needed for GAs.
 #
+echo "--------------------------------------------------" >> "${MY_LOGFILE}"
 echo '** Installing packages for building kernel modules...' | tee -a "${MY_LOGFILE}"
 log_command_in_target apt-get -y install build-essential
 log_command_in_target apt-get -y install linux-headers-$(uname -r)
 
+
 #
 # GAs
 #
 @@VBOX_COND_IS_INSTALLING_ADDITIONS@@
+echo "--------------------------------------------------" >> "${MY_LOGFILE}"
 echo '** Installing VirtualBox Guest Additions...' | tee -a "${MY_LOGFILE}"
 MY_IGNORE_EXITCODE=2  # returned if modules already loaded and reboot required.
@@ -130,8 +196,10 @@
 @@VBOX_COND_END@@
 
+
 #
 # Test Execution Service.
 #
 @@VBOX_COND_IS_INSTALLING_TEST_EXEC_SERVICE@@
+echo "--------------------------------------------------" >> "${MY_LOGFILE}"
 echo '** Installing Test Execution Service...' | tee -a "${MY_LOGFILE}"
 log_command_in_target test "/cdrom/vboxvalidationkit/linux/@@VBOX_INSERT_OS_ARCH@@/TestExecService"
@@ -167,5 +235,5 @@
 EOF
     fi
-    log_command chmod 755 "${MY_UNIT_PATH}/vboxtxs.service"
+    log_command chmod 644 "${MY_UNIT_PATH}/vboxtxs.service"
     log_command_in_target systemctl -q enable vboxtxs
 
@@ -176,4 +244,5 @@
 
 @@VBOX_COND_END@@
+
 
 #
@@ -185,4 +254,5 @@
 @@VBOX_COND_END@@
 
+
 #
 # Unmount the cdrom if we bound it and clean up the chroot if we set it up.
@@ -192,4 +262,9 @@
     log_command umount "${MY_TARGET}/cdrom"
 fi
+
+if [ -n "${MY_RMDIR_TARGET_CDROM}" ]; then
+    log_command rmdir "${MY_TARGET}/cdrom"
+fi
+
 if [ -n "${MY_HAVE_CHROOT_SETUP}" ]; then
     if chroot_cleanup; then
@@ -201,5 +276,5 @@
 
 #
-# Footer.
+# Log footer.
 #
 echo "******************************************************************************" >> "${MY_LOGFILE}"
Index: /trunk/src/VBox/Main/UnattendedTemplates/debian_preseed.cfg
===================================================================
--- /trunk/src/VBox/Main/UnattendedTemplates/debian_preseed.cfg	(revision 68086)
+++ /trunk/src/VBox/Main/UnattendedTemplates/debian_preseed.cfg	(revision 68087)
@@ -26,5 +26,7 @@
 d-i clock-setup/utc-auto boolean true
 d-i clock-setup/utc boolean true
+## @todo set this
 d-i time/zone string US/Pacific
+## @todo do we want ntp? probably not if GAs are installed.
 d-i clock-setup/ntp boolean true
 
@@ -32,9 +34,16 @@
 d-i base-installer/kernel/override-image string linux-server
 d-i base-installer/kernel/override-image string linux-image-amd64
+## @todo use nearest mirror somehow...
+# debug tip: Replace US with DE.
 d-i mirror/country string US
 d-i mirror/http/proxy string
+d-i pkgsel/install-language-support boolean false
+# debug tip: disable the following for minimal install
 d-i apt-setup/restricted boolean true
 d-i apt-setup/universe boolean true
-d-i pkgsel/install-language-support boolean false
+# debug tip: enable the following for minimal install
+#   tasksel tasksel/first multiselect minimal
+#   d-i pkgsel/include string openssh-server
+#   d-i pkgsel/upgrade select none
 
 # Users
@@ -61,7 +70,9 @@
 d-i finish-install/reboot_in_progress note
 
-# Custom Commands
+# Custom Commands.
+# Note! Debian netboot images use busybox, so no bash.
+#       Tell script to use target bash.
 d-i preseed/late_command string cp /cdrom/vboxpostinstall.sh /target/root/vboxpostinstall.sh \
  && chmod +x /target/root/vboxpostinstall.sh \
- && /bin/bash /root/vboxpostinstall.sh
+ && /bin/sh /target/root/vboxpostinstall.sh --need-target-bash --preseed-late-command
 
Index: /trunk/src/VBox/Main/UnattendedTemplates/ubuntu_preseed.cfg
===================================================================
--- /trunk/src/VBox/Main/UnattendedTemplates/ubuntu_preseed.cfg	(revision 68086)
+++ /trunk/src/VBox/Main/UnattendedTemplates/ubuntu_preseed.cfg	(revision 68087)
@@ -64,9 +64,13 @@
 d-i preseed/late_command string cp /cdrom/vboxpostinstall.sh /target/root/vboxpostinstall.sh \
  && chmod +x /target/root/vboxpostinstall.sh \
- && /bin/bash /root/vboxpostinstall.sh
+ && /bin/bash /root/vboxpostinstall.sh --preseed-late-command
 
 # Same as above, but for ubiquity.
+ubiquity ubiquity/success_command string vboxpostinstall.sh
 ubiquity ubiquity/success_command string cp /cdrom/vboxpostinstall.sh /target/root/vboxpostinstall.sh \
  && chmod +x /target/root/vboxpostinstall.sh \
- && /bin/bash /target/root/vboxpostinstall.sh
+ && /bin/bash /target/root/vboxpostinstall.sh --ubiquity-success-command
 
+# automatically reboot after installation.
+ubiquity ubiquity/reboot boolean true
+
