Update debian/setup_raspberry.sh
This commit is contained in:
Vendored
+10
-36
@@ -105,61 +105,35 @@ download_file() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure MAC address
|
||||
# Função para configurar o endereço MAC
|
||||
configure_mac() {
|
||||
local mac_script="$SCRIPT_DIR/set_mac_wifi.sh"
|
||||
local new_mac=$1
|
||||
|
||||
if [ ! -f "$mac_script" ]; then
|
||||
log "${RED}MAC address script not found${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate MAC address format
|
||||
if validate_mac "$new_mac"; then
|
||||
# Normalize to use colons
|
||||
new_mac=$(echo "$new_mac" | tr '-' ':')
|
||||
# Update MAC address in script
|
||||
sed -i "s/ETH0_MAC=.*/ETH0_MAC=\"$new_mac\"/" "$mac_script"
|
||||
log "${GREEN}MAC address updated to $new_mac${NC}"
|
||||
# Atualiza o script para gerar um MAC address automaticamente
|
||||
# Remove qualquer definição existente de ETH0_MAC para garantir que o script gere um novo
|
||||
sed -i '/ETH0_MAC=.*/d' "$mac_script"
|
||||
|
||||
log "${GREEN}MAC address will be generated automatically by the script${NC}"
|
||||
return 0
|
||||
else
|
||||
log "${RED}Invalid MAC address format: $new_mac. Please use format XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to setup MAC address
|
||||
# Função para configurar o endereço MAC
|
||||
setup_mac_address() {
|
||||
if ask_confirmation "Do you want to configure the MAC address for eth0?" "n"; then
|
||||
if ask_confirmation "Do you want to configure the MAC address for eth0 automatically?" "n"; then
|
||||
download_file "set_mac_wifi.sh" "$SCRIPT_DIR" || return 1
|
||||
|
||||
local mac_script="$SCRIPT_DIR/set_mac_wifi.sh"
|
||||
|
||||
# If MAC address was provided as parameter, use it
|
||||
if [ -n "$1" ]; then
|
||||
if configure_mac "$1"; then
|
||||
if configure_mac; then
|
||||
log "${GREEN}MAC address setup completed successfully${NC}"
|
||||
return 0
|
||||
else
|
||||
log "${RED}Failed to configure MAC address${NC}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prompt for MAC address
|
||||
while true; do
|
||||
read -p "Enter MAC address for eth0 (format: XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX): " new_mac < /dev/tty
|
||||
if validate_mac "$new_mac"; then
|
||||
if configure_mac "$new_mac"; then
|
||||
return 0
|
||||
else
|
||||
log "${RED}Failed to configure MAC address${NC}"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "${RED}Invalid MAC address format. Please use format XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX${NC}"
|
||||
fi
|
||||
done
|
||||
else
|
||||
log "${YELLOW}Skipping MAC address configuration${NC}"
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user