#!/bin/sh # Copyright (C)2024, Philip Munts dba Munts Technologies. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # Define a function to wait for a file or device node to be created WaitForFile() { while [ ! $1 $2 ] do #echo "Wait for $2" usleep 100000 done } . /etc/platform if [ "$SUBSYSTEM" != "net" ]; then exit 0 fi # Add a network interface if [ "${ACTION}" = "add" ]; then # Run ifplugd if [ "${INTERFACE}" != "lo" -a ! -f /var/run/ifplugd.${INTERFACE}.pid ]; then ifplugd -i ${INTERFACE} -I -r /usr/libexec/ifplugd.script WaitForFile -f /var/run/ifplugd.${INTERFACE}.pid fi # Run wpa_supplicant echo "${INTERFACE}" | grep -q -i wlan if [ $? -eq 0 -a -f /etc/wpa_supplicant.conf -a ! -f /var/run/wpa_supplicant.${INTERFACE}.pid ]; then wpa_supplicant -B -q -s -Dnl80211,wext -i ${INTERFACE} -c /etc/wpa_supplicant.conf -P /var/run/wpa_supplicant.${INTERFACE}.pid WaitForFile -f /var/run/wpa_supplicant.${INTERFACE}.pid fi fi # Remove a network interface if [ "${ACTION}" = "remove" ]; then # Kill wpa_supplicant if [ -f /var/run/wpa_supplicant.${INTERFACE}.pid ]; then kill `cat /var/run/wpa_supplicant.${INTERFACE}.pid` rm -f /var/run/wpa_supplicant.${INTERFACE}.pid fi # Kill ifplugd if [ -f /var/run/ifplugd.${INTERFACE}.pid ]; then kill `cat /var/run/ifplugd.${INTERFACE}.pid` rm -f /var/run/ifplugd.${INTERFACE}.pid fi fi