Last active
April 18, 2016 16:21
-
-
Save akpoff/ac1fb0eeab2969cb78ea78cb90076b31 to your computer and use it in GitHub Desktop.
Configure wlan card under OpenBSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if=$1 | |
MUTEX=/tmp/network_config.$if | |
if [ -f $MUTEX ] | |
then | |
echo "Wireless config for $if already in progress" | |
exit | |
fi | |
wlan_active=$(ifconfig $if | grep "status: active" | wc -l | tr -d ' ') | |
if [ ${wlan_active:-1} -eq 0 ] | |
then | |
touch $MUTEX | |
trap 'rm -f $MUTEX; exit 1' 0 HUP INT TERM | |
echo "$if not connected, search for known wireless network..." | |
ifconfig $if down > /dev/null | |
scand=$(ifconfig $if scan | grep -v ieee80211 | grep nwid | tr -d '\t' | sed -E 's#^nwid (.*) chan.*#\1#' | sort -u) | |
nwids=$(cat /etc/nwid.conf | sed -E 's#^nwid (.*) wpakey.*#\1#') | |
OLD_IFS=$IFS | |
# set IFS to a single return character | |
IFS=' | |
' | |
found=0 | |
# look for matches in order the nwids were set in the file | |
for i in $nwids | |
do | |
if [ found -eq 1 ] | |
then | |
break | |
fi | |
for j in $scand | |
do | |
if [ $i = $j ] | |
then | |
echo "Known wireless network found ($i), connecting..." | |
config=$(cat /etc/nwid.conf | grep $i) | |
# eval to ensure quoted text is handled | |
eval ifconfig $if $config up | |
ifconfig $if | grep status | |
dhclient $if | |
found=1 | |
break | |
fi | |
done | |
done | |
IFS=$OLD_IFS | |
else | |
echo "$if already connected and active" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment