From ef098a76a27cc5ee5a46d5fc0ca1c0b485f9a005 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 13 Dec 2023 22:23:31 -0500 Subject: [PATCH] Add_server function pretty much done except for the bug squishin'. --- tojam | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tojam b/tojam index 65048f2..99876e8 100755 --- a/tojam +++ b/tojam @@ -67,7 +67,7 @@ add_server() { errorMessage="" fi done - servers[${serverInfo[0]}]="${serverInfo[1]}:${serverInfo[2]}" + echo "[${serverInfo[0]}]=\"${serverInfo[1]}:${serverInfo[2]}\"" >> "${config}/servers.conf" exit 0 } @@ -99,10 +99,10 @@ mkdir -p "${config}" if ! [[ -r "${config}/config" ]]; then # Write initial config file - echo 'anonymous="true"' >> "${config}/config" - echo 'saveSourceFiles="false"' >> "${config}/config" - echo 'soundDriver="jack"' >> "${config}/config" - echo "userName='Tojam$(date '+%S')'" >> "${config}/config" + { echo 'anonymous="true"'; + echo 'saveSourceFiles="false"'; + echo 'soundDriver="jack"'; + echo "userName='Tojam$(date '+%S')'"; } >> "${config}/config" fi source "${config}/config" @@ -125,6 +125,20 @@ declare -A servers=( [Ninjamer 4]="ninjamer.com:2052" $( [[ -r "${config}/servers.conf" ]] && source "${config}/servers.conf") ) +if [[ -r "${config}/servers.conf" ]]; then + while IFS="=" read -r key value; do + if [[ "$key" =~ ^\[.*\]$ && "$value" =~ ^\".*\"$ ]]; then + key="${key#[}" + key="${key%]}" + value="${value#\"}" + value="${value%\"}" + servers["$key"]="$value" + else + echo "Error: invalid format in ${config}/servers.conf" >&2 + exit 1 + fi + done < <(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' "${config}/servers.conf") +fi # Server menu declare -a menuList