From 2db60266a50f043721420f324e634e2c898ba194 Mon Sep 17 00:00:00 2001 From: hp3icc Date: Thu, 9 Oct 2025 20:39:04 -0500 Subject: [PATCH] 3dash 3dash --- easy-fdmr.sh | 21 --- install.sh | 119 +++++++++----- update.sh | 446 +++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 422 insertions(+), 164 deletions(-) diff --git a/easy-fdmr.sh b/easy-fdmr.sh index 3d4ca68..1e43523 100644 --- a/easy-fdmr.sh +++ b/easy-fdmr.sh @@ -121,27 +121,6 @@ echo "Instalación completa." # Configuración adicional (timezone, cron, etc.) sudo timedatectl set-timezone America/Panama -# Crear script para editar cronjobs -cat > /usr/local/bin/cronedit.sh <<- "EOF" -cronjob_editor () { -# usage: cronjob_editor '' '' - -if [[ -z "$1" ]] ;then printf " no interval specified\n" ;fi -if [[ -z "$2" ]] ;then printf " no command specified\n" ;fi -if [[ -z "$3" ]] ;then printf " no action specified\n" ;fi - -if [[ "$3" == add ]] ;then - # add cronjob, no duplication: - ( sudo crontab -l | grep -v -F -w "$2" ; echo "$1 $2" ) | sudo crontab - -elif [[ "$3" == remove ]] ;then - # remove cronjob: - ( sudo crontab -l | grep -v -F -w "$2" ) | sudo crontab - -fi -} -cronjob_editor "$1" "$2" "$3" -EOF -sudo chmod +x /usr/local/bin/cronedit.sh - ####### bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/install/rpiswap.sh)" && bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/install/nginx.sh)" && diff --git a/install.sh b/install.sh index 3006693..bd8e326 100644 --- a/install.sh +++ b/install.sh @@ -25,31 +25,6 @@ else fi ####### cd / -###################################################################################################################### -# Cronedit -###################################################################################################################### -sudo cat > /usr/local/bin/cronedit.sh <<- "EOF" -#!/bin/bash -cronjob_editor () { -# usage: cronjob_editor '' '' - -if [[ -z "$1" ]] ;then printf " no interval specified\n" ;fi -if [[ -z "$2" ]] ;then printf " no command specified\n" ;fi -if [[ -z "$3" ]] ;then printf " no action specified\n" ;fi - -if [[ "$3" == add ]] ;then - # add cronjob, no duplication: - ( sudo crontab -l | grep -v -F -w "$2" ; echo "$1 $2" ) | sudo crontab - -elif [[ "$3" == remove ]] ;then - # remove cronjob: - ( sudo crontab -l | grep -v -F -w "$2" ) | sudo crontab - -fi -} -cronjob_editor "$1" "$2" "$3" - - -EOF -sudo chmod +x /usr/local/bin/cronedit.sh if [ -f "/var/www/html/tgcount.php" ]; then @@ -244,8 +219,7 @@ check_and_install() { for app in $apps; do check_and_install $app done -sudo systemctl restart mariadb && -sudo systemctl enable mariadb + #sudo mysql_secure_installation --host=localhost --port=3306 #echo "DROP USER emqte1@localhost" | /usr/bin/mysql -u root #echo "DROP DATABASE selfcare" | /usr/bin/mysql -u root @@ -263,6 +237,9 @@ host=localhost commands="CREATE DATABASE IF NOT EXISTS \`${newDb}\`;CREATE USER IF NOT EXISTS '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}';GRANT ALL ON \`${newDb}\`.* TO '${newUser}'@'${host}';FLUSH PRIVILEGES;" #cho "${commands}" | /usr/bin/mysql -u root -p +if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service +fi echo "${commands}" | /usr/bin/mysql -u root ################# #FDMR Server @@ -477,7 +454,7 @@ bash -c "$(curl -fsSLk https://raw.githubusercontent.com/hp3icc/D-APRS/main/emq- ######### sudo cat > /lib/systemd/system/adn-server.service <<- "EOF" [Unit] -Description=FreeDmr +Description=ADN Server After=multi-user.target [Service] @@ -651,23 +628,93 @@ WantedBy=multi-user.target EOF # -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 +systemctl daemon-reload -fi if [ -f "mon.db" ] then rm mon.db fi -cd /opt/FDMR-Monitor2 +#cd /opt/FDMR-Monitor2 #python3 mon_db.py --create #python3 mon_db.py --update +if ! systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 && \ + ! systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service 2>/dev/null + fi +fi +#################################################################### +#monitor3 +if [ -f "/opt/adn-dashboard/html/db/dashboard.db" ]; then + cp /opt/adn-dashboard/html/db/dashboard.db /opt/dashboard.db +fi +if [ -d "/opt/adn-dashboard" ]; then + rm -r /opt/adn-dashboard +fi +cd /opt +git clone https://github.com/Amateur-Digital-Network/ADN-Dashboard.git adn-dashboard +cp /opt/adn-dashboard/proxy/proxy_SAMPLE.cfg /opt/adn-dashboard/proxy/proxy.cfg +cp /opt/adn-dashboard/dashboard_SAMPLE.cfg /opt/adn-dashboard/dashboard.cfg + +sed -i "s|LASTHEARD_ROWS.*|LASTHEARD_ROWS = 20|g" /opt/adn-dashboard/dashboard.cfg +sed -i "s|TGCOUNT_ROWS.*|TGCOUNT_ROWS = 20|g" /opt/adn-dashboard/dashboard.cfg + +if [ -f "/opt/dashboard.db" ]; then + cp /opt/dashboard.db /opt/adn-dashboard/html/db/dashboard.db +fi +if [ ! -f "/opt/adn-dashboard/html/db/dashboard.db" ]; then + cd /opt/adn-dashboard/ + python3 dash_db.py +fi +chmod 777 /opt/adn-dashboard/html/db/dashboard.db +chown -R www-data:www-data /opt/adn-dashboard/html +############################################################## +# service update +############################################################ + +cat > /lib/systemd/system/fdmr_mon3.service <<- "EOF" +[Unit] +Description=ADN Monitor3 +# To make the network-online.target available +# systemctl enable systemd-networkd-wait-online.service +#After=network-online.target syslog.target +#Wants=network-online.target + +[Service] +User=root +Type=simple +Restart=always +RestartSec=3 +StandardOutput=null +WorkingDirectory=/opt/adn-dashboard +ExecStart=python3 /opt/adn-dashboard/dashboard.py +#Restart=on-abort +#Restart=on-failure + +[Install] +WantedBy=multi-user.target + +EOF +# +sudo cat > /lib/systemd/system/proxy2.service <<- "EOF" +[Unit] +Description=ADN Server Proxy +After=multi-user.target + +[Service] +StandardOutput=null +WorkingDirectory=/opt/adn-dashboard +RestartSec=3 +ExecStart=/usr/bin/python3 /opt/adn-dashboard/proxy/hotspot_proxy_v2.py -c /opt/adn-dashboard/proxy/proxy.cfg +Restart=on-failure + +[Install] +WantedBy=multi-user.target + +EOF ############################# sudo systemctl daemon-reload diff --git a/update.sh b/update.sh index 839771b..b3fb8dc 100644 --- a/update.sh +++ b/update.sh @@ -72,6 +72,21 @@ else ###################################################################### +EOF +# +fi +if [ -f "/opt/extra-4.sh" ] +then + echo "found file" +else + sudo cat > /opt/extra-4.sh <<- "EOF" +#!/bin/bash +###################################################################### +# Coloque en este archivo, cualquier instruccion shell adicional que # +# quierre se realice al finalizar la actualizacion. # +###################################################################### + + EOF # fi @@ -87,11 +102,12 @@ fi while : ; do choix=$(whiptail --title "Script proyect HP3ICC / update FDMR+" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. -" 17 50 4 \ +" 17 50 5 \ 1 " Update ADN-Server " \ -2 " Update FDMR-Monitor OA4DOA " \ -3 " Update FDMR-Monitor CS8ABG " \ -4 " Menu Principal " 3>&1 1>&2 2>&3) +2 " Update Monitor OA4DOA " \ +3 " Update Monitor CS8ABG " \ +4 " Update Monitor CS8ABG Map " \ +5 " Menu Principal " 3>&1 1>&2 2>&3) exitstatus=$? #on recupere ce choix #exitstatus=$? @@ -109,6 +125,8 @@ menu-up-fdmon ;; 3) menu-up-fdmon2 ;; 4) +menu-up-fdmon3 ;; +5) break; esac done @@ -164,10 +182,10 @@ if [[ $EUID -ne 0 ]]; then fi while : ; do -choix=$(whiptail --title "Script proyect HP3ICC / update FDMR-Monitor OA4DOA" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. +choix=$(whiptail --title "Script proyect HP3ICC / update Monitor OA4DOA" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. " 17 50 4 \ 1 " shell extra " \ -2 " Iniciar Actualizacion FDMR-Monitor OA4DOA " \ +2 " Iniciar Actualizacion Monitor OA4DOA " \ 3 " Menu Principal " 3>&1 1>&2 2>&3) exitstatus=$? #on recupere ce choix @@ -199,10 +217,10 @@ if [[ $EUID -ne 0 ]]; then fi while : ; do -choix=$(whiptail --title "Script proyect HP3ICC / update FDMR-Monitor CS8ABG" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. +choix=$(whiptail --title "Script proyect HP3ICC / update Monitor CS8ABG" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. " 17 50 4 \ 1 " shell extra " \ -2 " Iniciar Actualizacion FDMR-Monitor CS8ABG" \ +2 " Iniciar Actualizacion Monitor CS8ABG" \ 3 " Menu Principal " 3>&1 1>&2 2>&3) exitstatus=$? #on recupere ce choix @@ -226,11 +244,51 @@ exit 0 EOF +sudo cat > /bin/menu-up-fdmon3 <<- "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 "Script proyect HP3ICC / update Monitor CS8ABG Map" --menu "Nota Importante: antes de iniciar la actualizacion, el proceso de actualizacion borrara por completo todas las configuraciones, al finalizar la actualizacion el servicio se reinniciara automaticamente. +" 17 50 4 \ +1 " shell extra " \ +2 " Iniciar Actualizacion Monitor CS8ABG Map" \ +3 " Menu Principal " 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/extra-4.sh && chmod +x /opt/extra* ;; +2) +sudo /opt/monitor-update3.sh ;; +3) +break; +esac +done +exit 0 + + +EOF ######################################### ADN-Server Update ############################################################### sudo cat > /opt/fdmr-update.sh <<- "EOFD1" #!/bin/bash #"libapache2-mod-php" + +sudo systemctl stop adn-server.service 2>/dev/null || true +sudo systemctl stop adn-parrot.service 2>/dev/null || true +sudo systemctl stop proxy.service 2>/dev/null || true +sudo systemctl stop proxy2.service 2>/dev/null || true + apps="mariadb-server php php-zip php-mbstring php-cli php-common php-curl php-xml php-mysql" # Función para verificar e instalar una aplicación @@ -249,8 +307,7 @@ check_and_install() { for app in $apps; do check_and_install $app done -sudo systemctl restart mariadb && -sudo systemctl enable mariadb + #sudo mysql_secure_installation --host=localhost --port=3306 #echo "DROP USER emqte1@localhost" | /usr/bin/mysql -u root #echo "DROP DATABASE selfcare" | /usr/bin/mysql -u root @@ -268,6 +325,11 @@ host=localhost commands="CREATE DATABASE IF NOT EXISTS \`${newDb}\`;CREATE USER IF NOT EXISTS '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}';GRANT ALL ON \`${newDb}\`.* TO '${newUser}'@'${host}';FLUSH PRIVILEGES;" #cho "${commands}" | /usr/bin/mysql -u root -p +#echo "${commands}" | /usr/bin/mysql -u root + +if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service +fi echo "${commands}" | /usr/bin/mysql -u root ############### @@ -485,33 +547,53 @@ else fi sh /opt/extra-1.sh sudo systemctl daemon-reload -sudo systemctl start proxy.service -sudo systemctl start adn-server.service -sudo systemctl start adn-parrot.service -sudo systemctl enable proxy.service -sudo systemctl enable adn-server.service -sudo systemctl enable adn-parrot.service + +if systemctl status adn-server.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl start adn-server.service +fi +if systemctl status adn-parrot.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl start adn-parrot.service +fi +if systemctl status proxy.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl start proxy.service +fi +if systemctl status proxy2.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl start proxy2.service +fi if systemctl status fdmr_mon.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl stop fdmr_mon.service sudo systemctl start fdmr_mon.service - fi if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl stop fdmr_mon2.service sudo systemctl start fdmr_mon2.service - +fi +if systemctl status fdmr_mon3.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl stop fdmr_mon3.service + sudo systemctl start fdmr_mon3.service fi ###### -bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/menu/menu-fdmr)" + if [ -d "/opt/D-APRS" ] then echo "found file" else bash -c "$(curl -fsSLk https://raw.githubusercontent.com/hp3icc/D-APRS/main/emq-daprs.sh)" fi - +if ! systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 && \ + ! systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service 2>/dev/null + fi +fi EOFD1 sudo chmod +x /opt/fdmr-update.sh ######################################### FDMR-Monitor Update ############################################################### @@ -555,8 +637,8 @@ for servicio in $SERVICIOS; do echo "El servicio $servicio no existe." fi done -sudo systemctl stop fdmr_mon2.service -sudo systemctl stop fdmr_mon.service + +sudo systemctl stop fdmr_mon.service 2>/dev/null || true ############################################################## # service update @@ -564,7 +646,7 @@ sudo systemctl stop fdmr_mon.service cat > /lib/systemd/system/fdmr_mon.service <<- "EOF" [Unit] -Description=FDMR Monitor +Description=ADN Monitor # To make the network-online.target available # systemctl enable systemd-networkd-wait-online.service #After=network-online.target syslog.target @@ -595,8 +677,6 @@ fi ######################### #lamp -systemctl restart mariadb -systemctl enable mariadb #sudo mysql_secure_installation --host=localhost --port=3306 #echo "DROP USER emqte1@localhost" | /usr/bin/mysql -u root #echo "DROP DATABASE selfcare" | /usr/bin/mysql -u root @@ -614,6 +694,11 @@ host=localhost commands="CREATE DATABASE IF NOT EXISTS \`${newDb}\`;CREATE USER IF NOT EXISTS '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}';GRANT ALL ON \`${newDb}\`.* TO '${newUser}'@'${host}';FLUSH PRIVILEGES;" #cho "${commands}" | /usr/bin/mysql -u root -p +#echo "${commands}" | /usr/bin/mysql -u root + +if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service +fi echo "${commands}" | /usr/bin/mysql -u root DATABASE_NAME="selfcare" @@ -629,6 +714,7 @@ if [ "$CHECK_DB" ]; then mysql -u root -e "DROP DATABASE IF EXISTS selfcare;" rm hbmon.sql fi + ###FDMR-Monitor cd /opt #sudo git clone https://github.com/yuvelq/FDMR-Monitor.git @@ -772,13 +858,19 @@ chmod +x /opt/FDMR-Monitor/sysinfo/* systemctl daemon-reload && ############## -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 - +if systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 || \ + systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service + fi + if ! systemctl is-enabled --quiet mariadb.service 2>/dev/null; then + sudo systemctl enable mariadb.service + fi +else + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service + fi fi if systemctl status fdmr_mon.service |grep "service; enabled;" >/dev/null 2>&1 then @@ -795,18 +887,8 @@ then (crontab -l; echo "*/2 * * * * bash /opt/FDMR-Monitor/sysinfo/cpu.sh") | awk '!x[$0]++' | crontab - (crontab -l; echo "*/5 * * * * bash /opt/FDMR-Monitor/sysinfo/graph.sh") | awk '!x[$0]++' | crontab - (crontab -l | grep -v "rm /opt/FDMR-Monitor2/data/*") | crontab - - fi -if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1 -then - sudo systemctl stop fdmr_mon2.service - sudo systemctl start fdmr_mon2.service - (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 "/opt/FDMR-Monitor/sysinfo/cpu.sh") | crontab - - (crontab -l | grep -v "/opt/FDMR-Monitor/sysinfo/graph.sh") | crontab - -fi ############## sh /opt/extra-2.sh @@ -819,6 +901,8 @@ then fi sudo systemctl restart nginx + + EOFB1 sudo chmod +x /opt/monitor-update.sh ######################################### FDMR-Monitor2 Update ############################################################### @@ -855,8 +939,8 @@ for servicio in $SERVICIOS; do echo "El servicio $servicio no existe." fi done -sudo systemctl stop fdmr_mon.service -sudo systemctl stop fdmr_mon2.service + +sudo systemctl stop fdmr_mon2.service 2>/dev/null || true ############################################################## # service update @@ -879,8 +963,7 @@ then fi ######################### #lamp -systemctl restart mariadb -systemctl enable mariadb + #sudo mysql_secure_installation --host=localhost --port=3306 #echo "DROP USER emqte1@localhost" | /usr/bin/mysql -u root #echo "DROP DATABASE selfcare" | /usr/bin/mysql -u root @@ -898,6 +981,11 @@ host=localhost commands="CREATE DATABASE IF NOT EXISTS \`${newDb}\`;CREATE USER IF NOT EXISTS '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}';GRANT ALL ON \`${newDb}\`.* TO '${newUser}'@'${host}';FLUSH PRIVILEGES;" #cho "${commands}" | /usr/bin/mysql -u root -p +#echo "${commands}" | /usr/bin/mysql -u root + +if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service +fi echo "${commands}" | /usr/bin/mysql -u root DATABASE_NAME="selfcare" @@ -913,6 +1001,7 @@ if [ "$CHECK_DB" ]; then mysql -u root -e "DROP DATABASE IF EXISTS selfcare;" rm hbmon.sql fi + ################# cd /opt git clone https://gitlab.com/hp3icc/FDMR-Monitor2.git @@ -971,7 +1060,7 @@ mv /opt/FDMR-Monitor2/utils/logrotate/fdmr_mon /opt/FDMR-Monitor2/utils/logrotat mv /opt/FDMR-Monitor2/utils/systemd/fdmr_mon.service /opt/FDMR-Monitor2/utils/systemd/fdmr_mon2.service # \ sed -i "s/\/.*/\/opt\/FDMR-Monitor2\/log\/fdmr-mon.log {/g" /opt/FDMR-Monitor2/utils/logrotate/fdmr_mon2 -sed -i "s/Description=.*/Description=FDMR Monitor2/g" /opt/FDMR-Monitor2/utils/systemd/fdmr_mon2.service +sed -i "s/Description=.*/Description=ADN Monitor2/g" /opt/FDMR-Monitor2/utils/systemd/fdmr_mon2.service sed -i "s/WorkingDirectory=.*/WorkingDirectory=\/opt\/FDMR-Monitor2/g" /opt/FDMR-Monitor2/utils/systemd/fdmr_mon2.service sed -i "s/ExecStart=.*/ExecStart=python3 \/opt\/FDMR-Monitor2\/monitor.py/g" /opt/FDMR-Monitor2/utils/systemd/fdmr_mon2.service @@ -984,7 +1073,7 @@ sudo cp /opt/FDMR-Monitor2/utils/logrotate/fdmr_mon2 /etc/logrotate.d/fdmr_mon2 cat > /lib/systemd/system/fdmr_mon2.service <<- "EOF" [Unit] -Description=FDMR Monitor2 +Description=ADN Monitor2 # To make the network-online.target available # systemctl enable systemd-networkd-wait-online.service #After=network-online.target syslog.target @@ -1007,13 +1096,19 @@ WantedBy=multi-user.target EOF # systemctl daemon-reload -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 - +if systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 || \ + systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service + fi + if ! systemctl is-enabled --quiet mariadb.service 2>/dev/null; then + sudo systemctl enable mariadb.service + fi +else + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service + fi fi if [ -f "mon.db" ] then @@ -1032,31 +1127,21 @@ python3 mon_db.py --update sudo systemctl daemon-reload && ##################################### -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 - +if systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 || \ + systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service + fi + if ! systemctl is-enabled --quiet mariadb.service 2>/dev/null; then + sudo systemctl enable mariadb.service + fi +else + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service + fi fi -if systemctl status fdmr_mon.service |grep "service; enabled;" >/dev/null 2>&1 -then - sudo systemctl stop fdmr_mon.service - sudo systemctl start fdmr_mon.service - bash /opt/FDMR-Monitor/sysinfo/rrd-db.sh - sleep 1 - bash /opt/FDMR-Monitor/sysinfo/cpu.sh - sleep 1 - bash /opt/FDMR-Monitor/sysinfo/graph.sh - (crontab -l | grep -v "/opt/FDMR-Monitor/sysinfo/cpu.sh") | crontab - - (crontab -l | grep -v "/opt/FDMR-Monitor/sysinfo/graph.sh") | crontab - - (crontab -l; echo "* */24 * * * rm /opt/FDMR-Monitor/data/*") | awk '!x[$0]++' | crontab - - (crontab -l; echo "*/2 * * * * bash /opt/FDMR-Monitor/sysinfo/cpu.sh") | awk '!x[$0]++' | crontab - - (crontab -l; echo "*/5 * * * * bash /opt/FDMR-Monitor/sysinfo/graph.sh") | awk '!x[$0]++' | crontab - - (crontab -l | grep -v "rm /opt/FDMR-Monitor2/data/*") | crontab - -fi if systemctl status fdmr_mon2.service |grep "service; enabled;" >/dev/null 2>&1 then sudo systemctl stop fdmr_mon2.service @@ -1078,55 +1163,202 @@ then fi sudo systemctl restart nginx + EOFB2 sudo chmod +x /opt/monitor-update2.sh -###################################################################################################################### -# Cronedit -###################################################################################################################### -sudo cat > /usr/local/bin/cronedit.sh <<- "EOFC1" +# +######################################### FDMR-Monitor2 Update ############################################################### +sudo cat > /opt/monitor-update3.sh <<- "EOFC2" #!/bin/bash -cronjob_editor () { -# usage: cronjob_editor '' '' +# Verificar si el usuario tiene permisos de root +if [[ $EUID -ne 0 ]]; then + echo "Este script debe ejecutarse como usuario ROOT" + exit 1 +fi +if ! grep -q "Web-Dashboar-name: adn" "/opt/wdp" > /dev/null 2>&1; then + sed -i "s|Web-Dashboar-name:.*|Web-Dashboar-name: adn|g" /opt/wdp +fi +############## +SERVICIOS="adn_dashboard.service apache2.service" -if [[ -z "$1" ]] ;then printf " no interval specified\n" ;fi -if [[ -z "$2" ]] ;then printf " no command specified\n" ;fi -if [[ -z "$3" ]] ;then printf " no action specified\n" ;fi +for servicio in $SERVICIOS; do + # Verificar si el servicio existe + if systemctl list-unit-files --type=service | grep -q "^$servicio "; then + echo "El servicio $servicio existe." -if [[ "$3" == add ]] ;then - # add cronjob, no duplication: - ( sudo crontab -l | grep -v -F -w "$2" ; echo "$1 $2" ) | sudo crontab - -elif [[ "$3" == remove ]] ;then - # remove cronjob: - ( sudo crontab -l | grep -v -F -w "$2" ) | sudo crontab - -fi + # Verificar si el servicio está activo + if systemctl is-active --quiet $servicio; then + echo "El servicio $servicio está activo. Deteniendo..." + sudo systemctl stop $servicio + else + echo "El servicio $servicio no está activo." + fi + + # Deshabilitar el servicio + echo "Deshabilitando el servicio $servicio..." + sudo systemctl disable $servicio + else + echo "El servicio $servicio no existe." + fi +done + +sudo systemctl stop fdmr_mon3.service 2>/dev/null || true + +############################################################## +# monitor3 update +############################################################ +apps="php-sqlite3" + +# Función para verificar e instalar una aplicación +check_and_install() { + app=$1 + if ! dpkg -s $app 2>/dev/null | grep -q "Status: install ok installed"; then + echo "$app no está instalado. Instalando..." + DEBIAN_FRONTEND=noninteractive apt-get install -y $app || true + if dpkg -s $app 2>/dev/null | grep -q "Status: install ok installed"; then + echo "$app instalado correctamente." + else + echo "No se pudo instalar $app. Continuando con la siguiente aplicación..." + fi + else + echo "$app ya está instalado." + fi } -cronjob_editor "$1" "$2" "$3" +# Verificar e instalar cada aplicación +for app in $apps; do + check_and_install $app +done + +if [ -f "/opt/adn-dashboard/html/db/dashboard.db" ]; then + cp /opt/adn-dashboard/html/db/dashboard.db /opt/dashboard.db +fi +if [ -d "/opt/adn-dashboard" ]; then + rm -r /opt/adn-dashboard +fi +cd /opt +git clone https://github.com/Amateur-Digital-Network/ADN-Dashboard.git adn-dashboard +cp /opt/adn-dashboard/proxy/proxy_SAMPLE.cfg /opt/adn-dashboard/proxy/proxy.cfg +cp /opt/adn-dashboard/dashboard_SAMPLE.cfg /opt/adn-dashboard/dashboard.cfg + +sed -i "s|LASTHEARD_ROWS.*|LASTHEARD_ROWS = 20|g" /opt/adn-dashboard/dashboard.cfg +sed -i "s|TGCOUNT_ROWS.*|TGCOUNT_ROWS = 20|g" /opt/adn-dashboard/dashboard.cfg + +if [ -f "/opt/dashboard.db" ]; then + cp /opt/dashboard.db /opt/adn-dashboard/html/db/dashboard.db +fi +if [ ! -f "/opt/adn-dashboard/html/db/dashboard.db" ]; then + cd /opt/adn-dashboard/ + python3 dash_db.py +fi +chmod 777 /opt/adn-dashboard/html/db/dashboard.db +chown -R www-data:www-data /opt/adn-dashboard/html +############################################################## +# service update +############################################################ + + +cat > /lib/systemd/system/fdmr_mon3.service <<- "EOF" +[Unit] +Description=ADN Monitor3 +# To make the network-online.target available +# systemctl enable systemd-networkd-wait-online.service +#After=network-online.target syslog.target +#Wants=network-online.target + +[Service] +User=root +Type=simple +Restart=always +RestartSec=3 +StandardOutput=null +WorkingDirectory=/opt/adn-dashboard +ExecStart=python3 /opt/adn-dashboard/dashboard.py +#Restart=on-abort +#Restart=on-failure -EOFC1 -sudo chmod +x /usr/local/bin/cronedit.sh +[Install] +WantedBy=multi-user.target + +EOF +# +sudo cat > /lib/systemd/system/proxy2.service <<- "EOF" +[Unit] +Description=ADN Server Proxy +After=multi-user.target + +[Service] +StandardOutput=null +WorkingDirectory=/opt/adn-dashboard +RestartSec=3 +ExecStart=/usr/bin/python3 /opt/adn-dashboard/proxy/hotspot_proxy_v2.py -c /opt/adn-dashboard/proxy/proxy.cfg +Restart=on-failure + +[Install] +WantedBy=multi-user.target + +EOF + +############################# +sudo systemctl daemon-reload + +##################################### +if systemctl is-enabled fdmr_mon.service >/dev/null 2>&1 || \ + systemctl is-enabled fdmr_mon2.service >/dev/null 2>&1; then + if ! systemctl is-active --quiet mariadb.service; then + sudo systemctl start mariadb.service + fi + if ! systemctl is-enabled --quiet mariadb.service 2>/dev/null; then + sudo systemctl enable mariadb.service + fi +else + if systemctl is-active --quiet mariadb.service; then + sudo systemctl stop mariadb.service + sudo systemctl disable mariadb.service + fi +fi + +if systemctl status fdmr_mon3.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl stop fdmr_mon3.service + sudo systemctl start fdmr_mon3.service + (crontab -l | grep -v "rm /opt/FDMR-Monitor/data/*") | crontab - + (crontab -l | grep -v "rm /opt/FDMR-Monitor2/data/*") | crontab - + (crontab -l | grep -v "/opt/FDMR-Monitor/sysinfo/cpu.sh") | crontab - + (crontab -l | grep -v "/opt/FDMR-Monitor/sysinfo/graph.sh") | crontab - +fi +if systemctl status proxy2.service |grep "service; enabled;" >/dev/null 2>&1 +then + sudo systemctl stop proxy2.service + sudo systemctl start proxy2.service +fi +sh /opt/extra-4.sh + +if [ -f "/etc/nginx/sites-enabled/freedmr" ]; then + mv /etc/nginx/sites-enabled/freedmr /etc/nginx/sites-enabled/adn +fi +if ! systemctl status nginx.service |grep "service; enabled;" >/dev/null 2>&1 +then + systemctl enable nginx.service +fi +sudo systemctl restart nginx + + +EOFC2 +sudo chmod +x /opt/monitor-update3.sh ########################################## End Update Files ############################################################## sudo systemctl daemon-reload -sudo chmod +x /opt/fdmr-update.sh -sudo chmod +x /opt/monitor-update.sh sudo chmod +x /bin/menu* -sudo chmod +x /opt/monitor-update2.sh bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/install/ipv6off.sh)" && +bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/menu/menu-fdmr)" if [ -d "/opt/ADN-DMR-Peer-Server/" ]; then menu-update else bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/fdmr/-/raw/main/install.sh)" sudo systemctl daemon-reload - sudo systemctl start proxy.service - sudo systemctl start adn-server.service - sudo systemctl start adn-parrot.service - sudo systemctl enable proxy.service - sudo systemctl enable adn-server.service - sudo systemctl enable adn-parrot.service - if [ -f "/bin/menu" ]; then bash -c "$(curl -fsSLk https://gitlab.com/hp3icc/emq-TE1/-/raw/main/menu/menu)" fi