Set up default /etc/network/interfaces with dhcp for eth0 in VM use case
authorMichael Prokop <mika@grml.org>
Sat, 19 Apr 2014 23:28:33 +0000 (01:28 +0200)
committerMichael Prokop <mika@grml.org>
Sun, 20 Apr 2014 00:26:23 +0000 (02:26 +0200)
Network interfaces in VM should listen to DHCP by default,
and if /etc/network/interfaces doesn't exist at all (so
takeover from host to guest isn't possible either) create
a sane default as well.

Thanks: Christian Hofstaedtler <christian@hofstaedtler.name> for suggestion + review
Thanks: Ulrich Dangel <mru@spamt.net> for review
Fixes #20

chroot-script
grml-debootstrap

index 3ae79ee..dc895cb 100755 (executable)
@@ -414,25 +414,6 @@ EOF
 }
 # }}}
 
-# set up /etc/network/interfaces {{{
-interfaces() {
-  if ! [ -r /etc/network/interfaces ] || ! grep -q "auto lo" /etc/network/interfaces ; then
-     echo "Setting up /etc/network/interfaces"
-     cat >> /etc/network/interfaces << EOF
-
-# loopback device:
-iface lo inet loopback
-auto lo
-
-# eth0:
-# iface eth0 inet dhcp
-# auto eth0
-
-EOF
-  fi
-}
-# }}}
-
 # set default locales {{{
 default_locales() {
   if [ -n "$DEFAULT_LOCALES" ] ; then
@@ -626,7 +607,7 @@ trap signal_handler HUP INT QUIT TERM
  install_policy_rcd
 
  for i in chrootmirror grmlrepos backportrepos kernelimg_conf \
-     kernel packages extrapackages  reconfigure hosts interfaces \
+     kernel packages extrapackages reconfigure hosts \
      default_locales timezone fstab hostname initrd grub_install passwords \
      custom_scripts upgrade_system remove_apt_cache services \
      remove_chrootmirror; do
index 3cccbca..06200d8 100755 (executable)
@@ -1231,17 +1231,34 @@ preparechroot() {
   [ -d $CONFFILES/usr   ] && cp $VERBOSE -a -L $CONFFILES/usr/*   $MNTPOINT/usr/
   [ -d $CONFFILES/var   ] && cp $VERBOSE -a -L $CONFFILES/var/*   $MNTPOINT/var/
 
-  # copy local network setup to chroot
+  # network setup
+  DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
+
+# Include files from /etc/network/interfaces.d when using
+# ifupdown v0.7.44 or newer:
+#source-directory /etc/network/interfaces.d
+
+auto lo
+iface lo inet loopback
+
+allow-hotplug eth0
+iface eth0 inet dhcp
+"
+
   if [ -n "$NOINTERFACES" ] ; then
     einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0
   elif [ -n "$VIRTUAL" ] ; then
-    einfo "Installing into Virtual Machine, skipping installation of /etc/network/interfaces" ; eend 0
+    einfo "Installing into Virtual Machine, installing default /etc/network/interfaces"
+    echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
+    eend $?
   elif [ -r /etc/network/interfaces ] ; then
     einfo "Copying /etc/network/interfaces from host to target system"
-    cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
+    cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
     eend $?
   else
-    ewarn "Couldn't read /etc/network/interfaces, not copying to target system" ; eend 0
+    ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
+    echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces"
+    eend $?
   fi
 
   # install config file providing some example entries