From c3998687baf7b4ede0ba152e555bff142f918b72 Mon Sep 17 00:00:00 2001 From: Esteban Mackay Q Date: Sun, 10 Sep 2023 19:55:42 -0500 Subject: [PATCH] update wcs --- install/gotty.sh | 2 +- install/wifi-connect.sh | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/install/gotty.sh b/install/gotty.sh index dcefa88..9ab6bf3 100644 --- a/install/gotty.sh +++ b/install/gotty.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd /tmp/ +cd /opt/ if [ "$(uname -m | grep '64')" != "" ]; then # echo "ARCH: 64-bit" wget -qO gotty.tar.gz https://github.com/yudai/gotty/releases/latest/download/gotty_linux_amd64.tar.gz diff --git a/install/wifi-connect.sh b/install/wifi-connect.sh index 600ad8d..30f7c0c 100644 --- a/install/wifi-connect.sh +++ b/install/wifi-connect.sh @@ -13,12 +13,23 @@ sudo cat > /usr/local/bin/autoap.sh <<- "EOF" # Tiempo de espera entre los chequeos en segundos TIEMPO_ESPERA=30 +# Lista de servicios para verificar y detener si no hay conexión a Internet +SERVICIOS=("http.server-dw.service" "http.server-mmdvmh.service" "http.server-dvs.service" "http.server-ysf.service" "hbmon.service" "hbmon2.service" "hbmon-js.service" "http.server-fdmr.service" "http.server-fdmr2.service" "daprs-board.service") + # Funcion para verificar el estado de Internet verificar_internet() { ping -c 5 noip.com > /dev/null 2>&1 return $? } +# Funcion para detener un servicio si está habilitado +detener_servicio() { + servicio="$1" + if sudo systemctl is-enabled "$servicio" >/dev/null 2>&1; then + sudo systemctl stop "$servicio" + fi +} + # Bucle infinito para monitorear while true; do # Verificar el estado de la interfaz wlan0 @@ -37,10 +48,9 @@ while true; do : else # Internet no esta disponible, realiza acciones necesarias - if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then - # Detiene http.server-mmdvmh.service si esta habilitado - sudo systemctl stop http.server-mmdvmh.service - fi + for servicio in "${SERVICIOS[@]}"; do + detener_servicio "$servicio" + done wifi-connect fi fi @@ -52,11 +62,15 @@ while true; do sleep $TIEMPO_ESPERA done + EOF sudo cat > /usr/local/bin/apoff.sh <<- "EOF" #!/bin/bash +# Lista de servicios a verificar y reiniciar si están habilitados +SERVICIOS=("http.server-dw.service" "http.server-mmdvmh.service" "http.server-dvs.service" "http.server-ysf.service" "hbmon.service" "hbmon2.service" "hbmon-js.service" "http.server-fdmr.service" "http.server-fdmr2.service" "daprs-board.service") + while true; do # Verifica si wifi-connect está corriendo como proceso if pgrep -x "wifi-connect" >/dev/null; then @@ -65,11 +79,12 @@ while true; do # Si la respuesta de ping es positiva, reinicia autoap.service sudo systemctl restart autoap.service - # Verifica si http.server-mmdvmh.service está habilitado - if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then - # Inicia http.server-mmdvmh.service si está habilitado - sudo systemctl restart http.server-mmdvmh.service - fi + # Verifica y reinicia los servicios habilitados de la lista + for servicio in "${SERVICIOS[@]}"; do + if sudo systemctl is-enabled "$servicio" >/dev/null 2>&1; then + sudo systemctl restart "$servicio" + fi + done fi fi @@ -78,7 +93,6 @@ while true; do done - EOF sudo chmod +x /usr/local/bin/apoff.sh sudo chmod +x /usr/local/bin/autoap.sh