+ exit "$2"
+}
+trap 'bailout ${LINENO} $?' ERR
+
+## helper functions
+virtualbox_setup() {
+ case "$DEBIAN_VERSION" in
+ lenny)
+ echo "* Debian lenny doesn't support Virtualbox Guest Additions, skipping."
+ return 0
+ ;;
+ esac
+
+ if ! mountpoint "${TARGET}" &>/dev/null ; then
+ echo "* Mounting target system"
+ mount "${INSTALL_TARGET}" "${TARGET}"
+ fi
+
+ echo "* Installing packages for Virtualbox Guest Additions"
+ chroot ${TARGET} apt-get -y install make gcc dkms
+
+ echo "* Installing Virtualbox Guest Additions"
+ isofile="${HOME}/VBoxGuestAdditions.iso"
+
+ KERNELHEADERS=$(basename $(find $TARGET/usr/src/ -maxdepth 1 -name linux-headers\* ! -name \*common) | sort -u -r -V | head -1)
+ if [ -z "$KERNELHEADERS" ] ; then
+ echo "Error: no kernel headers found for building the VirtualBox Guest Additions kernel module." >&2
+ exit 1
+ fi
+
+ KERNELVERSION=${KERNELHEADERS##linux-headers-}
+ if [ -z "$KERNELVERSION" ] ; then
+ echo "Error: no kernel version could be identified." >&2
+ exit 1
+ fi
+
+ cp /tmp/fake-uname.so "${TARGET}/tmp/fake-uname.so"
+ mkdir -p "${TARGET}/media/cdrom"
+ mountpoint "${TARGET}/media/cdrom" >/dev/null && umount "${TARGET}/media/cdrom"
+ mount -t iso9660 $isofile "${TARGET}/media/cdrom/"
+ UTS_RELEASE=$KERNELVERSION LD_PRELOAD=/tmp/fake-uname.so grml-chroot "$TARGET" /media/cdrom/VBoxLinuxAdditions.run --nox11 || true
+ tail -10 "${TARGET}/var/log/VBoxGuestAdditions.log"
+ umount "${TARGET}/media/cdrom/"
+
+ # work around bug in VirtualBox 4.3.18 which leaves process behind,
+ # causing unmount of "$TARGET" to fail
+ grml-chroot "$TARGET" /etc/init.d/vboxadd-service stop || true
+ # left behind by VBoxService
+ umount "$TARGET"/dev || true
+
+ # work around regression in virtualbox-guest-additions-iso 4.3.10
+ if [ -d ${TARGET}/opt/VBoxGuestAdditions-4.3.10 ] ; then
+ ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions ${TARGET}/usr/lib/VBoxGuestAdditions
+ fi
+
+ if mountpoint "${TARGET}" &>/dev/null ; then
+ echo "* Unmounting target system"
+ umount "${TARGET}"
+ fi
+}
+
+vagrant_setup() {
+ if ! mountpoint "${TARGET}" &>/dev/null ; then
+ echo "* Mounting target system"
+ mount "${INSTALL_TARGET}" "${TARGET}"
+ fi
+
+ echo "* Setting password for user root to 'vagrant'"
+ echo root:vagrant | chroot ${TARGET} chpasswd
+
+ echo "* Installing sudo package"
+ chroot ${TARGET} apt-get -y install sudo
+
+ echo "* Adding Vagrant user"
+ chroot ${TARGET} useradd -d /home/vagrant -m -u 1000 vagrant
+
+ echo "* Installing Vagrant ssh key"
+ mkdir -m 0700 -p ${TARGET}/home/vagrant/.ssh
+ echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" >> ${TARGET}/home/vagrant/.ssh/authorized_keys
+ chmod 0600 ${TARGET}/home/vagrant/.ssh/authorized_keys
+ chroot ${TARGET} chown vagrant:vagrant /home/vagrant/.ssh /home/vagrant/.ssh/authorized_keys
+
+ echo "* Setting up sudo configuration for user vagrant"
+ if ! [ -d "${TARGET}/etc/sudoers.d" ] ; then # lenny:
+ echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> "${TARGET}/etc/sudoers"
+ else # wheezy and newer:
+ echo "vagrant ALL=(ALL) NOPASSWD: ALL" > "${TARGET}/etc/sudoers.d/vagrant"
+ chmod 0440 "${TARGET}/etc/sudoers.d/vagrant"
+ fi
+
+ host="$(cat ${TARGET}/etc/hostname)"
+ if ! grep -q "${host}$" "${TARGET}"/etc/hosts ; then
+ echo "* Setting up localhost entry for hostname $host in /etc/hosts"
+ cat >> "${TARGET}"/etc/hosts << EOF
+# Added by grml-debootstrap/provision to make sure host is resolvable for sudo:
+127.0.0.2 ${host}.local $host
+
+EOF
+ fi
+
+ echo "* Setting up stdin/tty workaround in /root/.profile"
+ sed -i "s;^mesg n$;# modified via grml-debootstrap/provision script to work around stdin/tty issue:\ntty -s \&\& mesg n;g" "${TARGET}"/root/.profile
+
+ if [ -f ${TARGET}/etc/ssh/sshd_config ] && ! grep -q '^UseDNS' ${TARGET}/etc/ssh/sshd_config ; then
+ echo "* Disabling UseDNS in sshd config"
+ echo "UseDNS no" >> ${TARGET}/etc/ssh/sshd_config
+ fi
+
+ if mountpoint "${TARGET}" &>/dev/null ; then
+ echo "* Unmounting target system"
+ umount "${TARGET}"
+ fi