diff --git a/tojam b/tojam index 185a224..01d7198 100755 --- a/tojam +++ b/tojam @@ -22,6 +22,7 @@ help() { # Array of command line arguments declare -A command=( [c]="Configure ${0##*/}." + [D]="Delete a server." [h]="This help screen." [T]="Dedication." ) @@ -72,24 +73,35 @@ add_server() { } -settings() { - echo "Settings coming soon" +delete_server() { + # Get servers into an array. + mapfile -t lines < "${config}/servers.conf" + for i in "${lines[@]}" ; do + j="${i#\[}" + j="${j/\]=\"/: }" + j="${j%\"}" + menuList+=("$i" "${j}") + done + server="$(dialog --clear \ + --backtitle "Tojam" \ + --no-tags \ + --ok-label "Delete" \ + --menu "Select a Ninjam server to be deleted" -1 -1 -1 "${menuList[@]}" --stdout)" + menuCode=$? + if [ ${menuCode} -eq 1 -o ${menuCode} -eq 255 ]; then + exit 0 + fi + tmpFile="$(mktemp -t XXXXXX)" + grep -vF "$server" "${config}/servers.conf" > "${tmpFile}" || exit 3 + mv "${tmpFile}" "${config}/servers.conf" || exit 4 + dialog --msgbox "Server deleted." -1 -1 + exit 0 } -# Convert the keys of the associative array to a format usable by getopts -args="${!command[*]}" -args="${args//[[:space:]]/}" -while getopts "${args}" i ; do - case "$i" in - c) echo "Coming soon" ;; - h) help ;; - T) - echo "For Tony, because he's awesome!" - exit 0 - ;; - esac -done +settings() { + echo "Settings coming soon" +} # Configuration stuff @@ -118,6 +130,22 @@ else fi +# Convert the keys of the associative array to a format usable by getopts +args="${!command[*]}" +args="${args//[[:space:]]/}" +while getopts "${args}" i ; do + case "$i" in + c) echo "Coming soon" ;; + D) delete_server ;; + h) help ;; + T) + echo "For Tony, because he's awesome!" + exit 0 + ;; + esac +done + + declare -A servers=( [Ninjamer 1]="ninjamer.com" [Ninjamer 2]="ninjamer.com:2050"