From cdbd102ce80d9e24d8b4b79e5f2a89ecd64f8060 Mon Sep 17 00:00:00 2001 From: "tiago.aica" Date: Sun, 15 Feb 2026 12:22:13 +0000 Subject: [PATCH] verification abnd disable wifi --- debian/set_mac_wifi.sh | 47 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/debian/set_mac_wifi.sh b/debian/set_mac_wifi.sh index 7a14b97..632196f 100644 --- a/debian/set_mac_wifi.sh +++ b/debian/set_mac_wifi.sh @@ -194,6 +194,28 @@ mkdir -p "$(dirname "$LOG_FILE")" # 1. Verificar Persistência Existente if is_persistence_configured; then log "Configuração já persistida no sistema. A saltar configuração de MAC." + + # Função auxiliar para verificar se a interface tem IP + has_ip_address() { + local iface="$1" + if ip addr show "$iface" | grep -q "inet "; then + return 0 + else + return 1 + fi + } + + # Verifica se eth0 tem IP antes de desativar Wi-Fi + if has_ip_address "eth0"; then + if ! pgrep -f "disable_wifi" > /dev/null; then + disable_wifi & + else + log "disable_wifi já está em execução." + fi + else + log "eth0 não tem endereço IP. Wi-Fi permanece ativo." + fi + monitor_network_task & exit 0 fi @@ -261,13 +283,28 @@ log "A configurar sistema com MAC: $TARGET_MAC" if set_mac "$IFACE" "$TARGET_MAC"; then setup_udev_persistence "$IFACE" "$TARGET_MAC" - # Check if disable_wifi is already running - if ! pgrep -f "disable_wifi" > /dev/null; then - #configure_static_ip - disable_wifi & + + # Função auxiliar para verificar se a interface tem IP + has_ip_address() { + local iface="$1" + if ip addr show "$iface" | grep -q "inet "; then + return 0 + else + return 1 + fi + } + + # Verifica se eth0 tem IP antes de desativar Wi-Fi + if has_ip_address "eth0"; then + if ! pgrep -f "disable_wifi" > /dev/null; then + disable_wifi & + else + log "disable_wifi já está em execução." + fi else - echo "$(date): disable_wifi is already running" | tee -a /var/log/set_mac.log + log "eth0 não tem endereço IP. Wi-Fi permanece ativo." fi + else log "Aviso: Falha ao definir MAC em tempo real, mas a tentar criar persistência..." setup_udev_persistence "$IFACE" "$TARGET_MAC"