diff --git a/misc/build.func b/misc/build.func index a63076f..d084364 100644 --- a/misc/build.func +++ b/misc/build.func @@ -419,8 +419,60 @@ advanced_settings() { exit_script fi - BRIDGES=$(awk -F: '/^[0-9]+: (vmbr[0-9]+(\.[0-9]+)?)@?/{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' <(ip -o link show) | cut -d@ -f1 | sort -u) + # List of network interface configuration files + # Considers both the main /etc/network/interfaces file and all files in the /etc/network/interfaces.d/ directory + IFACE_FILEPATH_LIST="/etc/network/interfaces"$'\n'$(find "/etc/network/interfaces.d/" -type f) + # Initialize the variable that will contain bridge names + BRIDGES="" + + # Save the original value of the internal field separator (IFS)... + OLD_IFS=$IFS + # ...then IFS to newline to iterate over complete lines + IFS=$'\n' + + # Iterate over each network interface configuration file + for iface_filepath in ${IFACE_FILEPATH_LIST}; do + # Create a unique temporary filename to store interface indexes + iface_indexes_tmpfile=$(mktemp -q -u '.iface-XXXX') + + # This block processes the file to create start:end pairs for each 'iface' block + # 1. Find all lines starting with 'iface' and store their line numbers + # 2. Get the total number of lines in the file + # 3. Use awk to create line ranges for each iface section (start:end) + ( grep -Pn '^\s*iface' "${iface_filepath}" | cut -d':' -f1 && wc -l "${iface_filepath}" | cut -d' ' -f1 ) | awk 'FNR==1 {line=$0; next} {print line":"$0-1; line=$0}' > "${iface_indexes_tmpfile}" + + # Check if the indexes file exists, hence has been created + if [ -f "${iface_indexes_tmpfile}" ]; then + # Iterate over each start:end pair in the indexes file + while read -r pair; do + # Extract the starting line number of the interface block + start=$(echo "${pair}" | cut -d':' -f1) + # Extract the ending line number of the interface block + end=$(echo "${pair}" | cut -d':' -f2) + + # Check if the block contains bridge configurations + # Looks for lines containing bridge parameters like bridge-ports, bridge-stp, etc. + if awk "NR >= ${start} && NR <= ${end}" "${iface_filepath}" | grep -qP '^\s*bridge[-_](ports|stp|fd|vlan-aware|vids)\s+'; then + # Extract the interface name from the first line of the block + iface_name=$(sed "${start}q;d" "${iface_filepath}" | awk '{print $2}') + # Add the interface name to the list of bridges + BRIDGES="${iface_name}"$'\n'"${BRIDGES}" + fi + + done < "${iface_indexes_tmpfile}" + + # Clean up the temporary file + rm -f "${iface_indexes_tmpfile}" + fi + + done + + # Restore the original IFS value + IFS=$OLD_IFS + + # Filter the bridge list to remove empty lines and duplicates, then sort alphabetically + BRIDGES=$(echo "$BRIDGES" | grep -v '^\s*$' | sort | uniq) if [[ -z "$BRIDGES" ]]; then BRG="vmbr0" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" @@ -678,7 +730,6 @@ EOF config_file() { - CONFIG_FILE="/opt/community-scripts/.settings" if [[ -f "/opt/community-scripts/${NSAPP}.conf" ]]; then @@ -691,13 +742,10 @@ config_file() { exit else echo -e "${INFO}${BOLD}${DGN}Using config File: ${BGN}$CONFIG_FILE${CL}" - echo "Befor base" base_settings - echo "After base" source "$CONFIG_FILE" fi fi - echo "ID: ${CT_ID}" if [[ -n "$CT_ID" ]]; then if [[ "$CT_ID" =~ ^([0-9]{3,4})-([0-9]{3,4})$ ]]; then MIN_ID=${BASH_REMATCH[1]} @@ -719,7 +767,6 @@ config_file() { echo -e "${CONTAINERID}${BOLD}${DGN}Container ID: ${BGN}$CT_ID${CL}" elif [[ "$CT_ID" =~ ^[0-9]+$ ]]; then - echo "Befor LIST_OF_IDS" LIST_OF_IDS=$(pvesh get /cluster/resources --type vm --output-format json 2>/dev/null | grep -oP '"vmid":\s*\K\d+') || true if [[ -n "$LIST_OF_IDS" ]]; then