DHCPInfo/utils/shared-networks.sh

54 lines
1.2 KiB
Bash
Raw Normal View History

2023-11-12 21:38:07 +00:00
#!/bin/bash
# BEGIN: Variables
DHCPD_CONF_CONTENTS="$(<${CONFIG_FILE:?"DHCPD_CONFIG was not set"})"
# END: Variables
# BEGIN: Functions
get_shared_network_declarations () {
local CURRENT_BUFFER=""
local CURRENT_SHARED_NETWORK_NAME=""
local -i OPEN_BRACKETS=0
local -i CLOSE_BRACKETS=0
local CAN_READ=0
local -n HASH_TABLE="${1:?"get_declarations: Has table variable not passed into function"}"
while read line; do
if [[ "$line" =~ ^$SHARED_NETWORK_BEGIN_REGEX.*$ ]]; then
CAN_READ=1
CURRENT_SHARED_NETWORK_NAME=`echo $line | awk '{ print $2 }' | tr -d \"`
fi
if [[ $CAN_READ -eq 1 ]]; then
CURRENT_BUFFER+="$line\n"
[[ "$line" == *'{'* ]] && ((OPEN_BRACKETS++))
[[ "$line" == *'}'* ]] && ((CLOSE_BRACKETS++))
if [[ $OPEN_BRACKETS -eq $CLOSE_BRACKETS ]]; then
HASH_TABLE["$CURRENT_SHARED_NETWORK_NAME"]="$( echo -e "$CURRENT_BUFFER" )"
CURRENT_BUFFER=""
CAN_READ=0
OPEN_BRACKETS=0
CLOSE_BRACKETS=0
CURRENT_SHARED_NETWORK_NAME=""
fi
fi
done <<< "$DHCPD_CONF_CONTENTS"
}
# END: Functions
declare -A testHashTable
get_shared_network_declarations testHashTable
for name in "${!testHashTable[@]}"; do
echo "$name"
echo "${testHashTable[$name]}"
done