diff --git a/proxmox/build.network.file b/proxmox/build.network.file new file mode 100755 index 0000000..d9d2577 --- /dev/null +++ b/proxmox/build.network.file @@ -0,0 +1,48 @@ +#!/bin/sh + +# Purpose : {{{ +# Proxmox only reads /etc/network/interfaces from a while +# See : https://forum.proxmox.com/threads/anyway-to-support-interfaces-d.34739/ +# So any bridge,… in the subdirectory /etc/network/interfaces.d won't be +# available from webgui to manage KVM/LXC's network device. +# }}} +# This script will try to fix this waiting for a Proxmox's fix. {{{ +# Check if /etc/network/interfaces.d contains file(s) +# Create a temp interfaces file +# Add some basic/header informations to the temp file +# Cat the content of interfaces.d files to the temp file +# Replace default interfaces file with the temp one + +# }}} + +interfaces_dir="/etc/network/interfaces.d" +interfaces_temp="/etc/network/interfaces.temp.script" + +# Test if interfaces.d is empty +if [ -z "$(ls -A ${interfaces_dir})" ]; then + exit 0 +fi + +# Create temp file +rm -f -- "${interfaces_temp}" +touch -- "${interfaces_temp}" + +# Header informations +printf '%b' "# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). +" >> "${interfaces_temp}" + +# Loopback informations if not present in interfaces.d +grep -q -R "iface lo" "${interfaces_dir}" || printf '%b' " +# The loopback network interface +auto lo +iface lo inet loopback +" >> "${interfaces_temp}" + +# Cat the content of interfaces.d to temp file (POSIX way) +find "${interfaces_dir}" -type f -exec cat {} >> "${interfaces_temp}" \; + +# Define it a new interfaces file +mv -- "${interfaces_temp}" /etc/network/interfaces + +exit 0