From owner-svn-src-all@freebsd.org Wed Jun 8 20:42:37 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2626EB6F917; Wed, 8 Jun 2016 20:42:37 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F21011C69; Wed, 8 Jun 2016 20:42:36 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u58KgaB9005712; Wed, 8 Jun 2016 20:42:36 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u58KgavE005711; Wed, 8 Jun 2016 20:42:36 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201606082042.u58KgavE005711@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Wed, 8 Jun 2016 20:42:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301694 - head/usr.sbin/bsdinstall/scripts X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2016 20:42:37 -0000 Author: avos Date: Wed Jun 8 20:42:35 2016 New Revision: 301694 URL: https://svnweb.freebsd.org/changeset/base/301694 Log: bsdinstall: add country/regulatory domain configuration dialog. Allow to setup country and/or regulatory domain before scanning (since channel list is affected by regulatory restrictions this may impact scan results). PR: 182600 (originally) Differential Revision: https://reviews.freebsd.org/D6325 Modified: head/usr.sbin/bsdinstall/scripts/wlanconfig Modified: head/usr.sbin/bsdinstall/scripts/wlanconfig ============================================================================== --- head/usr.sbin/bsdinstall/scripts/wlanconfig Wed Jun 8 20:22:25 2016 (r301693) +++ head/usr.sbin/bsdinstall/scripts/wlanconfig Wed Jun 8 20:42:35 2016 (r301694) @@ -31,6 +31,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 +f_include $BSDCFG_SHARE/dialog.subr ############################################################ MAIN @@ -58,40 +59,190 @@ if [ $? -ne 0 -a -z $BSDINSTALL_CONFIGCU exit 1 fi -output=$( wpa_cli scan 2>&1 ) -f_dprintf "%s" "$output" -dialog --backtitle "FreeBSD Installer" --title "Scanning" --ok-label "Skip" \ - --pause "Waiting 5 seconds to scan for wireless networks..." \ - 9 40 5 || exit 1 - -SCAN_RESULTS=`wpa_cli scan_results` -NETWORKS=`echo "$SCAN_RESULTS" | awk -F '\t' \ - '/..:..:..:..:..:../ {if (length($5) > 0) printf("\"%s\"\t%s\n", $5, $4);}' | - sort | uniq` - -if [ -z "$NETWORKS" ]; then - dialog --backtitle "FreeBSD Installer" --title "Error" \ - --yesno "No wireless networks were found. Rescan?" 0 0 && \ - exec $0 $@ - exit 1 +country_set() +{ + local error_str= + local iface_up= + local ifconfig_args= + + # Setup what was selected + # NB: do not change order of arguments (or regdomain will be ignored) + if [ ! -z "$2" ]; then + ifconfig_args="${ifconfig_args}country $2" + fi + if [ ! -z "$1" ]; then + if [ ! -z "$2" ]; then + ifconfig_args="${ifconfig_args} " + fi + ifconfig_args="${ifconfig_args}regdomain $1" + fi + if [ -z "$ifconfig_args" ]; then + # Nothing to do (everything was skipped) + return $SUCCESS + fi + + # Regdomain/country cannot be applied while interface is running + iface_up=`ifconfig -lu | grep -w $WLAN_IFACE` + if [ ! -z "$iface_up" ]; then + ifconfig $WLAN_IFACE down + fi + error_str=`ifconfig $WLAN_IFACE $ifconfig_args 2>&1 | \ + sed 's/ifconfig: //'` + if [ ! -z "$iface_up" ]; then + # Restart wpa_supplicant(8) (should not fail). + wpa_supplicant -B -i $WLAN_IFACE -c \ + $BSDINSTALL_TMPETC/wpa_supplicant.conf + fi + if [ ! -z "$error_str" ]; then + dialog --backtitle "FreeBSD Installer" --title "Error" \ + --yes-label Change --no-label Ignore --yesno \ + "Error while applying chosen settings ($error_str)" 0 0 + if [ $? -eq $DIALOG_OK ]; then + return $FAILURE # Restart + else + return $SUCCESS # Skip + fi + else + : > $BSDINSTALL_TMPETC/rc.conf.net.wlan + echo create_args_$WLAN_IFACE=\"$ifconfig_args\" >> \ + $BSDINSTALL_TMPETC/rc.conf.net.wlan + fi + + return $SUCCESS +} + +dialog_country_select() +{ + local input= + local def_item_regdomain= + local def_item_country= + local regdomains= + local countries= + local regdomain= + local country= + + # Parse available countries/regdomains + input=`ifconfig $WLAN_IFACE list countries | sed 's/DEBUG//gi'` + regdomains=`echo $input | sed 's/.*domains://' | tr ' ' '\n' | \ + sort | tr '\n' ' '` + countries=`echo $input | sed 's/Country codes://' | \ + sed 's/Regulatory.*//' | awk '{ + for (i = 1; i <= NF; i++) { + printf "%s", $i + if (match($i, "[[:lower:]]")) + if (match($(i+1), "[[:lower:]]")) + printf "\\\\\\ " + else + printf "\n" + else + printf " " + } + }' | sort -k 2 | tr '\n' ' '` + + # Change default cursor position (if required). + if [ "$1" != "" ]; then + def_item_regdomain="--default-item $1" + fi + if [ "$2" != "" ]; then + def_item_country="--default-item $2" + fi + + f_dialog_menu_size height width rows \"Regdomain selection\" \ + \"FreeBSD Installer\" \"Select your regdomain.\" \ + \"\" $regdomains + regdomain=`sh -c "dialog \ + --backtitle \"FreeBSD Installer\" \ + --title \"Regdomain selection\" \ + --cancel-label \"Skip\" \ + $def_item_regdomain \ + --no-items \ + --stdout \ + --menu \"Select your regdomain.\" \ + $height $width $rows $regdomains"` + + f_dialog_menu_size height width rows \"Country selection\" \ + \"FreeBSD Installer\" \"Select your country.\" \ + \"\" $countries + country=`sh -c "dialog \ + --backtitle \"FreeBSD Installer\" \ + --title \"Country selection\" \ + --cancel-label \"Skip\" \ + $def_item_country \ + --stdout \ + --menu \"Select your country.\" \ + $height $width $rows $countries"` + + country_set "$regdomain" "$country" + + return $? +} + +# There is no way to check country/regdomain without (possible) +# interface state modification +if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + # Get current country/regdomain for selected interface + WLAN_IFACE=`wpa_cli ifname | tail -n 1` + INPUT=`ifconfig $WLAN_IFACE list regdomain | head -n 1` + DEF_REGDOMAIN=`echo $INPUT | cut -w -f 2` + if [ "$DEF_REGDOMAIN" = "0" ]; then + DEF_REGDOMAIN="" + fi + DEF_COUNTRY=`echo $INPUT | cut -w -f 4` + if [ "$DEF_COUNTRY" = "0" ]; then + DEF_COUNTRY="" + fi + dialog --backtitle "FreeBSD Installer" --title "Regdomain/country" \ + --yesno "Change regdomain/country (now \ + $DEF_REGDOMAIN/$DEF_COUNTRY)?" 0 0 + if [ $? -eq 0 ]; then + while : + do + dialog_country_select "$DEF_REGDOMAIN" "$DEF_COUNTRY" + if [ $? -eq $SUCCESS ]; then + break + fi + done + fi fi -exec 3>&1 -NETWORK=`sh -c "dialog --extra-button --extra-label \"Rescan\" \ - --backtitle \"FreeBSD Installer\" --title \"Network Selection\" --menu \ - \"Select a wireless network to connect to.\" 0 0 0 \ - $(echo $NETWORKS | tr '\n' ' ')" 2>&1 1>&3` -case $? in -0) # OK - ;; -1) # Cancel - exit 1 - ;; -3) # Rescan - exec $0 $@ - ;; -esac -exec 3>&- +while : +do + output=$( wpa_cli scan 2>&1 ) + f_dprintf "%s" "$output" + dialog --backtitle "FreeBSD Installer" --title "Scanning" \ + --ok-label "Skip" \ + --pause "Waiting 5 seconds to scan for wireless networks..." \ + 9 40 5 || exit 1 + + SCAN_RESULTS=`wpa_cli scan_results` + NETWORKS=`echo "$SCAN_RESULTS" | awk -F '\t' \ + '/..:..:..:..:..:../ {if (length($5) > 0) \ + printf("\"%s\"\t%s\n", $5, $4);}' | sort | uniq` + + if [ -z "$NETWORKS" ]; then + dialog --backtitle "FreeBSD Installer" --title "Error" \ + --yesno "No wireless networks were found. Rescan?" 0 0 && \ + continue + exit 1 + fi + + exec 3>&1 + NETWORK=`sh -c "dialog --extra-button --extra-label \"Rescan\" \ + --backtitle \"FreeBSD Installer\" --title \"Network Selection\" \ + --menu \"Select a wireless network to connect to.\" 0 0 0 \ + $(echo $NETWORKS | tr '\n' ' ')" 2>&1 1>&3` + case $? in + 0) # OK + break + ;; + 1) # Cancel + exit 1 + ;; + 3) # Rescan + ;; + esac + exec 3>&- +done ENCRYPTION=`echo "$NETWORKS" | awk -F '\t' \ "/^\"$NETWORK\"\t/ {printf(\"%s\n\", \\\$2 );}"`