added a few things
This commit is contained in:
parent
84757d23e4
commit
78af1a1961
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
*
|
||||
!README.md
|
||||
!.gitignore
|
||||
!utils
|
||||
!utils/*
|
||||
|
33
utils/myread.sh
Normal file
33
utils/myread.sh
Normal file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
get_sections() {
|
||||
local START_REGEX="${1:?"get_sections: START_REGEX was not provided"}"
|
||||
local -n CONTAINER="${2:?"get_sections: Has CONTAINER variable not passed into function"}"
|
||||
local CONTENT="${3:?"get_sections: Content was not provided"}"
|
||||
|
||||
local CURRENT_BUFFER=""
|
||||
local -i OPEN_BRACKETS=0
|
||||
local -i CLOSE_BRACKETS=0
|
||||
local CAN_READ=0
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" =~ ^$START_REGEX.*$ ]]; then
|
||||
CAN_READ=1
|
||||
fi
|
||||
|
||||
if [[ $CAN_READ -eq 1 ]]; then
|
||||
CURRENT_BUFFER+="$line\n"
|
||||
[[ "$line" == *'{'* ]] && ((OPEN_BRACKETS++))
|
||||
[[ "$line" == *'}'* ]] && ((CLOSE_BRACKETS++))
|
||||
if [[ $OPEN_BRACKETS -eq $CLOSE_BRACKETS ]]; then
|
||||
CONTAINER+=( "$( echo -e "$CURRENT_BUFFER" )" )
|
||||
CURRENT_BUFFER=""
|
||||
CAN_READ=0
|
||||
OPEN_BRACKETS=0
|
||||
CLOSE_BRACKETS=0
|
||||
fi
|
||||
fi
|
||||
|
||||
done <<< "$CONTENT"
|
||||
}
|
||||
|
53
utils/shared-networks.sh
Executable file
53
utils/shared-networks.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/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
|
||||
|
20
utils/subnets.sh
Normal file
20
utils/subnets.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BEGIN: Variables
|
||||
|
||||
SUBNET_BEGIN_REGEX='^[[:space:]]*subnet[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[[:space:]]+netmask[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[[:space:]]+\{'
|
||||
# END: Variables
|
||||
|
||||
get_subnet_declerations () {
|
||||
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"}"
|
||||
local -i OPEN_BRACKETS=0
|
||||
local -i CLOSE_BRACKETS=0
|
||||
local CAN_READ=0
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" =~ ^$SUBNET_BEGIN_REGEX.*$ ]]; then
|
||||
CAN_READ=1
|
||||
fi
|
||||
done <<< "$CONTENT"
|
||||
}
|
Loading…
Reference in New Issue
Block a user