Update debian/set_mac_wifi.sh

This commit is contained in:
2026-02-15 11:28:19 +00:00
parent ed23bc3461
commit bc34b7aece
+32 -34
View File
@@ -13,6 +13,37 @@ log() {
echo "$(date '+%Y-%m-%d %H:%M:%S'): $1" | tee -a "$LOG_FILE"
}
# Função para perguntar confirmação ao utilizador
ask_confirmation() {
local message="$1"
local default="$2" # "y" or "n"
while true; do
if [ "$default" = "y" ]; then
read -p "$message [Y/n]: " choice < /dev/tty
else
read -p "$message [y/N]: " choice < /dev/tty
fi
# Default choice if user just presses Enter
if [ -z "$choice" ]; then
choice="$default"
fi
case "$choice" in
y|Y|yes|Yes|YES)
return 0
;;
n|N|no|No|NO)
return 1
;;
*)
echo "Por favor, responda sim ou não."
;;
esac
done
}
# Função para gerar MAC único baseado no Serial do CPU
generate_unique_mac() {
local serial
@@ -92,7 +123,6 @@ setup_udev_persistence() {
# Função robusta para verificar persistência
is_persistence_configured() {
if [ -f "$UDEV_RULES_FILE" ]; then
# Verifica se o ficheiro não está vazio (proteção extra)
if [ -s "$UDEV_RULES_FILE" ]; then
log "Ficheiro de persistência encontrado: $UDEV_RULES_FILE"
return 0
@@ -144,7 +174,6 @@ if is_persistence_configured; then
fi
# 2. Esperar pela Interface de Rede (Importante para boot/curl)
# O script pode correr antes da interface estar pronta.
IFACE="eth0"
log "A aguardar pela interface $IFACE..."
for i in {1..30}; do
@@ -162,37 +191,6 @@ fi
# 3. Determinar o MAC Address
TARGET_MAC=""
# Função para perguntar confirmação ao utilizador
ask_confirmation() {
local message="$1"
local default="$2" # "y" or "n"
while true; do
if [ "$default" = "y" ]; then
read -p "$message [Y/n]: " choice < /dev/tty
else
read -p "$message [y/N]: " choice < /dev/tty
fi
# Default choice if user just presses Enter
if [ -z "$choice" ]; then
choice="$default"
fi
case "$choice" in
y|Y|yes|Yes|YES)
return 0
;;
n|N|no|No|NO)
return 1
;;
*)
echo "Por favor, responda sim ou não."
;;
esac
done
}
# Verificar argumento ($1)
if [ -n "$1" ]; then
TARGET_MAC="$1"
@@ -236,7 +234,7 @@ if set_mac "$IFACE" "$TARGET_MAC"; then
setup_udev_persistence "$IFACE" "$TARGET_MAC"
else
log "Aviso: Falha ao definir MAC em tempo real, mas a tentar criar persistência..."
setup_udev_persistence "$IFACE" "$TARGET_MAC"
setup_udev_persistence "$IFACE" "$TARGET_MAC
fi
# 5. Lançar Monitor de Rede