DHCPInfo/utils/subnets.sh

18 lines
568 B
Bash
Raw Normal View History

2023-11-12 21:38:07 +00:00
#!/bin/bash
get_subnet_declerations () {
2023-11-12 23:08:54 +00:00
local SECTION_CONTENT SECTION_NAME
2023-11-12 21:38:07 +00:00
local -n HASH_TABLE="${1:?"get_subnet_declerations: Hash table was not provided"}"
local CONTENT="${2:?"get_subnet_declerations: Content to be parsed was not provided"}"
2023-11-12 23:08:54 +00:00
local -a SECTIONS
get_sections $SUBNET_BEGIN_REGEX SECTIONS "$CONTENT"
local IP_REGEX='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
2023-11-12 21:38:07 +00:00
2023-11-12 23:08:54 +00:00
for i in ${!SECTIONS[@]}; do
SECTION_CONTENT="${SECTIONS[$i]}"
SECTION_NAME=`grep -Eo $IP_REGEX <<< "$SECTION_CONTENT" | head -n 1`
HASH_TABLE["$SECTION_NAME"]="$SECTION_CONTENT"
2023-11-12 23:08:54 +00:00
done
2023-11-12 21:38:07 +00:00
}