improvement

This commit is contained in:
2026-02-15 16:27:30 +00:00
parent d2d28580a2
commit 64b197cbe5
+32 -10
View File
@@ -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