aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Arena <rnalrd@alpinelinux.org>2016-03-25 11:55:08 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2016-04-05 11:44:33 +0000
commitb634b7422e89728ad9cbd350ac8c4bf737f0f923 (patch)
tree0d40d5588e3e2868ce0848cb511ab13b5f9f27ad
parent5b1046727d57d48b0ffd5152447ec5d860f1f44e (diff)
downloadalpine-conf-b634b7422e89728ad9cbd350ac8c4bf737f0f923.tar.bz2
alpine-conf-b634b7422e89728ad9cbd350ac8c4bf737f0f923.tar.xz
setup-interfaces: add limited support for configuring wireless interfaces
-rw-r--r--setup-interfaces.in72
1 files changed, 72 insertions, 0 deletions
diff --git a/setup-interfaces.in b/setup-interfaces.in
index c62cd30..1d6ac6a 100644
--- a/setup-interfaces.in
+++ b/setup-interfaces.in
@@ -115,6 +115,62 @@ is_bridge() {
test -r $1.bridge_ports
}
+is_wifi() {
+ test -d /sys/class/net/$1/phy80211
+}
+
+find_essids() {
+ local iface=$1
+ export essids_list=wlans
+ # Supports only open or PSK
+ iwlist $iface scanning | awk -F: '/ESSID/ { printf "%s ",$2 } /Authentication Suites/ \
+ { printf ":%s\n",$2 }' | grep -v 802.1x | sort -u >$essids_list
+ if [ -s $essids_list ]; then
+ cat $essids_list
+ else
+ return 1
+ fi
+}
+
+config_wpa_supp() {
+ local iface=$1
+ local essid=$2
+ local psk=$3
+ local conffile=/etc/wpa_supplicant/wpa_supplicant.conf
+ if [ "$auth_type" == "WPA-PSK" ]; then
+ cat << EOF >> $conffile
+network={
+ ssid="$essid"
+ key_mgmt=$auth_type
+ psk="$psk"
+}
+EOF
+ else
+ cat << EOF >> $conffile
+network={
+ ssid="$essid"
+ key_mgmt=$auth_type
+}
+EOF
+ fi
+
+ wpa_supplicant -B -c $conffile -i $iface 2>/dev/null
+}
+
+wlan_is_not_open() {
+ local iface=$1
+ local essid=$2
+ auth_type=$(awk -F: '/'"$essid"'/ { print $2 }' $essids_list)
+ echo $auth_type | grep -q PSK
+ if [ "$?" -eq "0" ]; then
+ export auth_type="WPA-PSK"
+ return 0
+ else
+ export auth_type="open"
+ return 1
+ fi
+}
+
config_iface() {
local iface=$1
local prefix=$2
@@ -151,6 +207,22 @@ config_iface() {
raw_device=$(cat $iface.raw_device)
echo "raw_device=\"$raw_device\"" >> $conf
fi
+ if is_wifi $iface; then
+ apk add --quiet --no-progress wpa_supplicant || prompt_for_interfaces
+ echo "Available wireless networks (scanning):"
+ if find_essids $iface; then
+ ask "Type the wireless network name to connect to:"
+ local essid=$resp
+ if wlan_is_not_open $iface $essid; then
+ ask "Type the \"$essid\" network Pre-Shared Key:"
+ psk=$resp
+ fi
+ config_wpa_supp $iface $essid $psk
+ else
+ echo -e "\nNo available wireless networks\n"
+ prompt_for_interfaces
+ fi
+ fi
# use ipcalc to validate the address. we do accept /mask
# we are no interested in the result, only error code, so
# we send result to /dev/null