ambevar-dotfiles/.netinit

40 lines
1011 B
Bash
Executable File

#!/bin/bash
################################################################################
## Custom network initialization script.
## 2012-08-31
################################################################################
if [ $(id -u) -ne 0 ]; then
echo "You must be root to run this script."
exit
fi
NET_INTERFACE=wlan0
WPA_SUPPLICANT_CONF="/etc/wpa_supplicant.conf"
TIMEOUT_LIMIT=500
## Clean running processes if any.
pkill dhcpcd
pkill wpa_supplicant
## In case network inteface is not up.
ip link set ${NET_INTERFACE} up
## Connection.
if [ $# -eq 0 ]; then
# Associate if needed.
if [ -n "$(iwconfig ${NET_INTERFACE} | grep 'Not-Associated')" ]; then
wpa_supplicant -B -i ${NET_INTERFACE} -D wext -c "${WPA_SUPPLICANT_CONF}"
fi
## Wait until wpa_supplicant has finished association.
i=0
while [ -n "$(iwconfig ${NET_INTERFACE} | grep 'off/any')" ] && [ $i -lt $TIMEOUT_LIMIT ] ; do
i=$(($i+1))
done
fi
## Get IP.
dhcpcd ${NET_INTERFACE}