Skip to content

Instantly share code, notes, and snippets.

@o-kotb
o-kotb / setoldnmdefault.sh
Last active January 7, 2024 20:13
Sets all existing wifi networks' cloned-mac-address to preserve, the previous default, if they didn't have one set already.
#!/bin/bash
for nmprofile in /etc/NetworkManager/system-connections/*; do
# check if a cloned mac was already set
if grep -q "cloned-mac-address" "$nmprofile"; then
echo "$(basename "$nmprofile") already has a cloned mac address. No changes."
else
# If it doesn't have a [wifi] section, it's not a wifi network
if grep -q "\[wifi\]" "$nmprofile"; then
sed -i '/\[wifi\]/a cloned-mac-address=preserve' "$nmprofile"