improvement
This commit is contained in:
Vendored
+31
-9
@@ -197,20 +197,42 @@ disable_wifi() {
|
|||||||
# Função para forçar renovação de IP
|
# Função para forçar renovação de IP
|
||||||
force_ip_renewal() {
|
force_ip_renewal() {
|
||||||
local iface="$1"
|
local iface="$1"
|
||||||
|
local success=0
|
||||||
|
|
||||||
if systemctl is-active --quiet systemd-networkd; then
|
# Tentativa 1: Reiniciar dhcpcd (Raspberry Pi padrão)
|
||||||
log "A forçar renovação de IP em $iface (reiniciando systemd-networkd)..."
|
if systemctl is-active --quiet dhcpcd; then
|
||||||
if systemctl restart systemd-networkd; then
|
log "Tentativa 1/3: Reiniciando dhcpcd para renovar IP em $iface..."
|
||||||
log "Serviço systemd-networkd reiniciado com sucesso. IP deve ser atribuído em breve."
|
if systemctl restart dhcpcd; then
|
||||||
return 0
|
log "dhcpcd reiniciado com sucesso."
|
||||||
|
success=1
|
||||||
else
|
else
|
||||||
log "Erro: Falha ao reiniciar systemd-networkd."
|
log "Falha ao reiniciar dhcpcd."
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
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
|
else
|
||||||
log "Aviso: systemd-networkd não está ativo. Tentando alternativa..."
|
log "Falha ao renovar IP usando dhclient."
|
||||||
return 1
|
|
||||||
fi
|
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
|
# Tarefa em Background para monitorizar rede
|
||||||
|
|||||||
Reference in New Issue
Block a user