]> gitweb.fluxo.info Git - kvmx.git/commitdiff
TAP network config at kvmx-create
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 16:53:55 +0000 (13:53 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 16:53:55 +0000 (13:53 -0300)
kvmx-create
kvmxfile

index 0982f4dcbb46bc1e2853813eae7fcc63c6d8701e..a908663159b13f8c5c5718c66e33fef24e60ffcf 100755 (executable)
@@ -114,6 +114,14 @@ function kvmx_config {
   kvmx_user_config   ssh_custom        y                                "Setup a custom SSH keypair (y/n)"
   kvmx_user_config   user              user                             "Initial user name"
   kvmx_user_config   password          $default_password                "Initial user password"
+  kvmx_user_config   net               user                             "Networking config (user or tap)"
+
+  if [ "$net" == "tap" ]; then
+    kvmx_user_config net_ip            10.1.1.2                         "IP address"
+    kvmx_user_config net_mask          255.255.0                        "Netmask"
+    kvmx_user_config net_gateway       10.1.1.1                         "Gateway"
+    kvmx_user_config net_dns           192.168.1.1                      "DNS"
+  fi
 
   if [ ! -z "$image_base" ]; then
     image="$image_base/$hostname/box.img"
@@ -356,19 +364,44 @@ EOF
 
 # Second stage procedure
 function __kvmx_create_custom_second_stage {
-  # Networking: eth0
-  cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/eth0 > /dev/null
+  if [ ! -z "$net_ip" ] && [ ! -z "$net_mask" ] && [ ! -z "$net_gateway" ] && [ -z "$net_dns" ]; then
+    # DNS config
+    echo "nameserver $net_dns" > $WORK/etc/resolv.conf
+
+    # Networking: eth0
+    cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/eth0 > /dev/null
+auto eth0
+iface eth0 inet static
+  address $net_ip
+  netmask $net_mask
+  gateway $net_gateway
+EOF
+
+    # Networking: ens3
+    # See #799253 - virtio ens3 network interface
+    #     https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253
+    cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/ens3 > /dev/null
+auto ens3
+iface ens3 inet static
+  address $net_ip
+  netmask $net_mask
+  gateway $net_gateway
+EOF
+  else
+    # Networking: eth0
+    cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/eth0 > /dev/null
 allow-hotplug eth0
 iface eth0 inet dhcp
 EOF
 
-  # Networking: ens3
-  # See #799253 - virtio ens3 network interface
-  #     https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253
-  cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/ens3 > /dev/null
+    # Networking: ens3
+    # See #799253 - virtio ens3 network interface
+    #     https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253
+    cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/ens3 > /dev/null
 allow-hotplug ens3
 iface ens3 inet dhcp
 EOF
+  fi
 
   # Locale
   $APT_INSTALL locales
index 08f9ffedb835598a41a1114581fada6e40ce52f9..3247505e32abc5ed400b85e2f1f2dcd3b9002736 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -15,6 +15,13 @@ password="`head -c 20 /dev/urandom | base64`"
 #net="tap"
 net="user"
 
+# Networking: tap config only
+# This setting is used during virtual machine bootstrapping by kvmx-create.
+#net_ip="10.1.1.2"
+#net_mask="255.255.255.0"
+#net_gateway="10.1.1.1"
+#net_dns="192.168.1.1"
+
 # Set this is you want to be able to share a single folder between host and guest.
 # Needs ssh_support set to "y" and a workable SSH connection to the guest.
 shared_folder="."