Improve packer deployment for usage in Vagrant
authorMichael Prokop <mika@grml.org>
Thu, 15 May 2014 15:25:04 +0000 (17:25 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 15 May 2014 15:25:04 +0000 (17:25 +0200)
* work around "stdin: is not a tty" issue via /root/.profile
* set up loopback entry in /etc/hosts to make sudo happy ("sudo: unable to resolve host")
* store build information to /etc/grml_debootstrap.info

packer/debian64_provision.sh

index 7830ad4..d0a49d3 100644 (file)
@@ -95,11 +95,27 @@ chroot ${TARGET} chown vagrant:vagrant /home/vagrant/.ssh /home/vagrant/.ssh/aut
 echo "* Setting up sudo configuration for user vagrant"
 echo "vagrant ALL=(ALL) NOPASSWD: ALL" > ${TARGET}/etc/sudoers.d/vagrant
 
+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
 
+echo "* Logging build information to /etc/grml_debootstrap.info"
+echo "System generated by grml-debootstrap/provision on $(date)" > ${TARGET}/etc/grml_debootstrap.info
+
 echo "* Cleaning up apt stuff"
 chroot ${TARGET} apt-get clean
 rm -f ${TARGET}/var/lib/apt/lists/*Packages \