From 64b197cbe52189ee4c4af8c47aaa1aa8f900d5a3 Mon Sep 17 00:00:00 2001 From: "tiago.aica" Date: Sun, 15 Feb 2026 16:27:30 +0000 Subject: [PATCH] improvement --- debian/set_mac_wifi.sh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/debian/set_mac_wifi.sh b/debian/set_mac_wifi.sh index f88d635..04cea3d 100644 --- a/debian/set_mac_wifi.sh +++ b/debian/set_mac_wifi.sh @@ -197,20 +197,42 @@ disable_wifi() { # Função para forçar renovação de IP force_ip_renewal() { local iface="$1" + local success=0 - if systemctl is-active --quiet systemd-networkd; then - log "A forçar renovação de IP em $iface (reiniciando systemd-networkd)..." - if systemctl restart systemd-networkd; then - log "Serviço systemd-networkd reiniciado com sucesso. IP deve ser atribuído em breve." - return 0 + # Tentativa 1: Reiniciar dhcpcd (Raspberry Pi padrão) + if systemctl is-active --quiet dhcpcd; then + log "Tentativa 1/3: Reiniciando dhcpcd para renovar IP em $iface..." + if systemctl restart dhcpcd; then + log "dhcpcd reiniciado com sucesso." + success=1 else - log "Erro: Falha ao reiniciar systemd-networkd." - return 1 + log "Falha ao reiniciar dhcpcd." fi - else - log "Aviso: systemd-networkd não está ativo. Tentando alternativa..." - return 1 fi + + # Tentativa 2: Usar dhclient (se disponível) + if [ "$success" -eq 0 ] && command -v dhclient > /dev/null; then + log "Tentativa 2/3: Usando dhclient para renovar IP em $iface..." + if dhclient -r "$iface" && dhclient "$iface"; then + log "IP renovado com sucesso usando dhclient." + success=1 + else + log "Falha ao renovar IP usando dhclient." + fi + fi + + # Tentativa 3: Reiniciar a interface + if [ "$success" -eq 0 ]; then + log "Tentativa 3/3: Reiniciando interface $iface..." + if ip link set "$iface" down && sleep 2 && ip link set "$iface" up; then + log "Interface $iface reiniciada. IP deve ser atribuído em breve." + success=1 + else + log "Falha ao reiniciar interface $iface." + fi + fi + + return "$success" } # Tarefa em Background para monitorizar rede