Better Wi-Fi Interface Detection

Issue #611 resolved
Pico Mitchell created an issue

Hi, I’m proposing using the following code instead of indiscriminately trying to connect to Wi-Fi on en0 and en1 in https://bitbucket.org/twocanoes/macdeploystick/src/a7989eddae93d3339b54e30356da0c6ff13fd795/com.twocanoes.mds.main.sh#lines-40.

for this_network_interface in $(/usr/sbin/networksetup -listallhardwareports 2> /dev/null | grep '^Device: ' | cut -c 9-); do
    if /usr/sbin/networksetup -getairportnetwork "${this_network_interface}" &> /dev/null; then
        /usr/sbin/networksetup -setairportnetwork "${this_network_interface}" "${workflow_wifi_ssid}" "${workflow_wifi_password}"
    fi
done

This code will only try to connect to valid Wi-Fi interfaces by first retrieving all network interfaces with networksetup -listallhardwareports and then validating that they are Wi-Fi interfaces by using networksetup -getairportnetwork which will error if it’s not a Wi-Fi interface and only running networksetup -setairportnetwork on valid Wi-Fi interfaces.

I started looking at this part of the code because I am sometime noticing continuous airport crashes in the log while being successfully connected to Wi-Fi. I don’t really thinks it’s connected to trying to connect to a Wi-Fi network on a non-Wi-Fi interface, but I noticed the correct code and knew that I had a more specific bit of code that I could share in it’s place. The airport crash needs more investigation and I will post a separate issue if I can reliably reproduce that and narrow it down. The Wi-Fi connection and install does finish when with the airport crash, just pollutes the log.

Comments (3)

  1. Pico Mitchell reporter

    I see my airport crash would have actually happened after setting Wi-Fi in https://bitbucket.org/twocanoes/macdeploystick/src/a7989eddae93d3339b54e30356da0c6ff13fd795/MacDeployStick/run?at=master#run-74,77 rather than the specified file above. With how this code functions, the crash seems to definitely be unrelated to what interface was connected.

    Regardless, the previous code snippet could be used in the run script as well for reliable Wi-Fi connection regardless of interface ID.

  2. Log in to comment