Set up default /etc/network/interfaces with dhcp for eth0 in VM use case
[grml-debootstrap.git] / grml-debootstrap
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