X-Original-To: alpine-aports@mail.alpinelinux.org Delivered-To: alpine-aports@mail.alpinelinux.org Received: from mail.alpinelinux.org (dallas-a1.alpinelinux.org [127.0.0.1]) by mail.alpinelinux.org (Postfix) with ESMTP id 61067DC040E for ; Fri, 25 Mar 2016 11:55:32 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mail.alpinelinux.org (Postfix) with ESMTPS id 0B36BDC19F1 for ; Fri, 25 Mar 2016 11:55:31 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id l68so17096786wml.0 for ; Fri, 25 Mar 2016 04:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=OVgL5HAAKq/MAFneCoW6aMvM0caaaVEXGSR/8vIWYK8=; b=bz6sU4lxyuKoltZ8YPlS0qCFp4D7p7HmUxGdDAfEL8pgMi8AdVyteZsnSrw6RWcQxR /BVBMtOib2JhwJJrM2tZPVF+g+odn09y7eE0kjubAuzVnlvpAplkz84DOh4boFKIFKYO G+BEreWEjXO/+j7gQyGOfi8M1uZkCSKx3zNk/t4jtO0UwnXLIfVarB9yrT36Ujrt3GdF HoaiQpkX1SWkhd5wxBKtA91y73OnqE6YiJyxRdRKUxEXEeRZ6EXG8UkvYAb/U9Jc6W1J qZ1frjvclhjoZ52yXWYChshEZj69xvIrBx/4Sy50ws3VOJbpOU7JgnO6DzrbBy9jtHPZ 9sGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=OVgL5HAAKq/MAFneCoW6aMvM0caaaVEXGSR/8vIWYK8=; b=F8VIl/hBMUerT7CD4/REEb2yCeDzPkJcBwCM6JNuy3cLuF8a9GJSocKxXxihKQxu7t u89Ot2FSHwmwOWUklG6YxOQx+GdI32yAeDj5na1iqMzntJVkY7MqwTQsyD+kptzVE7Kl XemzuPKOi//avxrqMKBZ8DtOfyo+xdDpnojix84NFp7Q828MXpVliynYq6RLcD1TO21f +dBXwSNoMEO7Vm/4btDmnMkmYEbXHycMH/1JtWkUPThPMjjqzm/a0wUg9JqUWH5i4L8d m6+3YiPaoy3taau3tFjPVSAyeETJ/8qGOCqXXtBlv24GUbwzmelIcUdUMKG0LZomanEx KcJA== X-Gm-Message-State: AD7BkJKstfwHycxp3puWUYlazrB/xOU8Yb8LEsa+lPqWMgZbwSvb7NU60Gpd3klbVa6jpQ== X-Received: by 10.194.121.34 with SMTP id lh2mr14719416wjb.145.1458906930179; Fri, 25 Mar 2016 04:55:30 -0700 (PDT) Received: from df1844j.ita.jwm2.net ([89.202.239.194]) by smtp.gmail.com with ESMTPSA id z127sm2827667wme.5.2016.03.25.04.55.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Mar 2016 04:55:28 -0700 (PDT) Sender: Leonardo Arena From: Leonardo Arena To: alpine-aports@lists.alpinelinux.org Cc: Leonardo Arena Subject: [alpine-aports] [PATCH] setup-interfaces: add limited support for configuring wireless interfaces Date: Fri, 25 Mar 2016 11:55:08 +0000 Message-Id: <1458906908-18275-1-git-send-email-rnalrd@alpinelinux.org> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP X-Mailinglist: alpine-aports Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: --- setup-interfaces.in | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) 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 -- 2.7.4 --- Unsubscribe: alpine-aports+unsubscribe@lists.alpinelinux.org Help: alpine-aports+help@lists.alpinelinux.org ---