Wireless autodetection
From ArchWiki
You should have your network profiles up and running. You have to perform every step as root.
In general, it's always a good idea to back up your files before editing them, especially in this case as this workaround may need some modifications to get it to work on your setup.
First of all, you should rename your existing network profiles to the MAC addresses of the appropriate routers. For example:
mv /etc/network-profiles/EXISTING_PROFILE_NAME /etc/network-profiles/00:11:22:33:44:55
Do this for every profile that should be included within the auto-detection.
Therefore, I use a fallback LAN DHCP profile called lan-dhcp (see the 'netdetect' script below).
Next, you'll have to edit the network script
nano /etc/rc.d/network
Search for the following lines...
elif [ "$NET_PROFILES" ]; then if [ "$NET_PROFILES" = "menu" ]; then /usr/bin/netcfg --menu --timeout 5 else for prof in ${NET_PROFILES[@]}; do if [ "$prof" = "${prof#!}" ]; then /usr/bin/netcfg -c $prof fi done fi fi
... and replace them with these:
elif [ "$NET_PROFILES" ]; then if [ "$NET_PROFILES" = "menu" ]; then /usr/bin/netcfg --menu --timeout 5 elif [ "$NET_PROFILES" = "detect" ]; then /usr/bin/netdetect else for prof in ${NET_PROFILES[@]}; do if [ "$prof" = "${prof#!}" ]; then /usr/bin/netcfg -c $prof fi done fi fi
Save and exit.
To avoid losing this modification in future updates, tell pacman to leave this script as it is. Add this line to your general options within /etc/pacman.conf - hope this works ;) - not tested
NoUpgrade = etc/rc.d/network
Now that the network script should do its job fine for us, we'll edit /etc/rc.conf
nano /etc/rc.conf
Go to the network-profiles section and modify it like this:
aKNOWNMACS=("00:11:22:33:44:55" "66:77:88:99:00:AA" "BB:CC:DD:EE:FF:42") NET_PROFILES=(detect)
Replace the nice MAC addresses with the MAC addresses of the access points you trust in.
Finally, you need my small AP-detection script... you should save it as /usr/bin/netdetect and make it executable - here it comes:
#!/bin/bash . /etc/rc.conf aSCANNEDMACS=(`iwlist wlan0 scanning | grep Address | awk '{print $5;}'`) for J in ${aSCANNEDMACS[*]} ; do for K in ${aKNOWNMACS[*]} ; do if [ $J == $K ] then DETECTEDMAC=$K DET_ESSID=`cat /etc/network-profiles/$K | grep ESSID= | tr -d ESSID=` break fi done if [ $DETECTEDMAC ] then break fi done if [ $DETECTEDMAC ] then netcfg -c $DETECTEDMAC else echo "could not detect a known AP... falling back to LAN" netcfg -c lan-dhcp fi
chmod +x /usr/bin/netdetect