#!/bin/bash sudo cat > /bin/menu-fdmr <<- "EOF" #!/bin/bash if [[ $EUID -ne 0 ]]; then whiptail --title "sudo su" --msgbox "requiere ser usuario root , escriba (sudo su) antes de entrar a menu / requires root user, type (sudo su) before entering menu" 0 50 exit 0 fi while : ; do choix=$(whiptail --title "Raspbian Proyect HP3ICC FDMR+" --menu "move up or down with the keyboard arrows and select your option by pressing enter:" 23 56 13 \ 1 " Edit FreeDMR Server " \ 2 " Edit Interlink " \ 3 " Edit FDMR-Monitor OA4DOA " \ 4 " Edit FDMR-Monitor CS8ABG " \ 5 " Select Web Dashboard Port " \ 6 " Start-Restart FreeDMR Server " \ 7 " Stop FreeDMR SERVER " \ 8 " Select Dashboard OA4DOA" \ 9 " Select Dashboard CS8ABG" \ 10 " Stop Dashboard " \ 11 " D-APRS " \ 12 " Menu update " 3>&1 1>&2 2>&3) exitstatus=$? #on recupere ce choix #exitstatus=$? if [ $exitstatus = 0 ]; then echo "Your chosen option:" $choix else echo "You chose cancel."; break; fi # case : action en fonction du choix case $choix in 1) sudo nano /opt/FreeDMR/config/FreeDMR.cfg && if sudo systemctl status freedmr.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl restart freedmr.service fi;; 2) sudo nano /opt/FreeDMR/config/rules.py && if sudo systemctl status freedmr.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl restart freedmr.service fi ;; 3) sudo nano /opt/FDMR-Monitor/fdmr-mon.cfg ;; 4) sudo nano /opt/FDMR-Monitor2/fdmr-mon.cfg ;; 5) sudo nano /opt/wdp && if sudo systemctl status http.server-fdmr.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr.service fi && if sudo systemctl status http.server-fdmr2.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr2.service fi && variable80=$(grep "Web-Dashboar-Port:" /opt/wdp | grep -Eo '[A.0-9]{1,9}') if [ -z "$variable80" ] then variable80=80 fi sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr\//g" /lib/systemd/system/http.server-fdmr.service && sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr2\//g" /lib/systemd/system/http.server-fdmr2.service && systemctl daemon-reload && if sudo netstat -tuln | grep -q "0.0.0.0:$variable80"; then whiptail --title "Check Port" --msgbox "El puerto $variable80 esta ocupado , The port $variable80 is busy" 0 50 else if sudo systemctl status http.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl start http.server-fdmr.service else if sudo systemctl status http.server-fdmr2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl start http.server-fdmr2.service fi fi fi ;; 6) if ! systemctl status mariadb.service |grep "Active: active" >/dev/null 2>&1 then sudo systemctl restart mariadb.service fi if ! systemctl status mariadb.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl enable mariadb.service fi if systemctl status fdmrparrot.service |grep disable >/dev/null 2>&1 then sudo systemctl enable fdmrparrot.service fi if systemctl status proxy.service |grep disable >/dev/null 2>&1 then sudo systemctl enable proxy.service fi if systemctl status freedmr.service |grep disable >/dev/null 2>&1 then sudo systemctl enable freedmr.service fi if systemctl status fdmrparrot.service |grep active >/dev/null 2>&1 then sudo systemctl stop fdmrparrot.service fi if systemctl status proxy.service |grep active >/dev/null 2>&1 then sudo systemctl stop proxy.service fi if systemctl status freedmr.service |grep active >/dev/null 2>&1 then sudo systemctl stop freedmr.service fi sudo systemctl start freedmr.service sudo systemctl start fdmrparrot.service sudo systemctl start proxy.service ;; 7) sudo systemctl stop fdmrparrot.service sudo systemctl disable fdmrparrot.service sudo systemctl stop proxy.service sudo systemctl disable proxy.service sudo systemctl stop freedmr.service sudo systemctl disable freedmr.service # Verificar el estado del servicio mariadb.service if systemctl is-enabled mariadb.service | grep -q "disabled"; then echo "El servicio mariadb esta deshabilitado." else # Verificar el estado del servicio freedmr-fdmr.service if systemctl is-enabled freedmr.service | grep -q "enabled"; then echo "El servicio freedmr esta habilitado." else # Verificar el estado del servicio http.server-fdmr.service if systemctl is-enabled http.server-fdmr.service | grep -q "enabled"; then echo "El servicio http.server-fdmr esta habilitado." else # Verificar el estado del servicio http.server-fdmr2.service if systemctl is-enabled http.server-fdmr2.service | grep -q "enabled"; then echo "El servicio http.server-fdmr2 está habilitado." else # Si todo esta bien, deshabilitar el servicio mariadb.service systemctl disable mariadb.service systemctl stop mariadb.service echo "El servicio mariadb ha sido deshabilitado." fi fi fi fi ;; 8) if systemctl status http.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable http.server-fdmr.service fi if systemctl status http.server-fdmr2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable http.server-fdmr2.service fi if systemctl status fdmr_mon.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable fdmr_mon.service fi if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable fdmr_mon2.service fi if sudo systemctl status http.server-fdmr.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr.service fi if sudo systemctl status http.server-fdmr2.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr2.service fi if sudo systemctl status fdmr_mon.service |grep active >/dev/null 2>&1 then sudo systemctl stop fdmr_mon.service fi if sudo systemctl status fdmr_mon2.service |grep active >/dev/null 2>&1 then sudo systemctl stop fdmr_mon2.service fi variable80=$(grep "Web-Dashboar-Port:" /opt/wdp | grep -Eo '[A.0-9]{1,9}') if [ -z "$variable80" ] then variable80=80 fi sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr\//g" /lib/systemd/system/http.server-fdmr.service && sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr2\//g" /lib/systemd/system/http.server-fdmr2.service && systemctl daemon-reload && if sudo netstat -tuln | grep -q "0.0.0.0:$variable80"; then whiptail --title "Check Port" --msgbox "El puerto $variable80 esta ocupado , The port $variable80 is busy" 0 50 else (crontab -l; echo "* */1 * * * sync ; echo 3 > /proc/sys/vm/drop_caches >/dev/null 2>&1")|awk '!x[$0]++'|crontab - (crontab -l; echo "* */24 * * * rm /opt/FDMR-Monitor/data/*")|awk '!x[$0]++'|crontab - (crontab -l; echo "*/2 * * * * sh /opt/FDMR-Monitor/sysinfo/cpu.sh")|awk '!x[$0]++'|crontab - (crontab -l; echo "*/5 * * * * sh /opt/FDMR-Monitor/sysinfo/graph.sh")|awk '!x[$0]++'|crontab - (crontab -l | grep -v "sh /etc/freedmr/hbmon/sysinfo/cpu.sh") | crontab - (crontab -l | grep -v "sh /etc/freedmr/hbmon/sysinfo/graph.sh") | crontab - (crontab -l | grep -v "rm /etc/freedmr/hbmon/data/*") | crontab - (crontab -l | grep -v "rm /opt/FDMR-Monitor2/data/*") | crontab - if ! systemctl status mariadb.service |grep "Active: active" >/dev/null 2>&1 then sudo systemctl restart mariadb.service fi if ! systemctl status mariadb.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl enable mariadb.service fi if ! systemctl status proxy.service | grep "service; enabled;" >/dev/null 2>&1; then sudo systemctl enable proxy.service fi if ! systemctl status proxy.service | grep "Active: active" >/dev/null 2>&1; then sudo systemctl restart proxy.service fi ##################################### rm /opt/FDMR-Monitor/data/* mysql -u root -e "DROP TABLE IF EXISTS selfcare.last_heard;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.lstheard_log;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.peer_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.subscriber_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.talkgroup_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.tg_count;" cd /opt/FDMR-Monitor python3 mon_db.py --create && python3 mon_db.py --update sudo systemctl start fdmr_mon.service sudo systemctl enable fdmr_mon.service sudo systemctl start http.server-fdmr.service sudo systemctl enable http.server-fdmr.service fi ;; 9) if systemctl status http.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable http.server-fdmr.service fi if systemctl status http.server-fdmr2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable http.server-fdmr2.service fi if systemctl status fdmr_mon.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable fdmr_mon.service fi if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl disable fdmr_mon2.service fi if sudo systemctl status http.server-fdmr.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr.service fi if sudo systemctl status http.server-fdmr2.service |grep active >/dev/null 2>&1 then sudo systemctl stop http.server-fdmr2.service fi if sudo systemctl status fdmr_mon.service |grep active >/dev/null 2>&1 then sudo systemctl stop fdmr_mon.service fi if sudo systemctl status fdmr_mon2.service |grep active >/dev/null 2>&1 then sudo systemctl stop fdmr_mon2.service fi variable80=$(grep "Web-Dashboar-Port:" /opt/wdp | grep -Eo '[A.0-9]{1,9}') if [ -z "$variable80" ] then variable80=80 fi sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr\//g" /lib/systemd/system/http.server-fdmr.service && sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable80 -t \/var\/www\/fdmr2\//g" /lib/systemd/system/http.server-fdmr2.service && systemctl daemon-reload && if sudo netstat -tuln | grep -q "0.0.0.0:$variable80"; then whiptail --title "Check Port" --msgbox "El puerto $variable80 esta ocupado , The port $variable80 is busy" 0 50 else (crontab -l; echo "* */1 * * * sync ; echo 3 > /proc/sys/vm/drop_caches >/dev/null 2>&1")|awk '!x[$0]++'|crontab - (crontab -l; echo "* */24 * * * rm /opt/FDMR-Monitor2/data/*")|awk '!x[$0]++'|crontab - (crontab -l | grep -v "rm /opt/FDMR-Monitor/data/*") | crontab - (crontab -l | grep -v "rm /etc/freedmr/hbmon/data/*") | crontab - (crontab -l | grep -v "sh /etc/freedmr/hbmon/sysinfo/cpu.sh") | crontab - (crontab -l | grep -v "sh /etc/freedmr/hbmon/sysinfo/graph.sh") | crontab - (crontab -l | grep -v "sh /opt/FDMR-Monitor/sysinfo/cpu.sh") | crontab - (crontab -l | grep -v "sh /opt/FDMR-Monitor/sysinfo/graph.sh") | crontab - if ! systemctl status mariadb.service |grep "Active: active" >/dev/null 2>&1 then sudo systemctl restart mariadb.service fi if ! systemctl status mariadb.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl enable mariadb.service fi if ! systemctl status proxy.service | grep "service; enabled;" >/dev/null 2>&1; then sudo systemctl enable proxy.service fi if ! systemctl status proxy.service | grep "Active: active" >/dev/null 2>&1; then sudo systemctl restart proxy.service fi ##################################### rm /opt/FDMR-Monitor2/data/* mysql -u root -e "DROP TABLE IF EXISTS selfcare.last_heard;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.lstheard_log;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.peer_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.subscriber_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.talkgroup_ids;" && mysql -u root -e "DROP TABLE IF EXISTS selfcare.tg_count;" cd /opt/FDMR-Monitor2 python3 mon_db.py --create && python3 mon_db.py --update sudo systemctl start fdmr_mon2.service sudo systemctl enable fdmr_mon2.service sudo systemctl start http.server-fdmr2.service sudo systemctl enable http.server-fdmr2.service fi ;; 10) (crontab -l | grep -v "rm /opt/FDMR-Monitor2/data/*") | crontab - (crontab -l | grep -v "rm /opt/FDMR-Monitor/data/*") | crontab - (crontab -l | grep -v "sh /opt/FDMR-Monitor/sysinfo/cpu.sh") | crontab - (crontab -l | grep -v "sh /opt/FDMR-Monitor/sysinfo/graph.sh") | crontab - sudo systemctl stop fdmr_mon2.service sudo systemctl disable fdmr_mon2.service sudo systemctl stop http.server-fdmr2.service sudo systemctl disable http.server-fdmr2.service sudo systemctl stop fdmr_mon.service sudo systemctl disable fdmr_mon.service sudo systemctl stop http.server-fdmr.service sudo systemctl disable http.server-fdmr.service # Verificar el estado del servicio mariadb.service if systemctl is-enabled mariadb.service | grep -q "disabled"; then echo "El servicio mariadb está deshabilitado." else # Verificar el estado del servicio freedmr-fdmr.service if systemctl is-enabled freedmr.service | grep -q "enabled"; then echo "El servicio freedmr está habilitado." else # Verificar el estado del servicio http.server-fdmr.service if systemctl is-enabled http.server-fdmr.service | grep -q "enabled"; then echo "El servicio http.server-fdmr está habilitado." else # Verificar el estado del servicio http.server-fdmr2.service if systemctl is-enabled http.server-fdmr2.service | grep -q "enabled"; then echo "El servicio http.server-fdmr2 está habilitado." else # Si todo está bien, deshabilitar el servicio mariadb.service systemctl disable mariadb.service systemctl stop mariadb.service echo "El servicio mariadb ha sido deshabilitado." fi fi fi fi ;; 11) menu-igate ;; 12) bash -c "$(curl -fsSL https://gitlab.com/hp3icc/fdmr/-/raw/main/update.sh)"; esac done exit 0 EOF ################ sudo chmod +x /bin/menu* ln -sf /bin/menu-fdmr /bin/MENU-FDMR chmod +x /bin/MENU*