diff --git a/qnadmin b/qnadmin index a99607c..4654f9f 100755 --- a/qnadmin +++ b/qnadmin @@ -147,6 +147,180 @@ ModuleStatus () { fi } +GetModuleProcess () { + local nvar + process=$1 + nvar="n$process" + if [[ $process == 'mmdvm' ]]; then + process='relay' + fi + process="qn$process" + if [${!nvar} -gt 1 ]; then + process=${process}${1} + fi +} + +LogMenu () { + ans='' + while [[ "$ans" != q* ]]; do + clear + echo " Log Menu" + echo + echo "After starting a log, use -C to stop the log and return to this menu." + echo + if [[ $GateState == 'running' ]]; then + echo " g : qngateway Log" + else + echo " qngateway is not running" + fi + if [[ $LinkState == 'running' ]]; then + echo " l : qnlink Log" + else + echo " qnlink is not running" + fi + if [[ $DTMFState == 'running' ]]; then + echo " d : qndtmf Log" + else + echo " qndtmf is not running" + fi + if [[ ${ModuleState[0]} != 'EMPTY' ]]; then + GetModuleProcess $module_a + if [[ ${ModuleState[0]} == 'running' ]]; then + echo " a : $process Log" + else + echo " $process is not running" + fi + fi + if [[ ${ModuleState[1]} != 'EMPTY' ]]; then + GetModuleProcess $module_b + if [[ ${ModuleState[1]} == 'running' ]]; then + echo " b : $process Log" + else + echo " $process is not running" + fi + fi + if [[ ${ModuleState[2]} != 'EMPTY' ]]; then + GetModuleProcess $module_c + if [[ ${ModuleState[2]} == 'running' ]]; then + echo " c : $process Log" + else + echo " $process is not running" + fi + fi + echo + echo " q : quit and return to main menu" + echo + read -p "Command: " ans + + if [[ "$ans" == g* ]] && [[ "$GateState" == 'running' ]]; then + sudo journalctl -u qngateway -f + elif [[ "$ans" == l* ]] && [[ "$LinkState" == 'running' ]]; then + sudo journalctl -u qnlink -f + elif [[ "$ans" == d* ]] && [[ "$DTMFState" == 'running' ]]; then + sudo journalctl -u qndtmf -f + elif [[ "$ans" == a* ]] && [[ "${ModuleState[0]}" == 'running' ]]; then + GetModuleProcess $module_a + sudo journalctl -u $process -f + elif [[ "$ans" == b* ]] && [[ "${ModuleState[1]}" == 'running' ]]; then + GetModuleProcess $module_b + sudo journalctl -u $process -f + elif [[ "$ans" == c* ]] && [[ "${ModuleState[2]}" == 'running' ]]; then + GetModuleProcess $module_c + sudo journalctl -u $process -f + fi + + done +} + +MaintenanceMenu () { + local m n + ans='' + while [[ "$ans" != q* ]]; do + clear + echo " MaintenanceMenu" + echo + if [[ "$GateState" == 'running' ]]; then + echo " g : Stop QnetGateway" + elif [[ "$GateState" == 'stopped' ]]; then + echo " g : Start QnetGateway" + fi + if [[ "$LinkState" == 'running' ]]; then + echo " l : Stop QnetLink" + elif [[ "$LinkState" == 'stopped' ]]; then + echo " l : Start QnetLink" + fi + if [[ "$DTMFState" == 'running' ]]; then + echo " d : Stop DTMF" + elif [[ "$DTMFState" == 'stopped']]; then + echo " d : Start DTMF" + fi + if [[ "${ModuleState[0]}" == 'running' ]]; then + echo " a : Stop Module A" + elif [[ "${ModuleState[0]}" == 'stopped' ]]; then + echo " a : Start Module A" + fi + if [[ "${ModuleState[1]}" == 'running' ]]; then + echo " b : Stop Module B" + elif [[ "${ModuleState[1]}" == 'stopped' ]]; then + echo " b : Start Module B" + fi + if [[ "${ModuleState[2]}" == 'running' ]]; then + echo " c : Stop Module C" + elif [[ "${ModuleState[2]}" == 'stopped' ]]; then + echo " c : Start Module C" + fi + echo + echo " q : Return to main Menu" + echo + read -p "Command: " ans + + if [[ "$ans" == g* ]]; then + if [[ "$GateState" == 'running' ]]; then + sudo systemctl stop qngateway + elif [[ "$GateState" == 'stopped' ]] + sudo systemctl start qngateway + fi + elif [[ "$ans" == l* ]]; then + if [[ "$LinkState" == 'running' ]]; then + sudo systemctl stop qnlink + elif [[ "$LinkState" == 'stopped' ]] + sudo systemctl start qnlink + fi + elif [[ "$ans" == d* ]]; then + if [[ "$DTMFState" == 'running' ]]; then + sudo systemctl stop qndtmf + elif [[ "$DTMFState" == 'stopped' ]] + sudo systemctl start qndtmf + fi + elif [[ "$ans" == a* ]] && [ -n $module_a ]; then + GetModuleProcess $module_a + if [[ "${ModuleState[0]}" == 'running' ]]; then + sudo systemctl stop $process + elif [[ "${ModuleState[0]}" == 'stopped' ]]; then + sudo systemctl start $process + fi + ModuleState 0 a $module_a + elif [[ "$ans" == b* ]] && [ -n $module_b ]; then + GetModuleProcess $module_b + if [[ "${ModuleState[1]}" == 'running' ]]; then + sudo systemctl stop $process + elif [[ "${ModuleState[1]}" == 'stopped' ]]; then + sudo systemctl start $process + fi + ModuleState 1 b $module_b + elif [[ "$ans" == c* ]] && [ -n $module_c ]; then + GetModuleProcess $module_c + if [[ "${ModuleState[2]}" == 'running' ]]; then + sudo systemctl stop $process + elif [[ "${ModuleState[2]}" == 'stopped' ]]; then + sudo systemctl start $process + fi + ModuleState 2 c $module_c + fi + BaseState + done +} + # get defined modules from the config file if [ -e qn.cfg ]; then source <( grep "^module_[abc]=" qn.cfg ) @@ -227,6 +401,11 @@ while [[ "$ans" != q* ]]; do fi echo "c : Clean (remove temporary files and locally built executables)" echo + if [[ "$GateState" != 'not installed' ]] && [[ "$LinkState" != 'not installed' ]]; then + echo "m : Maintenance Menu" + echo "l : Log Menu" + fi + echo read -p "q to quit. Command: " ans # EXECUTE COMMANDS @@ -240,6 +419,10 @@ while [[ "$ans" != q* ]]; do sudo make uninstalldtmf elif [[ "$ans" == c* ]]; then make clean + elif [[ "$ans" == m* ]]; then + MaintenanceMenu + elif [[ "$ans" == l* ]]; then + LogMenu fi done