emq-TE1/menu/menu-fdmr

283 lines
9.8 KiB
Plaintext

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 ;;
2)
sudo nano /opt/FreeDMR/config/rules.py ;;
3)
sudo nano /opt/FDMR-Monitor/fdmr-mon.cfg ;;
4)
sudo nano /opt/FDMR-Monitor2/fdmr-mon.cfg ;;
5)
sudo nano /opt/wdp &&
variable1=$(grep "Web-Dashboar-Port:" /opt/wdp | grep -Eo '[A.0-9]{1,9}') &&
if [ -z "$variable1" ]
then variable1=80
fi &&
sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable1 -t \/var\/www\/fdmr\//g" /lib/systemd/system/http.server-fdmr.service &&
sudo sed -i "s/ExecStart=.*/ExecStart=php -S 0.0.0.0:$variable1 -t \/var\/www\/fdmr2\//g" /lib/systemd/system/http.server-fdmr2.service &&
systemctl daemon-reload &&
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 http.server-fdmr.service |grep "service; enabled;" >/dev/null 2>&1
then
sudo systemctl start http.server-fdmr.service
fi
if sudo systemctl status http.server-fdmr2.service |grep "service; enabled;" >/dev/null 2>&1
then
sudo systemctl start http.server-fdmr2.service
fi ;;
6)
if systemctl status mariadb.service |grep inactive >/dev/null 2>&1
then sudo systemctl start mariadb.service
fi
if systemctl status mariadb.service |grep disable >/dev/null 2>&1
then sudo systemctl enable mariadb.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
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
sudo systemctl start freedmr.service
sudo systemctl start fdmrparrot.service
sudo systemctl start proxy.service ;;
7)
if systemctl status fdmr_mon.service |grep disable >/dev/null 2>&1
then
sudo systemctl stop mariadb.service
sudo systemctl disable mariadb.service
fi
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 ;;
8)
(crontab -l; echo "* */1 * * * sync ; echo 3 > /proc/sys/vm/drop_caches >/dev/null 2>&1")|awk '!x[$0]++'|crontab -
cronedit.sh '*/5 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/graph.sh' add &&
cronedit.sh '*/2 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/cpu.sh' add &&
cronedit.sh '*/5 * * * *' 'sh /etc/freedmr/hbmon/sysinfo/graph.sh' remove &&
cronedit.sh '*/2 * * * *' 'sh /etc/freedmr/hbmon/sysinfo/cpu.sh' remove &&
cronedit.sh '* */24 * * *' 'rm /etc/freedmr/hbmon/data/*' remove &&
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor/data/*' add &&
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor2/data/*' remove
if systemctl status mariadb.service |grep inactive >/dev/null 2>&1
then sudo systemctl start mariadb.service
fi
if systemctl status mariadb.service |grep disable >/dev/null 2>&1
then sudo systemctl enable mariadb.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 http.server-fdmr.service | grep "service; enabled;" >/dev/null 2>&1; then
sudo systemctl enable http.server-fdmr.service
fi
if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1
then sudo systemctl disable fdmr_mon2.service
fi
if ! systemctl status fdmr_mon.service | grep "service; enabled;" >/dev/null 2>&1; then
sudo systemctl enable fdmr_mon.service
fi
if ! systemctl status proxy.service | grep "service; enabled;" >/dev/null 2>&1; then
sudo systemctl enable proxy.service
fi
#####################################
if systemctl status http.server-fdmr2.service |grep "active" >/dev/null 2>&1
then systemctl stop http.server-fdmr2.service
fi
if systemctl status http.server-fdmr.service |grep active >/dev/null 2>&1
then sudo systemctl stop http.server-fdmr.service
fi
if systemctl status fdmr_mon2.service |grep active >/dev/null 2>&1
then sudo systemctl stop fdmr_mon2.service
fi
if systemctl status fdmr_mon.service |grep active >/dev/null 2>&1
then sudo systemctl stop fdmr_mon.service
fi
if systemctl status proxy.service |grep "active" >/dev/null 2>&1
then sudo systemctl stop proxy.service
fi
sudo systemctl start proxy.service
sudo systemctl start fdmr_mon.service
sudo systemctl start http.server-fdmr.service ;;
9)
(crontab -l; echo "* */1 * * * sync ; echo 3 > /proc/sys/vm/drop_caches >/dev/null 2>&1")|awk '!x[$0]++'|crontab -
cronedit.sh '*/5 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/graph.sh' remove &&
cronedit.sh '*/2 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/cpu.sh' remove &&
cronedit.sh '*/5 * * * *' 'sh /etc/freedmr/hbmon/sysinfo/graph.sh' remove &&
cronedit.sh '*/2 * * * *' 'sh /etc/freedmr/hbmon/sysinfo/cpu.sh' remove &&
cronedit.sh '* */24 * * *' 'rm /etc/freedmr/hbmon/data/*' remove &&
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor/data/*' remove &&
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor2/data/*' add
if systemctl status mariadb.service |grep inactive >/dev/null 2>&1
then sudo systemctl start mariadb.service
fi
if systemctl status mariadb.service |grep disable >/dev/null 2>&1
then sudo systemctl enable mariadb.service
fi
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 enable 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 enable fdmr_mon2.service
fi
if ! systemctl status proxy.service | grep "service; enabled;" >/dev/null 2>&1; then
sudo systemctl enable proxy.service
fi
#####################################
if systemctl status http.server-fdmr.service |grep "active" >/dev/null 2>&1
then systemctl stop http.server-fdmr.service
fi
if systemctl status http.server-fdmr2.service |grep active >/dev/null 2>&1
then sudo systemctl stop http.server-fdmr2.service
fi
if systemctl status fdmr_mon.service |grep active >/dev/null 2>&1
then sudo systemctl stop fdmr_mon.service
fi
if systemctl status fdmr_mon2.service |grep active >/dev/null 2>&1
then sudo systemctl stop fdmr_mon2.service
fi
if systemctl status proxy.service |grep "active" >/dev/null 2>&1
then sudo systemctl stop proxy.service
fi
sudo systemctl start proxy.service
sudo systemctl start fdmr_mon2.service
sudo systemctl start http.server-fdmr2.service ;;
10)
cronedit.sh '*/5 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/graph.sh' remove
cronedit.sh '*/2 * * * *' 'sh /opt/FDMR-Monitor/sysinfo/cpu.sh' remove
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor/data/*' remove
cronedit.sh '* */24 * * *' 'rm /opt/FDMR-Monitor2/data/*' remove
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*