Thanks everybody for the input.
@wux: It seems like networking is one of the more arcane aspects of linux, at least to me.
@bacon: Thanks for the suggestions and tips. Apparently
select is found only in bash, ksh, and zsh. Maybe I'll suck it up, but for now I'm looking for a more portable workaround. I've added checking to see if a configuration file already exists and offering to use it, and a few other minor improvements.
Here's what I've got so far:
Code: Select all
#!/bin/sh
# if connected, nuke the 'net
if ( ps -A | grep "wpa_supplicant" > /dev/null 2>&1 ); then
echo "\nKilling connection..." &
kill $(ps -A | awk '/wpa_supplicant/ {print $1}')
fi
# look for past configurations and ask to use
if [ -e /etc/wpa_supplicant.conf ]; then
echo "\nPrevious configuration found:\n"
echo "$(awk '/"/' /etc/wpa_supplicant.conf)\n"
read -p "Use the above (y/n)? " ANSWER1
if echo "$ANSWER1" | grep -iq "^y"; then
wpa_supplicant -i wlan0 -B -Dnl80211 -c /etc/wpa_supplicant.conf > /dev/null 2>&1
dhclient wlan0 > /dev/null 2>&1
if ( ps -A | grep "wpa_supplicant" > /dev/null 2>&1 ); then
echo "\nConnected!\n"
else
echo "\nFailed.\n"
fi
exit
else
break
fi
fi
# acquire WiFi info
ip link set wlan0 up > /dev/null 2>&1
echo -n "\nNetwork: "
read NAME
echo -n "Password: "
read PASS
# write configuration file
cat <<EOT > /etc/wpa_supplicant.conf
# WPA-PSK/TKIP
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="$NAME"
psk="$PASS"
}
EOT
# connect to the network
iwconfig wlan0 essid $NAME > /dev/null 2>&1
wpa_supplicant -i wlan0 -B -Dnl80211 -c /etc/wpa_supplicant.conf > /dev/null 2>&1
dhclient wlan0 > /dev/null 2>&1
# check connection
if ( ps -A | grep "wpa_supplicant" > /dev/null 2>&1 ); then
echo "\nConnected!\n"
else
echo "\nFailed.\n"
fi
I've already mentioned that I'm new to putting out scripts & such for others to view, so I appreciate any and all feedback.