Created
February 5, 2020 15:31
-
-
Save ExploitSage/7c92a791cf9d583254754ec6ac6786ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_ini() { | |
local varname="${1}" | |
local ini_source=$(cat -) | |
declare -gA "${varname}" | |
local IFS_BAK="${IFS}"; | |
IFS=$'\n'; | |
for section in $(echo "${ini_source}" | grep -Po '(?<=\[).*(?=\])'); do | |
for option_value in $(echo "${ini_source}" | grep -Pazo "(?s)(?<=\[${section}\])(.*?)(?=\[|$)" | tr -d '\000' | grep "="); do | |
option="$(echo "${option_value}" | cut -d "=" -f 1)"; | |
value="$(echo "${option_value}" | cut -d "=" -f 2-)"; | |
eval "${varname}[\"${section},${option}\"]=\"${value}\""; | |
done; | |
done; | |
IFS="${IFS_BAK}"; | |
} | |
# TODO Need easy way to take output into array without sections with "spaces" being split-up | |
function get_sections() { | |
IFS_BAK="${IFS}"; | |
IFS=$'\n'; | |
for key in "${@}"; do | |
section_key="$(echo "${key}" | cut -d ',' -f 1)" | |
echo "${section_key}" | |
done | sort | uniq; | |
IFS="${IFS_BAK}"; | |
} | |
function get_options() { | |
section="${1}"; | |
shift 1; | |
IFS_BAK="${IFS}"; | |
IFS=$'\n'; | |
for key in "${@}"; do | |
echo "${key}" | grep "${section}"; | |
done | sort; | |
IFS="${IFS_BAK}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment