Skip to content

Instantly share code, notes, and snippets.

@o-kotb
Last active January 7, 2024 20:13
Show Gist options
  • Save o-kotb/59f02fc4de8fea54837333becbb78167 to your computer and use it in GitHub Desktop.
Save o-kotb/59f02fc4de8fea54837333becbb78167 to your computer and use it in GitHub Desktop.
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"
echo "Set cloned-mac-address=preserve in $(basename "$nmprofile") profile."
else
echo "$(basename "$nmprofile") isn't a wifi network. No changes."
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment